root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / filter / FilterDialog.java @ 1830
History | View | Annotate | Download (28.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.filter; |
42 |
|
43 |
import java.text.DateFormat; |
44 |
import java.text.NumberFormat; |
45 |
import java.text.ParseException; |
46 |
import java.util.ArrayList; |
47 |
import java.util.Comparator; |
48 |
import java.util.Date; |
49 |
import java.util.HashSet; |
50 |
import java.util.Iterator; |
51 |
import java.util.TreeSet; |
52 |
import java.util.regex.Matcher; |
53 |
import java.util.regex.Pattern; |
54 |
|
55 |
import javax.swing.DefaultListModel; |
56 |
import javax.swing.JPanel; |
57 |
|
58 |
import org.apache.log4j.Logger; |
59 |
|
60 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
61 |
import com.hardcode.gdbms.engine.instruction.IncompatibleTypesException; |
62 |
import com.hardcode.gdbms.engine.values.BooleanValue; |
63 |
import com.hardcode.gdbms.engine.values.DateValue; |
64 |
import com.hardcode.gdbms.engine.values.StringValue; |
65 |
import com.hardcode.gdbms.engine.values.Value; |
66 |
import com.iver.andami.PluginServices; |
67 |
import com.iver.andami.messages.NotificationManager; |
68 |
import com.iver.andami.ui.mdiManager.View; |
69 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
70 |
import com.iver.andami.ui.mdiManager.ViewListener; |
71 |
import com.iver.cit.gvsig.gui.Table; |
72 |
import com.iver.utiles.DefaultCharSet; |
73 |
import com.iver.utiles.StringUtilities; |
74 |
import com.iver.utiles.exceptionHandling.ExceptionHandlingSupport; |
75 |
import com.iver.utiles.exceptionHandling.ExceptionListener; |
76 |
import com.lamatek.swingextras.JDateChooser; |
77 |
|
78 |
|
79 |
/**
|
80 |
* DOCUMENT ME!
|
81 |
*
|
82 |
* @author Fernando Gonz?lez Cort?s
|
83 |
*/
|
84 |
public class FilterDialog extends JPanel implements View, ViewListener { |
85 |
private static Logger logger = Logger.getLogger(Table.class.getName()); |
86 |
private ArrayList expressionListeners = new ArrayList(); |
87 |
private int position = 0; |
88 |
private DefaultListModel fieldListModel = new DefaultListModel(); |
89 |
private DefaultListModel valuesListModel = new DefaultListModel(); |
90 |
private NumberFormat nf = NumberFormat.getNumberInstance(); |
91 |
private DateFormat df = DateFormat.getDateInstance(); |
92 |
private ArrayList variables = new ArrayList(); |
93 |
private ExpressionDataSource model = null; |
94 |
private javax.swing.JPanel jPanel = null; |
95 |
private javax.swing.JPanel jPanel1 = null; |
96 |
private javax.swing.JPanel jPanel2 = null; |
97 |
private javax.swing.JPanel jPanel3 = null; |
98 |
private javax.swing.JPanel jPanel4 = null; |
99 |
private javax.swing.JLabel jLabel = null; |
100 |
private javax.swing.JScrollPane jScrollPane = null; |
101 |
private javax.swing.JList lstCampos = null; |
102 |
private javax.swing.JButton btnIgual = null; |
103 |
private javax.swing.JButton btnMayor = null; |
104 |
private javax.swing.JButton btnNot = null; |
105 |
private javax.swing.JButton btnDistinto = null; |
106 |
private javax.swing.JButton btnMenor = null; |
107 |
private javax.swing.JButton btnMayorIgual = null; |
108 |
private javax.swing.JButton btnMenorIgual = null; |
109 |
private javax.swing.JButton btnAnd = null; |
110 |
private javax.swing.JButton btnOr = null; |
111 |
private javax.swing.JTextArea txtExpression = null; |
112 |
private javax.swing.JPanel jPanel5 = null; |
113 |
private javax.swing.JButton btnNuevo = null; |
114 |
private javax.swing.JButton btnAdd = null; |
115 |
private javax.swing.JButton btnName = null; |
116 |
private javax.swing.JButton btnFromSet = null; |
117 |
private javax.swing.JScrollPane jScrollPane1 = null; |
118 |
private javax.swing.JLabel jLabel1 = null; |
119 |
private javax.swing.JList lstValores = null; |
120 |
private javax.swing.JScrollPane jScrollPane2 = null; |
121 |
private javax.swing.JButton btnParentesis = null; |
122 |
private ExceptionHandlingSupport exceptionHandlingSupport = new ExceptionHandlingSupport(); |
123 |
|
124 |
/*
|
125 |
* TODO Eliminar si est? comentado
|
126 |
*
|
127 |
public class ComparableValue {
|
128 |
public Value value;
|
129 |
|
130 |
|
131 |
public boolean equals(Object obj) {
|
132 |
Value v = (Value) obj;
|
133 |
return v.equals(obj);
|
134 |
}
|
135 |
}
|
136 |
*/
|
137 |
|
138 |
/**
|
139 |
* This is the default constructor
|
140 |
*/
|
141 |
public FilterDialog() {
|
142 |
super();
|
143 |
initialize(); |
144 |
} |
145 |
|
146 |
/**
|
147 |
* DOCUMENT ME!
|
148 |
*
|
149 |
* @param t DOCUMENT ME!
|
150 |
*/
|
151 |
public void setModel(ExpressionDataSource t) { |
152 |
try {
|
153 |
if (model != null) |
154 |
{ |
155 |
model.stop(); |
156 |
} |
157 |
model = t; |
158 |
model.start(); |
159 |
} catch (DriverException e1) {
|
160 |
NotificationManager.addError(e1.getMessage(), e1); |
161 |
} |
162 |
fieldListModel.clear(); |
163 |
|
164 |
try {
|
165 |
for (int i = 0; i < model.getFieldCount(); i++) { |
166 |
fieldListModel.addElement(model.getFieldName(i)); |
167 |
} |
168 |
} catch (FilterException e) {
|
169 |
throwException(e); |
170 |
} |
171 |
} |
172 |
|
173 |
/**
|
174 |
* Rellena la lista con los valores del campo seleccionado
|
175 |
*
|
176 |
* @param timeOut DOCUMENT ME!
|
177 |
*/
|
178 |
private void fillValues(int timeOut) { |
179 |
int index = lstCampos.getSelectedIndex();
|
180 |
|
181 |
//Index es ahora el ?ndice del campo seleccionado
|
182 |
//Se eliminan los duplicados
|
183 |
TreeSet conjunto = new TreeSet(new Comparator() { |
184 |
public int compare(Object o1, Object o2) { |
185 |
int resul = -1; |
186 |
|
187 |
if ((o1 != null) && (o2 != null)) { |
188 |
Value v2 = (Value) o2; |
189 |
Value v1 = (Value) o1; |
190 |
BooleanValue boolVal; |
191 |
|
192 |
try {
|
193 |
boolVal = (BooleanValue) (v1.greater(v2)); |
194 |
|
195 |
if (boolVal.getValue()) {
|
196 |
return 1; |
197 |
} |
198 |
|
199 |
boolVal = (BooleanValue) (v1.less(v2)); |
200 |
|
201 |
if (boolVal.getValue()) {
|
202 |
return -1; |
203 |
} |
204 |
} catch (IncompatibleTypesException e) {
|
205 |
// TODO Auto-generated catch block
|
206 |
e.printStackTrace(); |
207 |
} |
208 |
} |
209 |
|
210 |
return 0; |
211 |
} |
212 |
}); // Para poder ordenar
|
213 |
|
214 |
valuesListModel.clear(); |
215 |
try {
|
216 |
for (int i = 0; i < model.getRowCount(); i++) { |
217 |
Value value = model.getFieldValue(i, index); |
218 |
|
219 |
if (!conjunto.contains(value)) {
|
220 |
conjunto.add(value); |
221 |
} |
222 |
} |
223 |
|
224 |
Iterator it = conjunto.iterator();
|
225 |
|
226 |
while (it.hasNext())
|
227 |
valuesListModel.addElement(it.next()); |
228 |
} catch (FilterException e) {
|
229 |
throwException(e); |
230 |
} |
231 |
} |
232 |
|
233 |
/**
|
234 |
* DOCUMENT ME!
|
235 |
*
|
236 |
* @param expresion DOCUMENT ME!
|
237 |
* @param substring DOCUMENT ME!
|
238 |
* @param startingPos DOCUMENT ME!
|
239 |
*
|
240 |
* @return DOCUMENT ME!
|
241 |
*/
|
242 |
private int getIndex(String expresion, String substring, int startingPos) { |
243 |
int index = startingPos;
|
244 |
|
245 |
do {
|
246 |
index = expresion.indexOf(substring, index); |
247 |
} while ((StringUtilities.isBetweenSymbols(expresion, index, "\"")) && |
248 |
(index != -1));
|
249 |
|
250 |
return index;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* DOCUMENT ME!
|
255 |
*
|
256 |
* @param expresion DOCUMENT ME!
|
257 |
* @param word DOCUMENT ME!
|
258 |
* @param translation DOCUMENT ME!
|
259 |
*
|
260 |
* @return DOCUMENT ME!
|
261 |
*
|
262 |
* @throws ParseException DOCUMENT ME!
|
263 |
*/
|
264 |
private String translateWord(String expresion, String word, |
265 |
String translation) throws ParseException { |
266 |
int booleanIndex = 0; |
267 |
int endIndex = 0; |
268 |
StringBuffer res = new StringBuffer(); |
269 |
|
270 |
while ((booleanIndex = getIndex(expresion, word, booleanIndex)) != -1) { |
271 |
res.append(expresion.substring(endIndex, booleanIndex)); |
272 |
endIndex = booleanIndex + word.length(); |
273 |
booleanIndex++; |
274 |
res.append(translation); |
275 |
} |
276 |
|
277 |
if (endIndex < expresion.length()) {
|
278 |
res.append(expresion.substring(endIndex)); |
279 |
} |
280 |
|
281 |
return res.toString();
|
282 |
} |
283 |
|
284 |
/**
|
285 |
* DOCUMENT ME!
|
286 |
*
|
287 |
* @param expresion DOCUMENT ME!
|
288 |
*
|
289 |
* @return DOCUMENT ME!
|
290 |
*
|
291 |
* @throws ParseException DOCUMENT ME!
|
292 |
*/
|
293 |
private String translateDates(String expresion) throws ParseException { |
294 |
//Se obtiene el valor de la fecha
|
295 |
String date = StringUtilities.substringDelimited(expresion, "Date(", |
296 |
")", 0); |
297 |
|
298 |
if (date == null) { |
299 |
return expresion;
|
300 |
} |
301 |
|
302 |
//Se comprueba que no est? entre comillas
|
303 |
int startIndex = expresion.indexOf(date);
|
304 |
|
305 |
while (startIndex != -1) { |
306 |
if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) { |
307 |
//Se sustituye por el valor ordinal de la fecha
|
308 |
expresion = expresion.substring(0, startIndex - 5) + |
309 |
expresion.substring(startIndex).replaceFirst(date + "\\)",
|
310 |
new Long((df.parse(date)).getTime()).toString()); |
311 |
; |
312 |
} else {
|
313 |
startIndex += date.length(); |
314 |
} |
315 |
|
316 |
//Se obtiene el valor de la fecha
|
317 |
|
318 |
/* date = StringUtilities.substringDelimited(expresion, "Date(", ")",
|
319 |
startIndex);
|
320 |
*/
|
321 |
if (date == null) { |
322 |
return expresion;
|
323 |
} |
324 |
|
325 |
startIndex = expresion.indexOf(date, startIndex); |
326 |
} |
327 |
|
328 |
return expresion;
|
329 |
} |
330 |
|
331 |
/**
|
332 |
* DOCUMENT ME!
|
333 |
*
|
334 |
* @param expresion DOCUMENT ME!
|
335 |
*
|
336 |
* @return DOCUMENT ME!
|
337 |
*
|
338 |
* @throws ParseException DOCUMENT ME!
|
339 |
*/
|
340 |
public String translateNumber(String expresion) throws ParseException { |
341 |
DefaultCharSet ss = new DefaultCharSet();
|
342 |
ss.addInterval('0', '9'); |
343 |
ss.addCharacter(',');
|
344 |
ss.addCharacter('.');
|
345 |
|
346 |
String number = StringUtilities.substringWithSymbols(expresion, ss, 0); |
347 |
|
348 |
if (number == null) { |
349 |
return expresion;
|
350 |
} |
351 |
|
352 |
int startIndex = expresion.indexOf(number);
|
353 |
|
354 |
while (startIndex != -1) { |
355 |
Number n = nf.parse(number);
|
356 |
|
357 |
if (!StringUtilities.isBetweenSymbols(expresion, startIndex, "\"")) { |
358 |
//Se sustituye por el valor ordinal de la fecha
|
359 |
expresion = expresion.substring(0, startIndex) +
|
360 |
expresion.substring(startIndex).replaceFirst(number, |
361 |
n.toString()); |
362 |
} else {
|
363 |
startIndex += n.toString().length(); |
364 |
} |
365 |
|
366 |
number = StringUtilities.substringWithSymbols(expresion, ss, |
367 |
startIndex); |
368 |
|
369 |
if (number == null) { |
370 |
return expresion;
|
371 |
} |
372 |
|
373 |
startIndex = expresion.indexOf(number, startIndex); |
374 |
} |
375 |
|
376 |
return expresion;
|
377 |
} |
378 |
|
379 |
/**
|
380 |
* DOCUMENT ME!
|
381 |
*
|
382 |
* @return DOCUMENT ME!
|
383 |
*
|
384 |
* @throws ParseException DOCUMENT ME!
|
385 |
*/
|
386 |
private String validateExpression() throws ParseException { |
387 |
String expression = txtExpression.getText();
|
388 |
HashSet variablesIndexes = new HashSet(); |
389 |
|
390 |
StringBuffer traducida = new StringBuffer(); |
391 |
|
392 |
//Se transforman los nombres de los campos en las variables xix que analizar?n
|
393 |
//Se quitan los Date(fecha) y se mete la fecha correspondiente
|
394 |
expression = translateDates(expression); |
395 |
expression = translateNumber(expression); |
396 |
expression = translateWord(expression, "true", "1"); |
397 |
expression = translateWord(expression, "false", "0"); |
398 |
|
399 |
String replacement;
|
400 |
Pattern patron = Pattern.compile("[^<>!]="); |
401 |
Matcher m = patron.matcher(expression);
|
402 |
int index = 0; |
403 |
|
404 |
while (m.find(index)) {
|
405 |
index = m.start(); |
406 |
replacement = expression.charAt(index) + "==";
|
407 |
m.replaceFirst(replacement); |
408 |
index++; |
409 |
} |
410 |
|
411 |
expression = expression.replaceAll("[^<>!]=", "=="); |
412 |
|
413 |
logger.debug(expression); |
414 |
|
415 |
return expression;
|
416 |
} |
417 |
|
418 |
/**
|
419 |
* DOCUMENT ME!
|
420 |
*
|
421 |
* @param symbol DOCUMENT ME!
|
422 |
*/
|
423 |
private void putSymbol(String symbol) { |
424 |
int position = txtExpression.getCaretPosition();
|
425 |
txtExpression.setText(StringUtilities.insert(txtExpression.getText(), |
426 |
position, symbol)); |
427 |
|
428 |
if (symbol.equals(" () ")) { |
429 |
position = position + 2;
|
430 |
} else {
|
431 |
position = position + symbol.length(); |
432 |
} |
433 |
|
434 |
txtExpression.setCaretPosition(position); |
435 |
} |
436 |
|
437 |
/**
|
438 |
* This method initializes this
|
439 |
*/
|
440 |
private void initialize() { |
441 |
this.setLayout(new java.awt.BorderLayout()); |
442 |
this.add(getJPanel(), java.awt.BorderLayout.CENTER);
|
443 |
this.add(getJPanel1(), java.awt.BorderLayout.SOUTH);
|
444 |
} |
445 |
|
446 |
/**
|
447 |
* This method initializes jPanel
|
448 |
*
|
449 |
* @return javax.swing.JPanel
|
450 |
*/
|
451 |
private javax.swing.JPanel getJPanel() {
|
452 |
if (jPanel == null) { |
453 |
jPanel = new javax.swing.JPanel();
|
454 |
jPanel.setLayout(new java.awt.BorderLayout());
|
455 |
jPanel.add(getJPanel2(), java.awt.BorderLayout.WEST); |
456 |
jPanel.add(getJPanel3(), java.awt.BorderLayout.CENTER); |
457 |
jPanel.add(getJPanel4(), java.awt.BorderLayout.EAST); |
458 |
} |
459 |
|
460 |
return jPanel;
|
461 |
} |
462 |
|
463 |
/**
|
464 |
* This method initializes jPanel1
|
465 |
*
|
466 |
* @return javax.swing.JPanel
|
467 |
*/
|
468 |
private javax.swing.JPanel getJPanel1() {
|
469 |
if (jPanel1 == null) { |
470 |
jPanel1 = new javax.swing.JPanel();
|
471 |
jPanel1.add(getJScrollPane2(), null);
|
472 |
jPanel1.add(getJPanel5(), null);
|
473 |
jPanel1.setPreferredSize(new java.awt.Dimension(10, 110)); |
474 |
} |
475 |
|
476 |
return jPanel1;
|
477 |
} |
478 |
|
479 |
/**
|
480 |
* This method initializes jPanel2
|
481 |
*
|
482 |
* @return javax.swing.JPanel
|
483 |
*/
|
484 |
private javax.swing.JPanel getJPanel2() {
|
485 |
if (jPanel2 == null) { |
486 |
jPanel2 = new javax.swing.JPanel();
|
487 |
jPanel2.add(getJLabel(), null);
|
488 |
jPanel2.add(getJScrollPane(), null);
|
489 |
jPanel2.setPreferredSize(new java.awt.Dimension(150, 170)); |
490 |
} |
491 |
|
492 |
return jPanel2;
|
493 |
} |
494 |
|
495 |
/**
|
496 |
* This method initializes jPanel3
|
497 |
*
|
498 |
* @return javax.swing.JPanel
|
499 |
*/
|
500 |
private javax.swing.JPanel getJPanel3() {
|
501 |
if (jPanel3 == null) { |
502 |
jPanel3 = new javax.swing.JPanel();
|
503 |
jPanel3.add(getBtnIgual(), null);
|
504 |
jPanel3.add(getBtnDistinto(), null);
|
505 |
jPanel3.add(getBtnMayor(), null);
|
506 |
jPanel3.add(getBtnMenor(), null);
|
507 |
jPanel3.add(getBtnMenorIgual(), null);
|
508 |
jPanel3.add(getBtnMayorIgual(), null);
|
509 |
jPanel3.add(getBtnAnd(), null);
|
510 |
jPanel3.add(getBtnOr(), null);
|
511 |
jPanel3.add(getBtnNot(), null);
|
512 |
jPanel3.add(getBtnParentesis(), null);
|
513 |
jPanel3.add(getBtnName(), null);
|
514 |
jPanel3.setPreferredSize(new java.awt.Dimension(180, 36)); |
515 |
} |
516 |
|
517 |
return jPanel3;
|
518 |
} |
519 |
|
520 |
/**
|
521 |
* This method initializes jPanel4
|
522 |
*
|
523 |
* @return javax.swing.JPanel
|
524 |
*/
|
525 |
private javax.swing.JPanel getJPanel4() {
|
526 |
if (jPanel4 == null) { |
527 |
jPanel4 = new javax.swing.JPanel();
|
528 |
jPanel4.add(getJLabel1(), null);
|
529 |
jPanel4.add(getJScrollPane1(), null);
|
530 |
jPanel4.setPreferredSize(new java.awt.Dimension(150, 10)); |
531 |
} |
532 |
|
533 |
return jPanel4;
|
534 |
} |
535 |
|
536 |
/**
|
537 |
* This method initializes jLabel
|
538 |
*
|
539 |
* @return javax.swing.JLabel
|
540 |
*/
|
541 |
private javax.swing.JLabel getJLabel() {
|
542 |
if (jLabel == null) { |
543 |
jLabel = new javax.swing.JLabel();
|
544 |
jLabel.setText(PluginServices.getText(this, "Campos") + ":"); |
545 |
} |
546 |
|
547 |
return jLabel;
|
548 |
} |
549 |
|
550 |
/**
|
551 |
* This method initializes jScrollPane
|
552 |
*
|
553 |
* @return javax.swing.JScrollPane
|
554 |
*/
|
555 |
private javax.swing.JScrollPane getJScrollPane() {
|
556 |
if (jScrollPane == null) { |
557 |
jScrollPane = new javax.swing.JScrollPane();
|
558 |
jScrollPane.setViewportView(getLstCampos()); |
559 |
jScrollPane.setPreferredSize(new java.awt.Dimension(135, 120)); |
560 |
} |
561 |
|
562 |
return jScrollPane;
|
563 |
} |
564 |
|
565 |
/**
|
566 |
* This method initializes lstCampos
|
567 |
*
|
568 |
* @return javax.swing.JList
|
569 |
*/
|
570 |
private javax.swing.JList getLstCampos() {
|
571 |
if (lstCampos == null) { |
572 |
lstCampos = new javax.swing.JList();
|
573 |
lstCampos.setModel(fieldListModel); |
574 |
lstCampos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
575 |
lstCampos.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
576 |
public void valueChanged( |
577 |
javax.swing.event.ListSelectionEvent e) { |
578 |
PluginServices.backgroundExecution(new Runnable() { |
579 |
public void run() { |
580 |
fillValues(0);
|
581 |
} |
582 |
}); |
583 |
} |
584 |
}); |
585 |
lstCampos.addMouseListener(new java.awt.event.MouseAdapter() {
|
586 |
public void mouseClicked(java.awt.event.MouseEvent e) { |
587 |
if (e.getClickCount() == 2) { |
588 |
putSymbol((String) fieldListModel.getElementAt(
|
589 |
getLstCampos().getSelectedIndex())); |
590 |
} |
591 |
} |
592 |
}); |
593 |
} |
594 |
|
595 |
return lstCampos;
|
596 |
} |
597 |
|
598 |
/**
|
599 |
* This method initializes btnIgual
|
600 |
*
|
601 |
* @return javax.swing.JButton
|
602 |
*/
|
603 |
private javax.swing.JButton getBtnIgual() {
|
604 |
if (btnIgual == null) { |
605 |
btnIgual = new javax.swing.JButton();
|
606 |
btnIgual.setText("=");
|
607 |
btnIgual.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
608 |
btnIgual.setPreferredSize(new java.awt.Dimension(40, 20)); |
609 |
btnIgual.addActionListener(new java.awt.event.ActionListener() {
|
610 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
611 |
putSymbol(" = ");
|
612 |
} |
613 |
}); |
614 |
} |
615 |
|
616 |
return btnIgual;
|
617 |
} |
618 |
|
619 |
/**
|
620 |
* This method initializes btnMayor
|
621 |
*
|
622 |
* @return javax.swing.JButton
|
623 |
*/
|
624 |
private javax.swing.JButton getBtnMayor() {
|
625 |
if (btnMayor == null) { |
626 |
btnMayor = new javax.swing.JButton();
|
627 |
btnMayor.setText(">");
|
628 |
btnMayor.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
629 |
btnMayor.setPreferredSize(new java.awt.Dimension(40, 20)); |
630 |
btnMayor.addActionListener(new java.awt.event.ActionListener() {
|
631 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
632 |
putSymbol(" > ");
|
633 |
} |
634 |
}); |
635 |
} |
636 |
|
637 |
return btnMayor;
|
638 |
} |
639 |
|
640 |
/**
|
641 |
* This method initializes btnNot
|
642 |
*
|
643 |
* @return javax.swing.JButton
|
644 |
*/
|
645 |
private javax.swing.JButton getBtnNot() {
|
646 |
if (btnNot == null) { |
647 |
btnNot = new javax.swing.JButton();
|
648 |
btnNot.setText("Not");
|
649 |
btnNot.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
650 |
btnNot.setPreferredSize(new java.awt.Dimension(40, 20)); |
651 |
btnNot.addActionListener(new java.awt.event.ActionListener() {
|
652 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
653 |
putSymbol(" not ");
|
654 |
} |
655 |
}); |
656 |
} |
657 |
|
658 |
return btnNot;
|
659 |
} |
660 |
|
661 |
/**
|
662 |
* This method initializes btnDistinto
|
663 |
*
|
664 |
* @return javax.swing.JButton
|
665 |
*/
|
666 |
private javax.swing.JButton getBtnDistinto() {
|
667 |
if (btnDistinto == null) { |
668 |
btnDistinto = new javax.swing.JButton();
|
669 |
btnDistinto.setText("!=");
|
670 |
btnDistinto.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
671 |
btnDistinto.setPreferredSize(new java.awt.Dimension(40, 20)); |
672 |
btnDistinto.addActionListener(new java.awt.event.ActionListener() {
|
673 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
674 |
putSymbol(" <> ");
|
675 |
} |
676 |
}); |
677 |
} |
678 |
|
679 |
return btnDistinto;
|
680 |
} |
681 |
|
682 |
/**
|
683 |
* This method initializes btnMenor
|
684 |
*
|
685 |
* @return javax.swing.JButton
|
686 |
*/
|
687 |
private javax.swing.JButton getBtnMenor() {
|
688 |
if (btnMenor == null) { |
689 |
btnMenor = new javax.swing.JButton();
|
690 |
btnMenor.setText("<");
|
691 |
btnMenor.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
692 |
btnMenor.setPreferredSize(new java.awt.Dimension(40, 20)); |
693 |
btnMenor.addActionListener(new java.awt.event.ActionListener() {
|
694 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
695 |
putSymbol(" < ");
|
696 |
} |
697 |
}); |
698 |
} |
699 |
|
700 |
return btnMenor;
|
701 |
} |
702 |
|
703 |
/**
|
704 |
* This method initializes btnMayorIgual
|
705 |
*
|
706 |
* @return javax.swing.JButton
|
707 |
*/
|
708 |
private javax.swing.JButton getBtnMayorIgual() {
|
709 |
if (btnMayorIgual == null) { |
710 |
btnMayorIgual = new javax.swing.JButton();
|
711 |
btnMayorIgual.setText(">=");
|
712 |
btnMayorIgual.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
713 |
btnMayorIgual.setPreferredSize(new java.awt.Dimension(40, 20)); |
714 |
btnMayorIgual.addActionListener(new java.awt.event.ActionListener() {
|
715 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
716 |
putSymbol(" >= ");
|
717 |
} |
718 |
}); |
719 |
} |
720 |
|
721 |
return btnMayorIgual;
|
722 |
} |
723 |
|
724 |
/**
|
725 |
* This method initializes btnMenorIgual
|
726 |
*
|
727 |
* @return javax.swing.JButton
|
728 |
*/
|
729 |
private javax.swing.JButton getBtnMenorIgual() {
|
730 |
if (btnMenorIgual == null) { |
731 |
btnMenorIgual = new javax.swing.JButton();
|
732 |
btnMenorIgual.setText("<=");
|
733 |
btnMenorIgual.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
734 |
btnMenorIgual.setPreferredSize(new java.awt.Dimension(40, 20)); |
735 |
btnMenorIgual.addActionListener(new java.awt.event.ActionListener() {
|
736 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
737 |
putSymbol(" <= ");
|
738 |
} |
739 |
}); |
740 |
} |
741 |
|
742 |
return btnMenorIgual;
|
743 |
} |
744 |
|
745 |
/**
|
746 |
* This method initializes btnAnd
|
747 |
*
|
748 |
* @return javax.swing.JButton
|
749 |
*/
|
750 |
private javax.swing.JButton getBtnAnd() {
|
751 |
if (btnAnd == null) { |
752 |
btnAnd = new javax.swing.JButton();
|
753 |
btnAnd.setText("And");
|
754 |
btnAnd.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
755 |
btnAnd.setPreferredSize(new java.awt.Dimension(40, 20)); |
756 |
btnAnd.addActionListener(new java.awt.event.ActionListener() {
|
757 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
758 |
putSymbol(" and ");
|
759 |
} |
760 |
}); |
761 |
} |
762 |
|
763 |
return btnAnd;
|
764 |
} |
765 |
|
766 |
/**
|
767 |
* This method initializes btnOr
|
768 |
*
|
769 |
* @return javax.swing.JButton
|
770 |
*/
|
771 |
private javax.swing.JButton getBtnOr() {
|
772 |
if (btnOr == null) { |
773 |
btnOr = new javax.swing.JButton();
|
774 |
btnOr.setText("Or");
|
775 |
btnOr.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
776 |
btnOr.setPreferredSize(new java.awt.Dimension(40, 20)); |
777 |
btnOr.addActionListener(new java.awt.event.ActionListener() {
|
778 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
779 |
putSymbol(" or ");
|
780 |
} |
781 |
}); |
782 |
} |
783 |
|
784 |
return btnOr;
|
785 |
} |
786 |
|
787 |
/**
|
788 |
* This method initializes txtExpression
|
789 |
*
|
790 |
* @return javax.swing.JTextArea
|
791 |
*/
|
792 |
private javax.swing.JTextArea getTxtExpression() {
|
793 |
if (txtExpression == null) { |
794 |
txtExpression = new javax.swing.JTextArea();
|
795 |
txtExpression.setLineWrap(true);
|
796 |
} |
797 |
|
798 |
return txtExpression;
|
799 |
} |
800 |
|
801 |
/**
|
802 |
* This method initializes jPanel5
|
803 |
*
|
804 |
* @return javax.swing.JPanel
|
805 |
*/
|
806 |
private javax.swing.JPanel getJPanel5() {
|
807 |
if (jPanel5 == null) { |
808 |
jPanel5 = new javax.swing.JPanel();
|
809 |
jPanel5.add(getBtnNuevo(), null);
|
810 |
jPanel5.add(getBtnAdd(), null);
|
811 |
jPanel5.add(getBtnFromSet(), null);
|
812 |
jPanel5.setPreferredSize(new java.awt.Dimension(190, 100)); |
813 |
} |
814 |
|
815 |
return jPanel5;
|
816 |
} |
817 |
|
818 |
/**
|
819 |
* This method initializes btnNuevo
|
820 |
*
|
821 |
* @return javax.swing.JButton
|
822 |
*/
|
823 |
private javax.swing.JButton getBtnNuevo() {
|
824 |
if (btnNuevo == null) { |
825 |
btnNuevo = new javax.swing.JButton();
|
826 |
btnNuevo.setText(PluginServices.getText(this, "Nuevo_conjunto")); |
827 |
btnNuevo.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
828 |
btnNuevo.addActionListener(new java.awt.event.ActionListener() {
|
829 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
830 |
final String expr = "select * from " + |
831 |
model.getDataSourceName() + " where " +
|
832 |
getTxtExpression().getText() + ";";
|
833 |
|
834 |
logger.debug(expr); |
835 |
|
836 |
PluginServices.backgroundExecution(new Runnable() { |
837 |
public void run() { |
838 |
for (int i = 0; i < expressionListeners.size(); i++) { |
839 |
ExpressionListener l = (ExpressionListener) expressionListeners.get(i); |
840 |
l.newSet(expr); |
841 |
} |
842 |
} |
843 |
}); |
844 |
} |
845 |
}); |
846 |
} |
847 |
|
848 |
return btnNuevo;
|
849 |
} |
850 |
|
851 |
/**
|
852 |
* This method initializes btnAdd
|
853 |
*
|
854 |
* @return javax.swing.JButton
|
855 |
*/
|
856 |
private javax.swing.JButton getBtnAdd() {
|
857 |
if (btnAdd == null) { |
858 |
btnAdd = new javax.swing.JButton();
|
859 |
btnAdd.setText(PluginServices.getText(this, "Anadir_al_conjunto")); |
860 |
btnAdd.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
861 |
btnAdd.addActionListener(new java.awt.event.ActionListener() {
|
862 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
863 |
final String expr = "select * from " + |
864 |
model.getDataSourceName() + " where " +
|
865 |
getTxtExpression().getText() + ";";
|
866 |
|
867 |
logger.debug(expr); |
868 |
|
869 |
PluginServices.backgroundExecution(new Runnable() { |
870 |
public void run() { |
871 |
for (int i = 0; |
872 |
i < expressionListeners.size(); |
873 |
i++) { |
874 |
ExpressionListener l = (ExpressionListener) expressionListeners.get(i); |
875 |
l.addToSet(expr); |
876 |
} |
877 |
} |
878 |
}); |
879 |
} |
880 |
}); |
881 |
} |
882 |
|
883 |
return btnAdd;
|
884 |
} |
885 |
|
886 |
/**
|
887 |
* This method initializes btnFromSet
|
888 |
*
|
889 |
* @return javax.swing.JButton
|
890 |
*/
|
891 |
private javax.swing.JButton getBtnFromSet() {
|
892 |
if (btnFromSet == null) { |
893 |
btnFromSet = new javax.swing.JButton();
|
894 |
btnFromSet.setText(PluginServices.getText(this,
|
895 |
"Seleccionar_del_conjunto"));
|
896 |
btnFromSet.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
897 |
btnFromSet.addActionListener(new java.awt.event.ActionListener() {
|
898 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
899 |
final String expr = "select * from " + |
900 |
model.getDataSourceName() + " where " +
|
901 |
getTxtExpression().getText() + ";";
|
902 |
|
903 |
logger.debug(expr); |
904 |
|
905 |
PluginServices.backgroundExecution(new Runnable() { |
906 |
public void run() { |
907 |
for (int i = 0; i < expressionListeners.size(); i++) { |
908 |
ExpressionListener l = (ExpressionListener) expressionListeners.get(i); |
909 |
l.fromSet(expr); |
910 |
} |
911 |
} |
912 |
}); |
913 |
} |
914 |
}); |
915 |
} |
916 |
|
917 |
return btnFromSet;
|
918 |
} |
919 |
|
920 |
/**
|
921 |
* This method initializes jScrollPane1
|
922 |
*
|
923 |
* @return javax.swing.JScrollPane
|
924 |
*/
|
925 |
private javax.swing.JScrollPane getJScrollPane1() {
|
926 |
if (jScrollPane1 == null) { |
927 |
jScrollPane1 = new javax.swing.JScrollPane();
|
928 |
jScrollPane1.setViewportView(getLstValores()); |
929 |
jScrollPane1.setPreferredSize(new java.awt.Dimension(140, 120)); |
930 |
} |
931 |
|
932 |
return jScrollPane1;
|
933 |
} |
934 |
|
935 |
/**
|
936 |
* This method initializes jLabel1
|
937 |
*
|
938 |
* @return javax.swing.JLabel
|
939 |
*/
|
940 |
private javax.swing.JLabel getJLabel1() {
|
941 |
if (jLabel1 == null) { |
942 |
jLabel1 = new javax.swing.JLabel();
|
943 |
jLabel1.setText(PluginServices.getText(this, "Valores") + ":"); |
944 |
} |
945 |
|
946 |
return jLabel1;
|
947 |
} |
948 |
|
949 |
/**
|
950 |
* This method initializes lstValores
|
951 |
*
|
952 |
* @return javax.swing.JList
|
953 |
*/
|
954 |
private javax.swing.JList getLstValores() {
|
955 |
if (lstValores == null) { |
956 |
lstValores = new javax.swing.JList();
|
957 |
lstValores.setModel(valuesListModel); |
958 |
lstValores.addMouseListener(new java.awt.event.MouseAdapter() {
|
959 |
public void mouseClicked(java.awt.event.MouseEvent e) { |
960 |
if (e.getClickCount() == 2) { |
961 |
Value valor = (Value) valuesListModel.getElementAt(getLstValores() |
962 |
.getSelectedIndex()); |
963 |
|
964 |
if (valor instanceof DateValue) { |
965 |
putSymbol("date('" + valor + "')"); |
966 |
} else if (valor instanceof BooleanValue) { |
967 |
putSymbol("boolean('" + valor.toString() +
|
968 |
"')");
|
969 |
} else if (valor instanceof StringValue) { |
970 |
putSymbol("'" + valor + "'"); |
971 |
} else {
|
972 |
putSymbol(valor.toString()); |
973 |
} |
974 |
} |
975 |
} |
976 |
}); |
977 |
} |
978 |
|
979 |
return lstValores;
|
980 |
} |
981 |
|
982 |
/**
|
983 |
* This method initializes jScrollPane2
|
984 |
*
|
985 |
* @return javax.swing.JScrollPane
|
986 |
*/
|
987 |
private javax.swing.JScrollPane getJScrollPane2() {
|
988 |
if (jScrollPane2 == null) { |
989 |
jScrollPane2 = new javax.swing.JScrollPane();
|
990 |
jScrollPane2.setViewportView(getTxtExpression()); |
991 |
jScrollPane2.setPreferredSize(new java.awt.Dimension(250, 100)); |
992 |
jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
993 |
} |
994 |
|
995 |
return jScrollPane2;
|
996 |
} |
997 |
|
998 |
/**
|
999 |
* This method initializes btnParentesis
|
1000 |
*
|
1001 |
* @return javax.swing.JButton
|
1002 |
*/
|
1003 |
private javax.swing.JButton getBtnParentesis() {
|
1004 |
if (btnParentesis == null) { |
1005 |
btnParentesis = new javax.swing.JButton();
|
1006 |
btnParentesis.setText("()");
|
1007 |
btnParentesis.setMargin(new java.awt.Insets(2, 2, 2, 2)); |
1008 |
btnParentesis.setPreferredSize(new java.awt.Dimension(40, 20)); |
1009 |
btnParentesis.addActionListener(new java.awt.event.ActionListener() {
|
1010 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
1011 |
putSymbol(" () ");
|
1012 |
} |
1013 |
}); |
1014 |
} |
1015 |
|
1016 |
return btnParentesis;
|
1017 |
} |
1018 |
|
1019 |
/**
|
1020 |
* This method initializes btnName
|
1021 |
*
|
1022 |
* @return javax.swing.JButton
|
1023 |
*/
|
1024 |
private javax.swing.JButton getBtnName() {
|
1025 |
if (btnName == null) { |
1026 |
btnName = new javax.swing.JButton();
|
1027 |
btnName.setText("Date");
|
1028 |
btnName.addActionListener(new java.awt.event.ActionListener() {
|
1029 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
1030 |
JDateChooser chooser = new JDateChooser();
|
1031 |
|
1032 |
PluginServices.getMDIManager().addView(chooser); |
1033 |
|
1034 |
Date selectedDate = chooser.getSelectedDate().getTime();
|
1035 |
|
1036 |
if (selectedDate != null) { |
1037 |
putSymbol("Date(" + df.format(selectedDate) + ")"); |
1038 |
} |
1039 |
} |
1040 |
}); |
1041 |
} |
1042 |
|
1043 |
return btnName;
|
1044 |
} |
1045 |
|
1046 |
/**
|
1047 |
* DOCUMENT ME!
|
1048 |
*
|
1049 |
* @param arg0
|
1050 |
*
|
1051 |
* @return
|
1052 |
*/
|
1053 |
public boolean addExpressionListener(ExpressionListener arg0) { |
1054 |
return expressionListeners.add(arg0);
|
1055 |
} |
1056 |
|
1057 |
/**
|
1058 |
* DOCUMENT ME!
|
1059 |
*
|
1060 |
* @param arg0
|
1061 |
*
|
1062 |
* @return
|
1063 |
*/
|
1064 |
public boolean removeExpressionListener(ExpressionListener arg0) { |
1065 |
return expressionListeners.remove(arg0);
|
1066 |
} |
1067 |
|
1068 |
/**
|
1069 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
1070 |
*/
|
1071 |
public ViewInfo getViewInfo() {
|
1072 |
ViewInfo vi = new ViewInfo(ViewInfo.ICONIFIABLE);
|
1073 |
vi.setWidth(480);
|
1074 |
vi.setHeight(362);
|
1075 |
|
1076 |
return vi;
|
1077 |
} |
1078 |
|
1079 |
/**
|
1080 |
* DOCUMENT ME!
|
1081 |
*
|
1082 |
* @param o DOCUMENT ME!
|
1083 |
*/
|
1084 |
public void addExceptionListener(ExceptionListener o) { |
1085 |
exceptionHandlingSupport.addExceptionListener(o); |
1086 |
} |
1087 |
|
1088 |
/**
|
1089 |
* DOCUMENT ME!
|
1090 |
*
|
1091 |
* @param o DOCUMENT ME!
|
1092 |
*
|
1093 |
* @return DOCUMENT ME!
|
1094 |
*/
|
1095 |
public boolean removeExceptionListener(ExceptionListener o) { |
1096 |
return exceptionHandlingSupport.removeExceptionListener(o);
|
1097 |
} |
1098 |
|
1099 |
/**
|
1100 |
* DOCUMENT ME!
|
1101 |
*
|
1102 |
* @param t DOCUMENT ME!
|
1103 |
*/
|
1104 |
private void throwException(Throwable t) { |
1105 |
exceptionHandlingSupport.throwException(t); |
1106 |
} |
1107 |
|
1108 |
/* (non-Javadoc)
|
1109 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewActivated()
|
1110 |
*/
|
1111 |
public void viewActivated() { |
1112 |
} |
1113 |
|
1114 |
/* (non-Javadoc)
|
1115 |
* @see com.iver.andami.ui.mdiManager.ViewListener#viewClosed()
|
1116 |
*/
|
1117 |
public void viewClosed() { |
1118 |
try {
|
1119 |
model.stop(); |
1120 |
} catch (DriverException e) {
|
1121 |
NotificationManager.addError(e.getMessage(), e); |
1122 |
} |
1123 |
} |
1124 |
} |
1125 |
|
1126 |
// @jve:visual-info decl-index=0 visual-constraint="10,10"
|