Revision 44011 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app.document.table.app/org.gvsig.app.document.table.app.mainplugin/src/main/java/org/gvsig/app/extension/SelectByAttributesInTableExtension.java
SelectByAttributesInTableExtension.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.app.extension; |
25 | 25 |
|
26 |
import java.awt.event.ActionEvent; |
|
27 |
import java.awt.event.ActionListener; |
|
28 |
import java.util.Iterator; |
|
29 | 26 |
|
30 | 27 |
import javax.swing.JOptionPane; |
31 | 28 |
|
... | ... | |
38 | 35 |
import org.gvsig.app.gui.filter.ExpressionListener; |
39 | 36 |
import org.gvsig.app.gui.filter.FilterDialog; |
40 | 37 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
41 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
42 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
43 |
import org.gvsig.expressionevaluator.swing.Element; |
|
44 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingLocator; |
|
45 |
import org.gvsig.expressionevaluator.swing.ExpressionEvaluatorSwingManager; |
|
46 |
import org.gvsig.expressionevaluator.swing.JExpressionBuilder; |
|
47 | 38 |
import org.gvsig.fmap.dal.DALLocator; |
48 | 39 |
import org.gvsig.fmap.dal.DataManager; |
49 | 40 |
import org.gvsig.fmap.dal.exception.DataException; |
... | ... | |
54 | 45 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
55 | 46 |
import org.gvsig.i18n.Messages; |
56 | 47 |
import org.gvsig.tools.dispose.DisposeUtils; |
57 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
58 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
|
59 | 48 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
60 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
|
61 | 49 |
import org.gvsig.utils.exceptionHandling.ExceptionListener; |
62 | 50 |
|
63 | 51 |
/** |
... | ... | |
65 | 53 |
* |
66 | 54 |
* @author Vicente Caballero Navarro |
67 | 55 |
*/ |
56 |
@SuppressWarnings("UseSpecificCatch") |
|
68 | 57 |
public class SelectByAttributesInTableExtension extends Extension implements ExpressionListener { |
69 | 58 |
|
70 | 59 |
protected FeatureStore featureStore = null; |
71 | 60 |
protected FeatureTableDocumentPanel table; |
72 | 61 |
private String filterTitle; |
73 | 62 |
|
63 |
@Override |
|
74 | 64 |
public void initialize() { |
75 | 65 |
registerIcons(); |
76 | 66 |
} |
... | ... | |
79 | 69 |
IconThemeHelper.registerIcon("action", "selection-by-attributes", this); |
80 | 70 |
} |
81 | 71 |
|
72 |
@Override |
|
82 | 73 |
public void execute(String actionCommand) { |
83 | 74 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
84 | 75 |
|
85 | 76 |
if (!(v instanceof FeatureTableDocumentPanel)) { |
86 | 77 |
return; |
87 | 78 |
} |
88 |
if ("selection-by-attributes-table2".equals(actionCommand)) {
|
|
79 |
if ("selection-by-attributes-table".equals(actionCommand)) { |
|
89 | 80 |
table = (FeatureTableDocumentPanel) v; |
90 | 81 |
|
91 | 82 |
featureStore = table.getModel().getStore(); |
92 | 83 |
filterTitle = table.getModel().getName(); |
93 | 84 |
table.getModel().setModified(true); |
94 |
|
|
95 |
doSelectByAttributes2(filterTitle, featureStore);
|
|
85 |
SelectByAttributes selector = new SelectByAttributes(); |
|
86 |
selector.showWindow(filterTitle, featureStore, WindowManager.MODE.TOOL);
|
|
96 | 87 |
|
97 |
} else if ("selection-by-attributes-table".equals(actionCommand)) { |
|
88 |
} else if ("selection-by-attributes-table-old".equals(actionCommand)) {
|
|
98 | 89 |
table = (FeatureTableDocumentPanel) v; |
99 | 90 |
|
100 | 91 |
featureStore = table.getModel().getStore(); |
... | ... | |
110 | 101 |
dlg.addExpressionListener(this); |
111 | 102 |
dlg.addExceptionListener(new ExceptionListener() { |
112 | 103 |
|
104 |
@Override |
|
113 | 105 |
public void exceptionThrown(Throwable t) { |
114 | 106 |
NotificationManager.addError(t.getMessage(), t); |
115 | 107 |
} |
... | ... | |
118 | 110 |
PluginServices.getMDIManager().addWindow(dlg); |
119 | 111 |
} |
120 | 112 |
|
113 |
@Override |
|
121 | 114 |
public boolean isEnabled() { |
122 | 115 |
return isVisible(); |
123 | 116 |
} |
124 | 117 |
|
118 |
@Override |
|
125 | 119 |
public boolean isVisible() { |
126 | 120 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
127 | 121 |
return (v instanceof FeatureTableDocumentPanel); |
128 | 122 |
} |
129 | 123 |
|
130 | 124 |
// if no filter expression -> no element selected |
125 |
@Override |
|
131 | 126 |
public void newSet(String expression) throws DataException { |
132 | 127 |
if (!this.filterExpressionFromWhereIsEmpty(expression)) { |
133 | 128 |
FeatureSet set = null; |
... | ... | |
199 | 194 |
} |
200 | 195 |
FeatureSelection oldSelection = featureStore.getFeatureSelection(); |
201 | 196 |
FeatureSelection newSelection = featureStore.createFeatureSelection(); |
202 |
Iterator iterator = set.iterator(); |
|
203 |
while (iterator.hasNext()) { |
|
204 |
Feature feature = (Feature) iterator.next(); |
|
197 |
for (Feature feature : set) { |
|
205 | 198 |
if (oldSelection.isSelected(feature)) { |
206 | 199 |
newSelection.select(feature); |
207 | 200 |
} |
... | ... | |
279 | 272 |
} |
280 | 273 |
return p.getMessage(); |
281 | 274 |
} |
282 |
|
|
283 |
private void doSelectByAttributes2(String title, final FeatureStore store) { |
|
284 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
|
285 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
286 |
ExpressionEvaluatorSwingManager swingManager = ExpressionEvaluatorSwingLocator.getManager(); |
|
287 |
|
|
288 |
final JExpressionBuilder panel = swingManager.createJExpressionBuilder(); |
|
289 |
Element element = swingManager.createElement("DAL.FeatureStoreElement", panel, store); |
|
290 |
if (element != null) { |
|
291 |
panel.getElements().add(element); |
|
292 |
} |
|
293 |
final Dialog dialog = windowManager.createDialog( |
|
294 |
panel.asJComponent(), |
|
295 |
title, |
|
296 |
null, |
|
297 |
WindowManager_v2.BUTTONS_OK_CANCEL |
|
298 |
); |
|
299 |
dialog.addActionListener(new ActionListener() { |
|
300 |
@Override |
|
301 |
public void actionPerformed(ActionEvent e) { |
|
302 |
if (dialog.getAction() == WindowManager_v2.BUTTON_OK) { |
|
303 |
try { |
|
304 |
DataManager manager = DALLocator.getDataManager(); |
|
305 |
|
|
306 |
FeatureQuery query = store.createFeatureQuery(); |
|
307 |
query.setFilter(manager.createExpresion(panel.getExpression())); |
|
308 |
FeatureSet selection = store.getFeatureSet(query); |
|
309 |
store.getFeatureSelection().select(selection); |
|
310 |
} catch (Exception ex) { |
|
311 |
logger.warn("Can't build selecction from filter expression.", ex); |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
}); |
|
316 |
dialog.show(WindowManager.MODE.WINDOW); |
|
317 |
|
|
318 |
} |
|
319 | 275 |
} |
Also available in: Unified diff