root / trunk / extensions / extSymbology / src / com / iver / cit / gvsig / project / documents / view / legend / gui / ExpressionCreator.java @ 20768
History | View | Annotate | Download (21.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.project.documents.view.legend.gui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Component; |
45 |
import java.awt.Dimension; |
46 |
import java.awt.event.ActionEvent; |
47 |
import java.awt.event.ActionListener; |
48 |
import java.awt.event.KeyEvent; |
49 |
import java.awt.event.KeyListener; |
50 |
import java.awt.event.MouseEvent; |
51 |
import java.awt.event.MouseListener; |
52 |
import java.awt.event.MouseMotionListener; |
53 |
import java.io.StringReader; |
54 |
import java.sql.Types; |
55 |
import java.util.Hashtable; |
56 |
|
57 |
import javax.swing.JButton; |
58 |
import javax.swing.JList; |
59 |
import javax.swing.JOptionPane; |
60 |
import javax.swing.JPanel; |
61 |
import javax.swing.JScrollPane; |
62 |
import javax.swing.JTextArea; |
63 |
|
64 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
65 |
import org.gvsig.symbology.fmap.rendering.filter.operations.Expression; |
66 |
import org.gvsig.symbology.fmap.rendering.filter.operations.ExpressionException; |
67 |
import org.gvsig.symbology.fmap.rendering.filter.operations.OperatorsUtils; |
68 |
import org.gvsig.symbology.fmap.rendering.filter.parser.ExpressionParser; |
69 |
import org.gvsig.symbology.fmap.rendering.filter.parser.ParseException; |
70 |
|
71 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
72 |
import com.hardcode.gdbms.engine.data.DataSource; |
73 |
import com.hardcode.gdbms.engine.values.Value; |
74 |
import com.iver.andami.PluginServices; |
75 |
import com.iver.andami.messages.NotificationManager; |
76 |
import com.iver.andami.ui.mdiManager.IWindow; |
77 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
78 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
79 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
80 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
81 |
|
82 |
|
83 |
|
84 |
/**
|
85 |
* Implements the panel which is used to create or modify an
|
86 |
* specific filter expression contained in a VectorialFilterExpressionLegend.
|
87 |
* @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
|
88 |
*
|
89 |
*/
|
90 |
public class ExpressionCreator extends JPanel implements IWindow { |
91 |
|
92 |
|
93 |
private static final long serialVersionUID = 1L; |
94 |
private FLyrVect layer;
|
95 |
private String[] fieldNames; |
96 |
private String[] operators; |
97 |
private int width = 750; |
98 |
private int height = 440; |
99 |
private DataSource dataSource; |
100 |
private Object[] fieldNamesExpression; |
101 |
private ExpressionParser parser;
|
102 |
private ISymbol symbolForExpression;
|
103 |
private String descriptionForExpression; |
104 |
private int shapeType; |
105 |
private JButton addExpressBut; |
106 |
private JButton addOperatorBut; |
107 |
private JButton butVerify; |
108 |
private JButton butClear; |
109 |
private AcceptCancelPanel acceptCancelPanel;
|
110 |
|
111 |
private JTextArea expressionArea; |
112 |
private JList fieldNamesList; |
113 |
private JList operatorsList; |
114 |
private JTextArea fieldPatternText = new JTextArea(); |
115 |
private JTextArea operatorPatternText = new JTextArea(); |
116 |
private JSymbolPreviewButton symbol;
|
117 |
private JTextArea description; |
118 |
|
119 |
private MyListener myBehavior = new MyListener(); |
120 |
|
121 |
|
122 |
String expression=""; |
123 |
/**
|
124 |
* Constructor method
|
125 |
* @param vect
|
126 |
*/
|
127 |
public ExpressionCreator(FLyrVect vect) {
|
128 |
super();
|
129 |
this.layer = vect;
|
130 |
this.setOperators(operators);
|
131 |
getShapeType(); |
132 |
fieldNamesList = getFieldNames(); |
133 |
operatorsList = getFieldOperators(); |
134 |
initialize(); |
135 |
} |
136 |
/**
|
137 |
* This method initializes this
|
138 |
*
|
139 |
*/
|
140 |
private void initialize() { |
141 |
|
142 |
JPanel topPanel = new JPanel(); |
143 |
topPanel.add(getFieldsPanel()); |
144 |
topPanel.add(getButtonsPanel()); |
145 |
topPanel.add(getOperatorsPanel()); |
146 |
|
147 |
expressionArea = new JTextArea(); |
148 |
expressionArea.setColumns(60);
|
149 |
expressionArea.setRows(3);
|
150 |
JScrollPane expressionScroll = new JScrollPane(expressionArea); |
151 |
expressionScroll.setPreferredSize(new Dimension(this.width-200, (this.height)/7)); |
152 |
|
153 |
JPanel centPanel = new JPanel(); |
154 |
centPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
155 |
null, PluginServices.getText(this,"expression"), |
156 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
157 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
158 |
centPanel.add(expressionScroll, null);
|
159 |
|
160 |
JPanel buttPanel = new JPanel(); |
161 |
buttPanel.setPreferredSize(new Dimension (100, this.height/7)); |
162 |
|
163 |
buttPanel.add(getButVerify()); |
164 |
buttPanel.add(getButClear()); |
165 |
|
166 |
centPanel.add(buttPanel); |
167 |
|
168 |
JPanel symAndDescPanel = new JPanel(); |
169 |
symAndDescPanel.add(getSymbol()); |
170 |
symAndDescPanel.add(getDescriptionPanel()); |
171 |
|
172 |
JPanel bottomPanel = new JPanel(); |
173 |
acceptCancelPanel = new AcceptCancelPanel(action, action);
|
174 |
bottomPanel.add(acceptCancelPanel, BorderLayout.SOUTH);
|
175 |
bottomPanel.setPreferredSize(new Dimension(200,35)); |
176 |
|
177 |
this.add(topPanel);
|
178 |
this.add(centPanel);
|
179 |
this.add(symAndDescPanel);
|
180 |
this.add(bottomPanel);
|
181 |
} |
182 |
|
183 |
private JPanel getOperatorsPanel() { |
184 |
JScrollPane operatorsScroll = new JScrollPane(operatorsList); |
185 |
operatorsScroll.setPreferredSize(new Dimension(this.width/4, this.height/5)); |
186 |
|
187 |
JPanel operatorsPanel = new JPanel(); |
188 |
operatorsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
189 |
null, PluginServices.getText(this,"operators"), |
190 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
191 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
192 |
operatorsPanel.setPreferredSize(new Dimension((this.width)/3,(this.height+160)/3)); |
193 |
|
194 |
operatorPatternText.setEnabled(false);
|
195 |
JScrollPane patternOperators = new JScrollPane(operatorPatternText); |
196 |
patternOperators.setBorder(javax.swing.BorderFactory.createTitledBorder( |
197 |
null, PluginServices.getText(this,"pattern"), |
198 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
199 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
200 |
patternOperators.setPreferredSize(new Dimension((this.width-50)/3, (this.height+40)/7)); |
201 |
|
202 |
operatorsPanel.add(operatorsScroll, null);
|
203 |
operatorsPanel.add(patternOperators, null);
|
204 |
|
205 |
return operatorsPanel;
|
206 |
} |
207 |
|
208 |
private JPanel getFieldsPanel() { |
209 |
|
210 |
JPanel fieldPanel = new JPanel(); |
211 |
JScrollPane fieldsScroll = new JScrollPane(fieldNamesList); |
212 |
fieldsScroll.setPreferredSize(new Dimension(this.width/4, this.height/5)); |
213 |
|
214 |
|
215 |
fieldPanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
216 |
null, PluginServices.getText(this,"fields_exp"), |
217 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
218 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
219 |
fieldPanel.setPreferredSize(new Dimension((this.width)/3,(this.height+160)/3)); |
220 |
|
221 |
|
222 |
fieldPatternText.setEnabled(false);
|
223 |
JScrollPane patternFields = new JScrollPane(fieldPatternText); |
224 |
patternFields.setBorder(javax.swing.BorderFactory.createTitledBorder( |
225 |
null, PluginServices.getText(this,"pattern"), |
226 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
227 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
228 |
patternFields.setPreferredSize(new Dimension((this.width-50)/3, (this.height+40)/7)); |
229 |
|
230 |
fieldPanel.add(fieldsScroll, null);
|
231 |
fieldPanel.add(patternFields,null);
|
232 |
|
233 |
return fieldPanel;
|
234 |
} |
235 |
|
236 |
private JPanel getButtonsPanel() { |
237 |
JPanel myPanelBut = new JPanel(); |
238 |
|
239 |
addExpressBut = new JButton(PluginServices.getText(this, "add_expression")); |
240 |
addExpressBut.addActionListener(action); |
241 |
myPanelBut.add(addExpressBut); |
242 |
|
243 |
addOperatorBut = new JButton(PluginServices.getText(this, "add_operator")); |
244 |
addOperatorBut.addActionListener(action); |
245 |
|
246 |
myPanelBut.add(addOperatorBut); |
247 |
|
248 |
return myPanelBut;
|
249 |
} |
250 |
|
251 |
private JButton getButClear() { |
252 |
if(butClear == null) { |
253 |
butClear = new JButton(); |
254 |
butClear.setText(PluginServices.getText(this, "clear")); |
255 |
butClear.setPreferredSize(new Dimension(80,20 )); |
256 |
butClear.addActionListener(action); |
257 |
} |
258 |
return butClear;
|
259 |
} |
260 |
|
261 |
private JButton getButVerify() { |
262 |
if(butVerify == null) { |
263 |
butVerify = new JButton(); |
264 |
butVerify.setText(PluginServices.getText(this, "verify")); |
265 |
butVerify.setPreferredSize(new Dimension(80,20 )); |
266 |
butVerify.addActionListener(action); |
267 |
} |
268 |
return butVerify;
|
269 |
} |
270 |
|
271 |
private JList getFieldNames() { |
272 |
|
273 |
try {
|
274 |
dataSource = this.layer.getRecordset();
|
275 |
dataSource.start(); |
276 |
this.fieldNames = dataSource.getFieldNames();
|
277 |
dataSource.stop(); |
278 |
} catch (ReadDriverException e) {
|
279 |
NotificationManager.addError(PluginServices.getText(this,"error_trying_to_access_to_the_layer"),e); |
280 |
} |
281 |
|
282 |
JList myList = new JList(fieldNames); |
283 |
myList.addMouseListener(myBehavior); |
284 |
myList.addMouseMotionListener(myBehavior); |
285 |
myList.addKeyListener(myBehavior); |
286 |
|
287 |
return myList;
|
288 |
} |
289 |
|
290 |
private JList getFieldOperators() { |
291 |
|
292 |
String[] myOperators = new String [OperatorsUtils.getOperatorNames().length]; |
293 |
for (int i = 0; i < OperatorsUtils.getOperatorNames().length; i++) { |
294 |
myOperators[i] = OperatorsUtils.getOperatorNames()[i].toString(); |
295 |
} |
296 |
JList myFieldOperators = new JList(myOperators); |
297 |
myFieldOperators.addMouseListener(myBehavior); |
298 |
myFieldOperators.addMouseMotionListener(myBehavior); |
299 |
myFieldOperators.addKeyListener(myBehavior); |
300 |
|
301 |
return myFieldOperators;
|
302 |
} |
303 |
|
304 |
private JScrollPane getDescriptionPanel() { |
305 |
if(description == null) { |
306 |
description = new JTextArea(); |
307 |
description.setColumns(65);
|
308 |
description.setRows(3);
|
309 |
|
310 |
JScrollPane scroll = new JScrollPane(description); |
311 |
scroll.setBorder(javax.swing.BorderFactory.createTitledBorder( |
312 |
null, PluginServices.getText(this,"description"), |
313 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
314 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
315 |
return scroll;
|
316 |
} |
317 |
return null; |
318 |
} |
319 |
|
320 |
private JPanel getSymbol() { |
321 |
if(symbol == null) { |
322 |
JPanel panel = new JPanel(); |
323 |
symbol = new JSymbolPreviewButton(getShapeType());
|
324 |
symbol.setSymbol(SymbologyFactory.createDefaultSymbolByShapeType(shapeType)); |
325 |
symbol.setPreferredSize(new Dimension(100,35)); |
326 |
panel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
327 |
null, PluginServices.getText(this,"symbol"), |
328 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
329 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
330 |
panel.add(symbol); |
331 |
return panel;
|
332 |
} |
333 |
return null; |
334 |
} |
335 |
|
336 |
/**
|
337 |
* Obtains the shapetype of the layer
|
338 |
*
|
339 |
* @return int shapetype of the layer
|
340 |
*/
|
341 |
private int getShapeType() { |
342 |
|
343 |
try {
|
344 |
shapeType = layer.getShapeType(); |
345 |
} catch (ReadDriverException e) {
|
346 |
NotificationManager.addError(PluginServices.getText(this,"error_trying_to_access_to_the_layer"),e); |
347 |
} |
348 |
return shapeType;
|
349 |
} |
350 |
|
351 |
|
352 |
|
353 |
|
354 |
public WindowInfo getWindowInfo() {
|
355 |
WindowInfo wi = new WindowInfo(WindowInfo.MODALDIALOG);
|
356 |
wi.setTitle(PluginServices.getText(this, "expression_creator")); |
357 |
wi.setWidth(this.width);
|
358 |
wi.setHeight(this.height);
|
359 |
return wi;
|
360 |
} |
361 |
|
362 |
|
363 |
private ActionListener action = new ActionListener() { |
364 |
|
365 |
Object[] options = {PluginServices.getText(this, "yes"), |
366 |
PluginServices.getText(this, "no"), |
367 |
PluginServices.getText(this, "cancel")}; |
368 |
|
369 |
public void actionPerformed(ActionEvent e) { |
370 |
String actionCommand = e.getActionCommand();
|
371 |
if ("OK".equals(actionCommand)) { |
372 |
if(verifyExpression() && symbol.getSymbol() != null) { |
373 |
setExpression(expressionArea.getText()); |
374 |
setFieldNamesExpression(parser.getClassNames().toArray()); |
375 |
setDescriptionForExpression(description.getText()); |
376 |
setSymbolForExpression(symbol.getSymbol()); |
377 |
PluginServices.getMDIManager().closeWindow(ExpressionCreator.this); |
378 |
} |
379 |
int answer = 0; |
380 |
|
381 |
if(!verifyExpression()) {
|
382 |
answer = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
383 |
PluginServices.getText(this, "malformed_or_empty_expression")+"\n"+ |
384 |
PluginServices.getText(this, "it_will_not_be_added"), |
385 |
PluginServices.getText(this, "confirmation_dialog"), |
386 |
JOptionPane.YES_NO_CANCEL_OPTION,
|
387 |
JOptionPane.QUESTION_MESSAGE,
|
388 |
null,
|
389 |
options, options[1]);
|
390 |
|
391 |
if (answer==JOptionPane.OK_OPTION) { |
392 |
setExpression(null);
|
393 |
PluginServices.getMDIManager().closeWindow(ExpressionCreator.this); |
394 |
} |
395 |
|
396 |
|
397 |
} |
398 |
else if(symbol.getSymbol() == null) { |
399 |
answer = JOptionPane.showOptionDialog((Component)PluginServices.getMainFrame(), |
400 |
PluginServices.getText(this, "no_symbol_especified")+"\n"+ |
401 |
PluginServices.getText(this,"a_default_symbol_will_be_used"), |
402 |
PluginServices.getText(this, "confirmation_dialog"), |
403 |
JOptionPane.YES_NO_CANCEL_OPTION,
|
404 |
JOptionPane.QUESTION_MESSAGE,
|
405 |
null,
|
406 |
options, options[1]);
|
407 |
|
408 |
if (answer==JOptionPane.OK_OPTION) { |
409 |
setExpression(expressionArea.getText()); |
410 |
setFieldNamesExpression(parser.getClassNames().toArray()); |
411 |
setDescriptionForExpression(description.getText()); |
412 |
setSymbolForExpression(SymbologyFactory.createDefaultSymbolByShapeType(shapeType)); |
413 |
PluginServices.getMDIManager().closeWindow(ExpressionCreator.this); |
414 |
} |
415 |
|
416 |
} |
417 |
} |
418 |
else if ("CANCEL".equals(actionCommand)){ |
419 |
setExpression(null);
|
420 |
PluginServices.getMDIManager().closeWindow(ExpressionCreator.this); |
421 |
} |
422 |
else if (e.getSource().equals(addExpressBut)) { |
423 |
if(fieldNamesList.getSelectedValue() != null) { |
424 |
expressionArea.append(" ["+fieldNamesList.getSelectedValue().toString()+"]"); |
425 |
} |
426 |
} |
427 |
else if (e.getSource().equals(addOperatorBut)) { |
428 |
if(operatorsList.getSelectedValue() != null) { |
429 |
expressionArea.append(" "+operatorsList.getSelectedValue().toString());
|
430 |
} |
431 |
} |
432 |
else if (e.getSource().equals(butClear)) { |
433 |
expressionArea.setText("");
|
434 |
expression = "";
|
435 |
} |
436 |
else if (e.getSource().equals(butVerify)) { |
437 |
|
438 |
if(expressionArea.getText().compareTo("") == 0) { |
439 |
JOptionPane.showMessageDialog(butVerify, PluginServices.getText(this, "no_expression_defined")+"\n"); |
440 |
} |
441 |
else {
|
442 |
Expression exp = null; |
443 |
Hashtable<String, Value> symbols = getSymbolsTable(fieldNames); |
444 |
|
445 |
try {
|
446 |
parser = new ExpressionParser(new StringReader(expressionArea.getText())); |
447 |
parser.Expression(); |
448 |
parser.getStack(); |
449 |
exp = parser.getExpression(); |
450 |
exp.check(symbols); |
451 |
if(exp.evaluate(symbols).toString().compareTo("true") == 0 || |
452 |
exp.evaluate(symbols).toString().compareTo("false") == 0) |
453 |
JOptionPane.showMessageDialog(butVerify,PluginServices.getText(this, "correct_expression")+"\n"); |
454 |
else
|
455 |
JOptionPane.showMessageDialog(butVerify, PluginServices.getText(this, "incorrect_expression")+"\n-"+ |
456 |
PluginServices.getText(this,"the_result_is_not_a_boolean_value")+"\n"); |
457 |
|
458 |
} catch (ParseException e1) { |
459 |
JOptionPane.showMessageDialog(butVerify, PluginServices.getText(this, "incorrect_expression")+"\n"); |
460 |
|
461 |
} catch (ExpressionException e2) {
|
462 |
int type = e2.getType();
|
463 |
String message = ""; |
464 |
message+=PluginServices.getText(this, "incorrect_expression")+":"; |
465 |
|
466 |
if ((type & ExpressionException.CLASS_CASTING_EXCEPTION) != 0){ |
467 |
type = type & ~ExpressionException.CLASS_CASTING_EXCEPTION; |
468 |
message += "\n-"+PluginServices.getText(this, "some_arguments_are_incorrect")+".\n"; |
469 |
} |
470 |
if ((type & ExpressionException.INCORRECT_NUMBER_OF_ARGUMENTS) != 0){ |
471 |
type = type & ~ExpressionException.INCORRECT_NUMBER_OF_ARGUMENTS; |
472 |
message += "\n-"+PluginServices.getText(this,"the_number_or_arguments_is_incorrect")+".\n"; |
473 |
} |
474 |
if ((type & ExpressionException.ARGUMENT_ADDED_TO_CONSTANT) != 0){ |
475 |
type = type & ~ExpressionException.ARGUMENT_ADDED_TO_CONSTANT; |
476 |
message += "\n-"+PluginServices.getText(this, "arguments_added_to_a_costant")+".\n"; |
477 |
} |
478 |
if ((type & ExpressionException.DIVIDED_BY_CERO) != 0){ |
479 |
type = type & ~ExpressionException.DIVIDED_BY_CERO; |
480 |
message += "\n-"+PluginServices.getText(this, "divided_by_0")+".\n"; |
481 |
} |
482 |
if ((type & ExpressionException.NO_CLASSIF_NAME) != 0){ |
483 |
type = type & ~ExpressionException.NO_CLASSIF_NAME; |
484 |
message += "\n-"+PluginServices.getText(this, "classifying_field_name_not_found")+".\n"; |
485 |
} |
486 |
|
487 |
JOptionPane.showMessageDialog(butVerify, message);
|
488 |
} |
489 |
|
490 |
} |
491 |
} |
492 |
} |
493 |
|
494 |
}; |
495 |
|
496 |
private Hashtable<String, Value> getSymbolsTable(String[] fNames) { |
497 |
Hashtable<String, Value> parser_symbol_table = new Hashtable<String, Value>(); |
498 |
|
499 |
for (int j = 0; j < fNames.length; j++) { |
500 |
try {
|
501 |
parser_symbol_table.put(fNames[j], dataSource.getFieldValue(0, j));
|
502 |
} catch (ReadDriverException e) {
|
503 |
e.printStackTrace(); |
504 |
} |
505 |
} |
506 |
return parser_symbol_table;
|
507 |
} |
508 |
|
509 |
|
510 |
private String getFieldType(Object selectedValue) { |
511 |
String cad = null; |
512 |
int type;
|
513 |
|
514 |
try {
|
515 |
type = dataSource.getFieldType(dataSource.getFieldIndexByName(selectedValue.toString())); |
516 |
|
517 |
switch (type) {
|
518 |
case Types.INTEGER: |
519 |
case Types.BIGINT: |
520 |
case Types.DECIMAL: |
521 |
case Types.DOUBLE: |
522 |
case Types.FLOAT: |
523 |
case Types.NUMERIC: |
524 |
cad = PluginServices.getText(this, "numeric_value"); |
525 |
break;
|
526 |
case Types.LONGVARCHAR: |
527 |
case Types.VARCHAR: |
528 |
cad=PluginServices.getText(this,"string_value"); |
529 |
break;
|
530 |
case Types.BOOLEAN: |
531 |
cad=PluginServices.getText(this,"boolean_value"); |
532 |
break;
|
533 |
case Types.DATE: |
534 |
cad=PluginServices.getText(this,"date_value"); |
535 |
break;
|
536 |
} |
537 |
} catch (ReadDriverException e) {
|
538 |
e.printStackTrace(); |
539 |
} |
540 |
return cad;
|
541 |
} |
542 |
|
543 |
|
544 |
private class MyListener implements MouseListener, MouseMotionListener,KeyListener { |
545 |
|
546 |
public void mouseClicked(MouseEvent e) {/*Nothing*/} |
547 |
public void mouseEntered(MouseEvent e) {/*Nothing*/} |
548 |
public void mouseExited(MouseEvent e) {/*Nothing*/} |
549 |
public void mouseReleased(MouseEvent e) {/*Nothing*/} |
550 |
public void mouseDragged(MouseEvent e) {/*Nothing*/} |
551 |
public void mouseMoved(MouseEvent e) {/*Nothing*/} |
552 |
public void keyTyped(KeyEvent e) {/*Nothing*/} |
553 |
public void keyPressed(KeyEvent e) {/*Nothing*/} |
554 |
|
555 |
public void keyReleased(KeyEvent e) { |
556 |
if (operatorsList.getSelectedValue() != null) |
557 |
operatorPatternText.setText(OperatorsUtils.getPatternByName(operatorsList.getSelectedValue().toString())); |
558 |
if(fieldNamesList.getSelectedValue() != null) |
559 |
fieldPatternText.setText(getFieldType(fieldNamesList.getSelectedValue())); |
560 |
|
561 |
repaint(); |
562 |
} |
563 |
|
564 |
public void mousePressed(MouseEvent e) { |
565 |
if (operatorsList.getSelectedValue() != null) |
566 |
operatorPatternText.setText(OperatorsUtils.getPatternByName(operatorsList.getSelectedValue().toString())); |
567 |
if(fieldNamesList.getSelectedValue() != null) |
568 |
fieldPatternText.setText(getFieldType(fieldNamesList.getSelectedValue())); |
569 |
|
570 |
repaint(); |
571 |
} |
572 |
} |
573 |
|
574 |
private boolean verifyExpression() { |
575 |
Expression exp = null; |
576 |
Hashtable<String, Value> symbols = getSymbolsTable(fieldNames); |
577 |
|
578 |
try {
|
579 |
parser = new ExpressionParser(new StringReader(expressionArea.getText())); |
580 |
parser.Expression(); |
581 |
parser.getStack(); |
582 |
exp = parser.getExpression(); |
583 |
exp.check(symbols); |
584 |
if(exp.evaluate(symbols).toString().compareTo("true") == 0 |
585 |
|| exp.evaluate(symbols).toString().compareTo("false") == 0) |
586 |
|
587 |
return true; |
588 |
else
|
589 |
return false; |
590 |
|
591 |
} catch (ParseException e1) { |
592 |
return false; |
593 |
} catch (ExpressionException e2) {
|
594 |
return false; |
595 |
} |
596 |
|
597 |
} |
598 |
|
599 |
public String[] getOperators() {return operators;} |
600 |
public void setOperators(String[] operators) {this.operators = operators;} |
601 |
public String getExpression() {return expression;} |
602 |
|
603 |
public Object[] getFieldNamesExpression() {return fieldNamesExpression;} |
604 |
public void setFieldNamesExpression(Object[] objects) {this.fieldNamesExpression = objects;} |
605 |
public void setDescriptionForExpression(String descriptionForExpression) { |
606 |
this.descriptionForExpression = descriptionForExpression;
|
607 |
description.setText(this.descriptionForExpression);
|
608 |
} |
609 |
public void setSymbolForExpression(ISymbol symbolForExpression) { |
610 |
this.symbolForExpression = symbolForExpression;
|
611 |
this.symbol.setSymbol(this.symbolForExpression); |
612 |
} |
613 |
|
614 |
|
615 |
|
616 |
public void setExpression(String text) { |
617 |
this.expression = text;
|
618 |
expressionArea.setText(text); |
619 |
|
620 |
} |
621 |
public String getDescriptionForExpression() { |
622 |
|
623 |
if(descriptionForExpression == null || descriptionForExpression.compareTo("") == 0) |
624 |
descriptionForExpression = this.expressionArea.getText();
|
625 |
|
626 |
return descriptionForExpression;
|
627 |
} |
628 |
|
629 |
public ISymbol getSymbolForExpression() {
|
630 |
|
631 |
if(symbol.getSymbol() != null) |
632 |
symbolForExpression =symbol.getSymbol(); |
633 |
|
634 |
if(symbolForExpression == null) |
635 |
symbolForExpression = SymbologyFactory.createDefaultSymbolByShapeType(shapeType); |
636 |
|
637 |
symbolForExpression.setDescription(getDescriptionForExpression()); |
638 |
return symbolForExpression;
|
639 |
} |
640 |
} |
641 |
|