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