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