Revision 3373 org.gvsig.legend.vectorfilterexpression.app.mainplugin/trunk/org.gvsig.legend.vectorfilterexpression.app.mainplugin/src/main/java/org/gvsig/symbology/gui/layerproperties/VectorFilterExpressionPanel.java
VectorFilterExpressionPanel.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
2 | 3 |
* |
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
|
4 | 5 |
* |
5 | 6 |
* This program is free software; you can redistribute it and/or |
6 | 7 |
* modify it under the terms of the GNU General Public License |
7 |
* as published by the Free Software Foundation; either version 2
|
|
8 |
* as published by the Free Software Foundation; either version 3
|
|
8 | 9 |
* of the License, or (at your option) any later version. |
9 | 10 |
* |
10 | 11 |
* This program is distributed in the hope that it will be useful, |
... | ... | |
14 | 15 |
* |
15 | 16 |
* You should have received a copy of the GNU General Public License |
16 | 17 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
18 | 20 |
* |
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 |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
40 | 23 |
*/ |
41 | 24 |
package org.gvsig.symbology.gui.layerproperties; |
42 | 25 |
|
... | ... | |
55 | 38 |
import javax.swing.JCheckBox; |
56 | 39 |
import javax.swing.JOptionPane; |
57 | 40 |
import javax.swing.JPanel; |
41 |
import org.apache.commons.lang3.StringUtils; |
|
58 | 42 |
|
59 | 43 |
import org.slf4j.Logger; |
60 | 44 |
import org.slf4j.LoggerFactory; |
61 | 45 |
|
62 | 46 |
import org.gvsig.andami.IconThemeHelper; |
63 |
import org.gvsig.andami.ui.mdiManager.MDIManager; |
|
64 | 47 |
import org.gvsig.app.ApplicationLocator; |
65 | 48 |
import org.gvsig.app.project.documents.view.legend.gui.Categories; |
66 | 49 |
import org.gvsig.app.project.documents.view.legend.gui.ILegendPanel; |
... | ... | |
82 | 65 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.PictureFillSymbol; |
83 | 66 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle; |
84 | 67 |
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend; |
85 |
import org.gvsig.symbology.fmap.rendering.filterexpression.EvaluatorCreator;
|
|
86 |
import org.gvsig.tools.evaluator.EvaluatorWithDescriptions;
|
|
68 |
import org.gvsig.tools.ToolsLocator;
|
|
69 |
import org.gvsig.tools.i18n.I18nManager;
|
|
87 | 70 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
88 | 71 |
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
72 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
73 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
|
74 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
89 | 75 |
|
90 | 76 |
/** |
91 | 77 |
* Implements the JPanel that shows the properties of a |
92 | 78 |
* VectorialFilterExpressionLegend |
93 | 79 |
* in order to allows the user to modify its characteristics |
94 | 80 |
* |
95 |
* @author Pepe Vidal Salvador - jose.vidal.salvador@iver.es
|
|
81 |
* @author gvSIG Team
|
|
96 | 82 |
* |
97 | 83 |
*/ |
98 | 84 |
public class VectorFilterExpressionPanel extends JPanel |
... | ... | |
110 | 96 |
private JPanel pnlMovBut; |
111 | 97 |
private SymbolTable symbolTable; |
112 | 98 |
private JButton btnAddExpression; |
113 |
private JButton btnModExpression; |
|
99 |
// private JButton btnModExpression;
|
|
114 | 100 |
private JButton btnRemoveExpression; |
115 | 101 |
private JButton moveUp; |
116 | 102 |
private JButton moveDown; |
... | ... | |
139 | 125 |
|
140 | 126 |
JPanel pnlButtons = new JPanel(); |
141 | 127 |
btnAddExpression = usabilitySwingManager.createJButton( |
142 |
Messages.getText("new_filter_expression"));
|
|
128 |
Messages.getText("Anadir"));
|
|
143 | 129 |
btnAddExpression.setActionCommand("NEW_EXPRESSION"); |
144 | 130 |
btnAddExpression.addActionListener(this); |
145 | 131 |
pnlButtons.add(btnAddExpression); |
146 | 132 |
|
147 |
btnModExpression = usabilitySwingManager.createJButton( |
|
148 |
Messages.getText("modify_filter_expression")); |
|
149 |
btnModExpression.setActionCommand("MODIFY_EXPRESSION"); |
|
150 |
btnModExpression.addActionListener(this); |
|
151 |
pnlButtons.add(btnModExpression); |
|
133 |
// btnModExpression = usabilitySwingManager.createJButton(
|
|
134 |
// Messages.getText("modify_filter_expression"));
|
|
135 |
// btnModExpression.setActionCommand("MODIFY_EXPRESSION");
|
|
136 |
// btnModExpression.addActionListener(this);
|
|
137 |
// pnlButtons.add(btnModExpression);
|
|
152 | 138 |
|
153 | 139 |
btnRemoveExpression = usabilitySwingManager.createJButton( |
154 |
Messages.getText("delete_filter_expression"));
|
|
140 |
Messages.getText("Quitar"));
|
|
155 | 141 |
btnRemoveExpression.setActionCommand("REMOVE"); |
156 | 142 |
btnRemoveExpression.addActionListener(this); |
157 | 143 |
pnlButtons.add(btnRemoveExpression); |
... | ... | |
307 | 293 |
getDefaultSymbolPrev(shapeType); |
308 | 294 |
|
309 | 295 |
symbolTable = new SymbolTable(this, "expressions", shapeType); |
296 |
try { |
|
297 |
ExpressionFieldCellEditor cellEditor = new ExpressionFieldCellEditor( |
|
298 |
((FLyrVect)layer).getFeatureStore() |
|
299 |
); |
|
300 |
symbolTable.setCellEditor(cellEditor); |
|
301 |
} catch(Exception ex) { |
|
302 |
|
|
303 |
} |
|
310 | 304 |
pnlCenter.add(symbolTable, BorderLayout.CENTER); |
311 | 305 |
pnlCenter.add(getPnlMovBut(),BorderLayout.EAST); |
312 | 306 |
|
... | ... | |
388 | 382 |
for (int i = 0; i < symbolTable.getRowCount(); i++) { |
389 | 383 |
orders.add(symbolTable.getFieldValue(i,1).toString()); |
390 | 384 |
} |
391 |
} |
|
392 |
if (e.getActionCommand() == "NEW_EXPRESSION") { |
|
385 |
|
|
386 |
} if (e.getActionCommand() == "NEW_EXPRESSION") {
|
|
393 | 387 |
|
394 | 388 |
FLyrVect vect = (FLyrVect) layer; |
395 |
FeatureStore fsto = (FeatureStore) vect.getDataStore(); |
|
396 |
FeatureType fty = null; |
|
397 |
int shptype = 0; |
|
389 |
final FeatureStore fsto = vect.getFeatureStore(); |
|
390 |
final FeatureType fty = fsto.getDefaultFeatureTypeQuietly(); |
|
391 |
final int shptype = fty.getDefaultGeometryAttribute().getGeomType().getType(); |
|
392 |
final I18nManager i18n = ToolsLocator.getI18nManager(); |
|
393 |
final ExpressionSymbolPanel esp = new ExpressionSymbolPanel(fsto, shptype, previewSymbol); |
|
394 |
final WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
395 |
final Dialog dialog = windowManager.createDialog( |
|
396 |
esp, |
|
397 |
i18n.getTranslation("expression_creator"), |
|
398 |
"", |
|
399 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
400 |
); |
|
401 |
dialog.addActionListener((ActionEvent e1) -> { |
|
402 |
if( dialog.getAction()!=WindowManager_v2.BUTTON_OK ) { |
|
403 |
return; |
|
404 |
} |
|
405 |
String expr = esp.getExpression(); |
|
406 |
if ( StringUtils.isBlank(expr) ) { |
|
407 |
ApplicationLocator.getManager().messageDialog( |
|
408 |
Messages.getText("error_validating_filter_query"), |
|
409 |
Messages.getText("error"), |
|
410 |
JOptionPane.ERROR_MESSAGE); |
|
411 |
return; |
|
412 |
} |
|
413 |
ISymbol sym = esp.getSymbol(); |
|
414 |
this.addClassFieldNames(fty); |
|
398 | 415 |
|
399 |
try { |
|
400 |
fty = fsto.getDefaultFeatureType(); |
|
401 |
shptype = vect.getGeometryType().getType(); |
|
402 |
dummyFeat = fsto.createNewFeature(true); |
|
403 |
} catch (Exception exc) { |
|
404 |
logger.error(Messages.getText( |
|
405 |
"error_trying_to_access_to_the_layer"), exc); |
|
406 |
return; |
|
407 |
} |
|
416 |
auxLegend.addSymbol(expr, sym); |
|
417 |
symbolTable.removeAllItems(); |
|
418 |
fillTableSkipDefault(auxLegend); |
|
408 | 419 |
|
409 |
EvaluatorWithDescriptions evalu = EvaluatorCreator.getEvaluator(""); |
|
410 |
MDIManager mm = ApplicationLocator.getManager().getUIManager(); |
|
420 |
repaint(); |
|
421 |
}); |
|
422 |
dialog.show(WindowManager.MODE.DIALOG); |
|
423 |
// |
|
424 |
// } |
|
425 |
// else if (e.getActionCommand() == "MODIFY_EXPRESSION") { |
|
426 |
// |
|
427 |
// if(symbolTable.getSelectedRowElements() == null) { |
|
428 |
// JOptionPane.showMessageDialog(this, |
|
429 |
// Messages.getText("select_one_row")+".\n"); |
|
430 |
// } else { |
|
431 |
// |
|
432 |
// FLyrVect vect = (FLyrVect) layer; |
|
433 |
// FeatureStore fsto = (FeatureStore) vect.getDataStore(); |
|
434 |
// FeatureType fty = null; |
|
435 |
// int shptype = 0; |
|
436 |
// try { |
|
437 |
// fty = fsto.getDefaultFeatureType(); |
|
438 |
// shptype = vect.getGeometryType().getType(); |
|
439 |
// dummyFeat = fsto.createNewFeature(true); |
|
440 |
// } catch (Exception exc) { |
|
441 |
// logger.error(Messages.getText( |
|
442 |
// "error_trying_to_access_to_the_layer"), exc); |
|
443 |
// return; |
|
444 |
// } |
|
445 |
// |
|
446 |
// ISymbol mySymbol = (ISymbol) symbolTable.getSelectedRowElements()[0]; |
|
447 |
// String expression = (String) symbolTable.getSelectedRowElements()[1]; |
|
448 |
// |
|
449 |
// EvaluatorWithDescriptions evalu = |
|
450 |
// EvaluatorCreator.getEvaluator(expression); |
|
451 |
// |
|
452 |
// MDIManager mm = ApplicationLocator.getManager().getUIManager(); |
|
453 |
// ExpressionSymbolPanel esp = new ExpressionSymbolPanel( |
|
454 |
// dummyFeat, evalu, shptype, mySymbol); |
|
455 |
// mm.addCentredWindow(esp); |
|
456 |
// /* |
|
457 |
// * esp is modal |
|
458 |
// */ |
|
459 |
// if (!esp.isOkPressed()) { |
|
460 |
// return; |
|
461 |
// } |
|
462 |
// |
|
463 |
// String expr = esp.getExpression(); |
|
464 |
// if (expr == null || expr.length() == 0) { |
|
465 |
// ApplicationLocator.getManager().messageDialog( |
|
466 |
// Messages.getText("error_validating_filter_query"), |
|
467 |
// Messages.getText("error"), |
|
468 |
// JOptionPane.ERROR_MESSAGE); |
|
469 |
// return; |
|
470 |
// } |
|
471 |
// |
|
472 |
// ISymbol sym = esp.getSymbol(); |
|
473 |
//// evalu = EvaluatorCreator.getEvaluator(expr); |
|
474 |
// // Add all fields in the feature type |
|
475 |
// this.addClassFieldNames(fty); |
|
476 |
// |
|
477 |
// // Remove old |
|
478 |
// auxLegend.delSymbol(expression); |
|
479 |
// auxLegend.addSymbol(expr, sym); |
|
480 |
// symbolTable.removeAllItems(); |
|
481 |
// this.fillTableSkipDefault(auxLegend); |
|
482 |
// |
|
483 |
// repaint(); |
|
484 |
// } |
|
411 | 485 |
|
412 |
ExpressionSymbolPanel esp = new ExpressionSymbolPanel( |
|
413 |
dummyFeat, evalu, shptype, null); |
|
414 |
mm.addCentredWindow(esp); |
|
486 |
} else if (e.getActionCommand() == "REMOVE") { |
|
415 | 487 |
|
416 |
/* |
|
417 |
* esp is modal |
|
418 |
*/ |
|
419 |
if (!esp.isOkPressed()) { |
|
420 |
return; |
|
421 |
} |
|
422 |
|
|
423 |
String expr = esp.getExpression(); |
|
424 |
if (expr == null || expr.length() == 0) { |
|
425 |
ApplicationLocator.getManager().messageDialog( |
|
426 |
Messages.getText("error_validating_filter_query"), |
|
427 |
Messages.getText("error"), |
|
428 |
JOptionPane.ERROR_MESSAGE); |
|
429 |
return; |
|
430 |
} |
|
431 |
|
|
432 |
ISymbol sym = esp.getSymbol(); |
|
433 |
// evalu = EvaluatorCreator.getEvaluator(expr); |
|
434 |
// Add all fields in the feature type |
|
435 |
this.addClassFieldNames(fty); |
|
436 |
|
|
437 |
auxLegend.addSymbol(expr, sym); |
|
438 |
symbolTable.removeAllItems(); |
|
439 |
fillTableSkipDefault(auxLegend); |
|
440 |
|
|
441 |
repaint(); |
|
442 |
} |
|
443 |
else if (e.getActionCommand() == "MODIFY_EXPRESSION") { |
|
444 |
|
|
445 | 488 |
if(symbolTable.getSelectedRowElements() == null) { |
446 | 489 |
JOptionPane.showMessageDialog(this, |
447 |
Messages.getText("select_one_row")+".\n"); |
|
448 |
} else { |
|
449 |
|
|
450 |
FLyrVect vect = (FLyrVect) layer; |
|
451 |
FeatureStore fsto = (FeatureStore) vect.getDataStore(); |
|
452 |
FeatureType fty = null; |
|
453 |
int shptype = 0; |
|
454 |
try { |
|
455 |
fty = fsto.getDefaultFeatureType(); |
|
456 |
shptype = vect.getGeometryType().getType(); |
|
457 |
dummyFeat = fsto.createNewFeature(true); |
|
458 |
} catch (Exception exc) { |
|
459 |
logger.error(Messages.getText( |
|
460 |
"error_trying_to_access_to_the_layer"), exc); |
|
461 |
return; |
|
462 |
} |
|
463 |
|
|
464 |
ISymbol mySymbol = (ISymbol) symbolTable.getSelectedRowElements()[0]; |
|
465 |
String expression = (String) symbolTable.getSelectedRowElements()[1]; |
|
466 |
|
|
467 |
EvaluatorWithDescriptions evalu = |
|
468 |
EvaluatorCreator.getEvaluator(expression); |
|
469 |
|
|
470 |
MDIManager mm = ApplicationLocator.getManager().getUIManager(); |
|
471 |
ExpressionSymbolPanel esp = new ExpressionSymbolPanel( |
|
472 |
dummyFeat, evalu, shptype, mySymbol); |
|
473 |
mm.addCentredWindow(esp); |
|
474 |
/* |
|
475 |
* esp is modal |
|
476 |
*/ |
|
477 |
if (!esp.isOkPressed()) { |
|
478 |
return; |
|
479 |
} |
|
480 |
|
|
481 |
String expr = esp.getExpression(); |
|
482 |
if (expr == null || expr.length() == 0) { |
|
483 |
ApplicationLocator.getManager().messageDialog( |
|
484 |
Messages.getText("error_validating_filter_query"), |
|
485 |
Messages.getText("error"), |
|
486 |
JOptionPane.ERROR_MESSAGE); |
|
487 |
return; |
|
488 |
} |
|
489 |
|
|
490 |
ISymbol sym = esp.getSymbol(); |
|
491 |
// evalu = EvaluatorCreator.getEvaluator(expr); |
|
492 |
// Add all fields in the feature type |
|
493 |
this.addClassFieldNames(fty); |
|
494 |
|
|
495 |
// Remove old |
|
496 |
auxLegend.delSymbol(expression); |
|
497 |
auxLegend.addSymbol(expr, sym); |
|
498 |
symbolTable.removeAllItems(); |
|
499 |
this.fillTableSkipDefault(auxLegend); |
|
500 |
|
|
501 |
repaint(); |
|
502 |
} |
|
503 |
} |
|
504 |
|
|
505 |
else if (e.getActionCommand() == "REMOVE") { |
|
506 |
|
|
507 |
if(symbolTable.getSelectedRowElements() == null) { |
|
508 |
JOptionPane.showMessageDialog(this, |
|
509 | 490 |
Messages.getText("select_one_row")); |
510 | 491 |
} else{ |
511 | 492 |
String my_expr = (String) symbolTable.getSelectedRowElements()[1]; |
... | ... | |
626 | 607 |
(ISymbol[]) syms.toArray(new ISymbol[0]), |
627 | 608 |
(Object[]) vals.toArray(new Object[0]), |
628 | 609 |
(String[]) descs.toArray(new String[0])); |
610 |
doUpdateCellEditor(); |
|
629 | 611 |
} |
630 | 612 |
|
613 |
private void doUpdateCellEditor() { |
|
614 |
try { |
|
615 |
ExpressionFieldCellEditor cellEditor = new ExpressionFieldCellEditor( |
|
616 |
((FLyrVect)layer).getFeatureStore() |
|
617 |
); |
|
618 |
symbolTable.setCellEditor(cellEditor); |
|
619 |
} catch(Exception ex) { |
|
620 |
logger.debug("Can't update cell editors",ex); |
|
621 |
} |
|
622 |
} |
|
631 | 623 |
|
632 | 624 |
/** |
633 | 625 |
* @param i |
Also available in: Unified diff