svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / searchpanel / DefaultSearchPanel.java @ 44712
History | View | Annotate | Download (31.7 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.searchpanel; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Cursor; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.net.URL; |
10 |
import java.util.ArrayList; |
11 |
import java.util.Collection; |
12 |
import java.util.Collections; |
13 |
import java.util.HashMap; |
14 |
import java.util.List; |
15 |
import java.util.Map; |
16 |
import javax.swing.AbstractAction; |
17 |
import javax.swing.Action; |
18 |
import static javax.swing.Action.ACTION_COMMAND_KEY; |
19 |
import static javax.swing.Action.NAME; |
20 |
import javax.swing.BorderFactory; |
21 |
import javax.swing.ImageIcon; |
22 |
import javax.swing.JButton; |
23 |
import javax.swing.JComponent; |
24 |
import javax.swing.SwingUtilities; |
25 |
import javax.swing.event.ListSelectionEvent; |
26 |
import javax.swing.event.ListSelectionListener; |
27 |
import javax.swing.table.TableModel; |
28 |
import org.apache.commons.io.FilenameUtils; |
29 |
import org.apache.commons.lang.mutable.MutableObject; |
30 |
import org.apache.commons.lang3.StringUtils; |
31 |
import org.gvsig.configurableactions.ConfigurableActionsMamager; |
32 |
import org.gvsig.expressionevaluator.Expression; |
33 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
34 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
35 |
import static org.gvsig.fmap.dal.DataManager.DAL_USE_LABELS; |
36 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_BOTH; |
37 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_NO; |
38 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_YES; |
39 |
import org.gvsig.fmap.dal.DataStore; |
40 |
import org.gvsig.fmap.dal.complements.Search; |
41 |
import org.gvsig.fmap.dal.feature.Feature; |
42 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
43 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
44 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
45 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
46 |
import org.gvsig.fmap.dal.feature.FeatureType; |
47 |
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory.AbstractDALActionContext; |
48 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
49 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
50 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryCalculatedColumnsPanel; |
51 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributeSelectionPanel; |
52 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel; |
53 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryGroupByPanel; |
54 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
55 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel; |
56 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory; |
57 |
import org.gvsig.tools.ToolsLocator; |
58 |
import org.gvsig.tools.dataTypes.DataType; |
59 |
import org.gvsig.tools.dynobject.Tags; |
60 |
import org.gvsig.tools.i18n.I18nManager; |
61 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
62 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
63 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
64 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
65 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
66 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
67 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
68 |
import org.gvsig.tools.util.ToolsUtilLocator; |
69 |
import org.slf4j.Logger; |
70 |
import org.slf4j.LoggerFactory; |
71 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryGroupByPanel; |
72 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryOrderPanel; |
73 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryCalculatedColumnsPanel; |
74 |
|
75 |
/**
|
76 |
*
|
77 |
* @author jjdelcerro
|
78 |
*/
|
79 |
@SuppressWarnings({"UseSpecificCatch"}) |
80 |
public class DefaultSearchPanel |
81 |
extends DefaultSearchPanelView
|
82 |
implements FeatureStoreSearchPanel {
|
83 |
|
84 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class); |
85 |
|
86 |
static /* friend */ Integer useLabels = null; |
87 |
|
88 |
public static class UseLabelsYesAction extends AbstractAction { |
89 |
|
90 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
91 |
public UseLabelsYesAction() {
|
92 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
93 |
|
94 |
this.putValue(NAME, i18n.getTranslation("_Use_labels")); |
95 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsYes"); |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public Object getValue(String key) { |
100 |
if( NAME.equals(key) ) {
|
101 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
102 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
103 |
return i18n.getTranslation("_Use_labels"); |
104 |
} |
105 |
return super.getValue(key); |
106 |
} |
107 |
|
108 |
@Override
|
109 |
public void actionPerformed(ActionEvent ae) { |
110 |
DefaultSearchPanel.useLabels = USE_LABELS_YES; |
111 |
} |
112 |
} |
113 |
|
114 |
public static class UseLabelsNoAction extends AbstractAction { |
115 |
|
116 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
117 |
public UseLabelsNoAction() {
|
118 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
119 |
this.putValue(NAME, i18n.getTranslation("_Use_names")); |
120 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsNo"); |
121 |
} |
122 |
|
123 |
@Override
|
124 |
public Object getValue(String key) { |
125 |
if( NAME.equals(key) ) {
|
126 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
127 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
128 |
return i18n.getTranslation("_Use_names"); |
129 |
} |
130 |
return super.getValue(key); |
131 |
} |
132 |
|
133 |
@Override
|
134 |
public void actionPerformed(ActionEvent ae) { |
135 |
DefaultSearchPanel.useLabels = USE_LABELS_NO; |
136 |
} |
137 |
} |
138 |
|
139 |
public static class UseLabelsBothAction extends AbstractAction { |
140 |
|
141 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
142 |
public UseLabelsBothAction() {
|
143 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
144 |
|
145 |
this.putValue(NAME, i18n.getTranslation("_Use_labels_and_names")); |
146 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsBoth"); |
147 |
} |
148 |
|
149 |
@Override
|
150 |
public Object getValue(String key) { |
151 |
if( NAME.equals(key) ) {
|
152 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
153 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
154 |
return i18n.getTranslation("_Use_labels_and_names"); |
155 |
} |
156 |
return super.getValue(key); |
157 |
} |
158 |
|
159 |
@Override
|
160 |
public void actionPerformed(ActionEvent ae) { |
161 |
DefaultSearchPanel.useLabels = USE_LABELS_BOTH; |
162 |
} |
163 |
} |
164 |
|
165 |
|
166 |
public static class SelectColumnsAction extends AbstractAction { |
167 |
|
168 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
169 |
public SelectColumnsAction() {
|
170 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
171 |
|
172 |
this.putValue(NAME, i18n.getTranslation("_Select_columns_to_display")); |
173 |
this.putValue(ACTION_COMMAND_KEY, "SelectColumns"); |
174 |
} |
175 |
|
176 |
@Override
|
177 |
public Object getValue(String key) { |
178 |
if( NAME.equals(key) ) {
|
179 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
180 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
181 |
return i18n.getTranslation("_Select_columns_to_display"); |
182 |
} |
183 |
return super.getValue(key); |
184 |
} |
185 |
|
186 |
@Override
|
187 |
public void actionPerformed(ActionEvent ae) { |
188 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
189 |
panel.doSelectResultColumnNames(); |
190 |
} |
191 |
} |
192 |
|
193 |
public static class CalculatedColumnsAction extends AbstractAction { |
194 |
|
195 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
196 |
public CalculatedColumnsAction() {
|
197 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
198 |
|
199 |
this.putValue(NAME, i18n.getTranslation("_Calculated_columns")); |
200 |
this.putValue(ACTION_COMMAND_KEY, "CalculatedColumns"); |
201 |
} |
202 |
|
203 |
@Override
|
204 |
public Object getValue(String key) { |
205 |
if( NAME.equals(key) ) {
|
206 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
207 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
208 |
return i18n.getTranslation("_Calculated_columns"); |
209 |
} |
210 |
return super.getValue(key); |
211 |
} |
212 |
|
213 |
@Override
|
214 |
public void actionPerformed(ActionEvent ae) { |
215 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
216 |
panel.doCalculatedColumns(); |
217 |
} |
218 |
} |
219 |
|
220 |
public static class GroupByAction extends AbstractAction { |
221 |
|
222 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
223 |
public GroupByAction() {
|
224 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
225 |
|
226 |
this.putValue(NAME, i18n.getTranslation("_Group_by")); |
227 |
this.putValue(ACTION_COMMAND_KEY, "GroupBy"); |
228 |
} |
229 |
|
230 |
@Override
|
231 |
public Object getValue(String key) { |
232 |
if( NAME.equals(key) ) {
|
233 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
234 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
235 |
return i18n.getTranslation("_Group_by"); |
236 |
} |
237 |
return super.getValue(key); |
238 |
} |
239 |
|
240 |
@Override
|
241 |
public void actionPerformed(ActionEvent ae) { |
242 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
243 |
panel.doGroupBy(); |
244 |
} |
245 |
} |
246 |
|
247 |
public static class OrderByAction extends AbstractAction { |
248 |
|
249 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
250 |
public OrderByAction() {
|
251 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
252 |
|
253 |
this.putValue(NAME, i18n.getTranslation("_Order_by")); |
254 |
this.putValue(ACTION_COMMAND_KEY, "SelectOrderBy"); |
255 |
} |
256 |
|
257 |
@Override
|
258 |
public Object getValue(String key) { |
259 |
if( NAME.equals(key) ) {
|
260 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
261 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
262 |
return i18n.getTranslation("_Order_by"); |
263 |
} |
264 |
return super.getValue(key); |
265 |
} |
266 |
|
267 |
@Override
|
268 |
public void actionPerformed(ActionEvent ae) { |
269 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
270 |
panel.doOrderBy(); |
271 |
} |
272 |
} |
273 |
|
274 |
|
275 |
private class ActionButtons { |
276 |
|
277 |
private final DALActionFactory factory; |
278 |
private final Action action; |
279 |
private final JButton button; |
280 |
|
281 |
public ActionButtons(DALActionFactory factory, Action action, JButton button) { |
282 |
this.factory = factory;
|
283 |
this.action = action;
|
284 |
this.button = button;
|
285 |
} |
286 |
} |
287 |
|
288 |
public static class SearchActionContext extends AbstractDALActionContext { |
289 |
|
290 |
private final DefaultSearchPanel panel; |
291 |
|
292 |
public SearchActionContext(DefaultSearchPanel panel) {
|
293 |
super(FeatureStoreSearchPanel.ACTION_CONTEXT_NAME);
|
294 |
this.panel = panel;
|
295 |
} |
296 |
|
297 |
@Override
|
298 |
public DataStore getStore() {
|
299 |
return this.panel.getStore(); |
300 |
} |
301 |
|
302 |
@Override
|
303 |
public JComponent getActionButton(String actionName) { |
304 |
return this.panel.getActionButton(actionName); |
305 |
} |
306 |
|
307 |
@Override
|
308 |
public int getSelectedsCount() { |
309 |
return this.panel.getSelectedFeatureCount(); |
310 |
} |
311 |
|
312 |
@Override
|
313 |
public Expression getFilterForSelecteds() { |
314 |
return this.panel.getFilterForSelectedFeature(); |
315 |
} |
316 |
} |
317 |
|
318 |
private final FeatureStore store; |
319 |
private final ActionListenerSupport acctionListeners; |
320 |
private final Map<String, ActionButtons> actions; |
321 |
private boolean showActions = true; |
322 |
private SearchParameters parameters;
|
323 |
|
324 |
private List<SearchConditionPanel> conditionPanels; |
325 |
|
326 |
|
327 |
private static final int PANEL_SIMPLIFIED = 0; |
328 |
private static final int PANEL_ADVANCED = 1; |
329 |
|
330 |
|
331 |
public DefaultSearchPanel(FeatureStore store) {
|
332 |
this.store = store;
|
333 |
this.acctionListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
|
334 |
this.actions = new HashMap<>(); |
335 |
this.parameters = new SearchParameters(); |
336 |
this.parameters.setQuery(this.store.createFeatureQuery()); |
337 |
|
338 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
339 |
Search.COMPLEMENT_MANE, getFeatureType() |
340 |
); |
341 |
List<Search.OrderedAttribute> attributos = search.getOrderedAttributes(
|
342 |
Search.BASIC_TYPES_FILTER, |
343 |
Search.STR_INT_LONG_LABEL_ORDER, |
344 |
12
|
345 |
); |
346 |
for (Search.OrderedAttribute attrdesc : attributos) {
|
347 |
this.parameters.getResultColumnNames().add(attrdesc.getDescriptor().getName());
|
348 |
} |
349 |
} |
350 |
|
351 |
@Override
|
352 |
public JComponent asJComponent() { |
353 |
if( this.conditionPanels==null ) { |
354 |
this.initComponents();
|
355 |
} |
356 |
return this; |
357 |
} |
358 |
|
359 |
private void addActions() { |
360 |
if( !this.showActions ) { |
361 |
return;
|
362 |
} |
363 |
this.pnlActions.removeAll();
|
364 |
this.pnlActions.setLayout(new FlowLayout(FlowLayout.TRAILING, 8, 4)); |
365 |
SearchActionContext actionContext = new SearchActionContext(this); |
366 |
Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions();
|
367 |
for (DALActionFactory factory : factories) {
|
368 |
Action action = factory.createAction(actionContext);
|
369 |
JButton button = new JButton(action); |
370 |
this.actions.put(factory.getName(), new ActionButtons(factory, action, button)); |
371 |
button.setBorder(BorderFactory.createEmptyBorder());
|
372 |
button.setBorderPainted(false);
|
373 |
button.setFocusPainted(false);
|
374 |
button.setContentAreaFilled(false);
|
375 |
button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
376 |
this.pnlActions.add(button);
|
377 |
} |
378 |
this.pnlActions.revalidate();
|
379 |
this.pnlActions.repaint();
|
380 |
} |
381 |
|
382 |
@Override
|
383 |
public void addActionListener(ActionListener listener) { |
384 |
this.acctionListeners.addActionListener(listener);
|
385 |
} |
386 |
|
387 |
@Override
|
388 |
public ActionListener[] getActionListeners() { |
389 |
return this.acctionListeners.getActionListeners(); |
390 |
} |
391 |
|
392 |
@Override
|
393 |
public void removeActionListener(ActionListener listener) { |
394 |
this.acctionListeners.removeActionListener(listener);
|
395 |
} |
396 |
|
397 |
@Override
|
398 |
public void removeAllActionListener() { |
399 |
this.acctionListeners.removeAllActionListener();
|
400 |
} |
401 |
|
402 |
@Override
|
403 |
public void fireActionEvent(ActionEvent event) { |
404 |
this.acctionListeners.fireActionEvent(event);
|
405 |
} |
406 |
|
407 |
@Override
|
408 |
public boolean hasActionListeners() { |
409 |
return this.acctionListeners.hasActionListeners(); |
410 |
} |
411 |
|
412 |
private void initComponents() { |
413 |
this.conditionPanels = new ArrayList<>(); |
414 |
|
415 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
416 |
swingManager.translate(this.tabSearchMode);
|
417 |
swingManager.translate(this.btnSearch);
|
418 |
swingManager.translate(this.btnClear);
|
419 |
swingManager.translate(this.lblExpressionDeBusqueda);
|
420 |
swingManager.translate(this.btnAddAccumulatedFilter);
|
421 |
swingManager.translate(this.btnRemoveAccumulatedFilter);
|
422 |
swingManager.translate(this.btnViewAccumulatedFilter);
|
423 |
|
424 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
425 |
JComponent c = cfgActionsManager.getConfigurableActionsComponent(CONFIGURABLE_PANEL_ID, this); |
426 |
this.pnlCfgActions.setLayout(new BorderLayout(0,0)); |
427 |
this.pnlCfgActions.add(c, BorderLayout.CENTER); |
428 |
|
429 |
this.conditionPanels.add(
|
430 |
new SearchConditionPanelSimplified(
|
431 |
store, |
432 |
btnAddAccumulatedFilter, |
433 |
btnRemoveAccumulatedFilter, |
434 |
btnViewAccumulatedFilter, |
435 |
lblField1, |
436 |
lblExtraFields1, |
437 |
lblRelationalOperator1, |
438 |
cboValue1, |
439 |
lblLogicalOperators1, |
440 |
lblField2, |
441 |
lblExtraFields2, |
442 |
lblRelationalOperator2, |
443 |
cboValue2, |
444 |
lblLogicalOperators2, |
445 |
lblField3, |
446 |
lblExtraFields3, |
447 |
lblRelationalOperator3, |
448 |
cboValue3, |
449 |
lblLogicalOperators3, |
450 |
lblField4, |
451 |
lblExtraFields4, |
452 |
lblRelationalOperator4, |
453 |
cboValue4, |
454 |
null
|
455 |
) |
456 |
); |
457 |
this.conditionPanels.add(
|
458 |
new SearchConditionPanelAdvanced(
|
459 |
this.store,
|
460 |
txtAdvancedExpression, |
461 |
btnAdvancedExpression, |
462 |
btnAdvancedExpressionHistory, |
463 |
btnAdvancedExpressionBookmarks |
464 |
) |
465 |
); |
466 |
for (SearchConditionPanelFactory factory : DALSwingLocator.getManager().getSearchConditionPanels()) {
|
467 |
if( factory.isApplicable(store) ) {
|
468 |
this.conditionPanels.add(factory.create(this)); |
469 |
} |
470 |
} |
471 |
|
472 |
this.btnSearch.addActionListener((ActionEvent e) -> { |
473 |
search(); |
474 |
}); |
475 |
|
476 |
this.tblResults.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { |
477 |
for (ActionButtons actionButton : actions.values()) {
|
478 |
if( actionButton.action instanceof ListSelectionListener) { |
479 |
((ListSelectionListener) actionButton.action).valueChanged(e);
|
480 |
} |
481 |
} |
482 |
}); |
483 |
this.btnClear.addActionListener((ActionEvent e) -> { |
484 |
clear(); |
485 |
}); |
486 |
addActions(); |
487 |
this.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); |
488 |
|
489 |
search(); |
490 |
} |
491 |
|
492 |
private FeatureType getFeatureType() {
|
493 |
try {
|
494 |
return store.getDefaultFeatureType();
|
495 |
} catch (Exception ex) { |
496 |
throw new RuntimeException("Can't retrieve the feature type.", ex); |
497 |
} |
498 |
} |
499 |
|
500 |
@Override
|
501 |
public void setEnabled(boolean enabled) { |
502 |
if( this.conditionPanels==null ) { |
503 |
this.initComponents();
|
504 |
} |
505 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
506 |
conditionPanel.setEnabled(enabled); |
507 |
} |
508 |
|
509 |
this.btnClear.setEnabled(enabled);
|
510 |
this.btnSearch.setEnabled(enabled);
|
511 |
for (ActionButtons actionButton : actions.values()) {
|
512 |
actionButton.action.setEnabled(enabled); |
513 |
} |
514 |
} |
515 |
|
516 |
@Override
|
517 |
public void clear() { |
518 |
if( this.conditionPanels==null ) { |
519 |
return;
|
520 |
} |
521 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
522 |
conditionPanel.clear(); |
523 |
} |
524 |
} |
525 |
|
526 |
@Override
|
527 |
public FeatureQuery getQuery() {
|
528 |
FeatureQuery query; |
529 |
try {
|
530 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
531 |
SearchConditionPanel panel = this.conditionPanels.get(searchMode);
|
532 |
Expression filter = panel.get();
|
533 |
if( searchMode!=PANEL_ADVANCED ) {
|
534 |
this.conditionPanels.get(PANEL_ADVANCED).set(filter);
|
535 |
} |
536 |
if (ExpressionUtils.isPhraseEmpty(filter)) {
|
537 |
return null; |
538 |
} |
539 |
query = (FeatureQuery) this.parameters.getQuery().clone();
|
540 |
query.setFilter(filter); |
541 |
return query;
|
542 |
} catch (Exception ex) { |
543 |
LOGGER.warn("Can't build query.",ex);
|
544 |
return null; |
545 |
} |
546 |
} |
547 |
|
548 |
@Override
|
549 |
public FeatureQuery getLastQuery() {
|
550 |
return this.parameters.getQuery(); |
551 |
} |
552 |
|
553 |
@Override
|
554 |
public void search() { |
555 |
final MutableObject model = new MutableObject(null); |
556 |
|
557 |
lblMsg.setText("Searching...");
|
558 |
setEnabled(false);
|
559 |
Thread th = new Thread(() -> { |
560 |
try {
|
561 |
final List<Feature> features; |
562 |
features = store.getFeatures(this.getQuery());
|
563 |
model.setValue( new SimpleFeaturesTableModel(
|
564 |
getFeatureType(), |
565 |
parameters.getResultColumnNames(), |
566 |
features |
567 |
) |
568 |
); |
569 |
} catch (Exception ex) { |
570 |
LOGGER.warn("Can't get features or create table model",ex);
|
571 |
} finally {
|
572 |
SwingUtilities.invokeLater(() -> {
|
573 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
574 |
TableModel m = (TableModel) model.getValue(); |
575 |
tblResults.setModel(m); |
576 |
lblMsg.setText(String.format("%d "+i18n.getTranslation("_elements"), m.getRowCount())); |
577 |
setEnabled(true);
|
578 |
}); |
579 |
} |
580 |
}); |
581 |
th.start(); |
582 |
} |
583 |
|
584 |
public void setResultColumnNames(List<String> names) { |
585 |
this.parameters.getResultColumnNames().clear();
|
586 |
this.parameters.getResultColumnNames().addAll(names);
|
587 |
if( this.conditionPanels==null ) { |
588 |
return;
|
589 |
} |
590 |
SimpleFeaturesTableModel model = (SimpleFeaturesTableModel) this.tblResults.getModel();
|
591 |
List<Feature> features = model.getFeatures();
|
592 |
model = new SimpleFeaturesTableModel(
|
593 |
getFeatureType(), |
594 |
this.parameters.getResultColumnNames(),
|
595 |
features |
596 |
); |
597 |
tblResults.setModel(model); |
598 |
} |
599 |
|
600 |
@Override
|
601 |
public boolean setFilter(Expression filter) { |
602 |
try {
|
603 |
if( this.conditionPanels==null ) { |
604 |
this.initComponents();
|
605 |
} |
606 |
if( ExpressionUtils.isPhraseEmpty(filter) ) {
|
607 |
this.clear();
|
608 |
return true; |
609 |
} |
610 |
int panel = 0; |
611 |
int selected = PANEL_ADVANCED;
|
612 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
613 |
if( panel!=PANEL_ADVANCED && conditionPanel.set(filter) ) {
|
614 |
selected = panel; |
615 |
} |
616 |
panel++; |
617 |
} |
618 |
this.tabSearchMode.setSelectedIndex(selected);
|
619 |
|
620 |
SimpleFeaturesTableModel model = new SimpleFeaturesTableModel(this.getStore()); |
621 |
tblResults.setModel(model); |
622 |
lblMsg.setText("");
|
623 |
return true; |
624 |
} catch(Exception ex) { |
625 |
LOGGER.warn("Can't set current search", ex);
|
626 |
return false; |
627 |
} |
628 |
} |
629 |
|
630 |
@Override
|
631 |
public List<SearchConditionPanel> getConditionPanels() { |
632 |
return Collections.unmodifiableList(this.conditionPanels); |
633 |
} |
634 |
|
635 |
@Override
|
636 |
public SearchConditionPanel getConditionPanel(String name) { |
637 |
for (SearchConditionPanel panel : conditionPanels) {
|
638 |
if( StringUtils.equalsIgnoreCase(name, panel.getFactory().getName()) ) {
|
639 |
return panel;
|
640 |
} |
641 |
} |
642 |
return null; |
643 |
} |
644 |
|
645 |
@Override
|
646 |
public Expression getFilterForSelectedFeature() { |
647 |
if( this.conditionPanels==null ) { |
648 |
return null; |
649 |
} |
650 |
int selectedRow = this.tblResults.getSelectedRow(); |
651 |
if (selectedRow < 0) { |
652 |
return null; |
653 |
} |
654 |
try {
|
655 |
List<Feature> features = ((SimpleFeaturesTableModel) this.tblResults.getModel()).getFeatures(); |
656 |
Feature feature = features.get(selectedRow); |
657 |
|
658 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
659 |
FeatureType ftype = this.store.getDefaultFeatureType();
|
660 |
for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
|
661 |
builder.and( |
662 |
builder.eq( |
663 |
builder.column(attrdesc.getName()), |
664 |
builder.constant(feature.get(attrdesc.getName())) |
665 |
) |
666 |
); |
667 |
} |
668 |
Expression filter = ExpressionUtils.createExpression(builder.toString());
|
669 |
return filter;
|
670 |
} catch (Exception ex) { |
671 |
LOGGER.warn("Can't build search for the selected feature.", ex);
|
672 |
return null; |
673 |
} |
674 |
} |
675 |
|
676 |
@Override
|
677 |
public FeatureStore getStore() {
|
678 |
return store;
|
679 |
} |
680 |
|
681 |
private void doOrderBy() { |
682 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
683 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
684 |
FeatureQueryOrderPanel orderPanel = DALSwingLocator.getDataSwingManager().createFeatureStoreOrderPanel(); |
685 |
orderPanel.setStore(store); |
686 |
orderPanel.put(parameters.getQuery()); |
687 |
Dialog dialog = windowManager.createDialog(
|
688 |
orderPanel.asJComponent(), |
689 |
i18n.getTranslation("_Select_order"),
|
690 |
null,
|
691 |
WindowManager_v2.BUTTONS_OK_CANCEL |
692 |
); |
693 |
dialog.addActionListener((ActionEvent e) -> {
|
694 |
if( dialog.getAction()==WindowManager_v2.BUTTON_OK ) {
|
695 |
orderPanel.fetch(this.parameters.getQuery());
|
696 |
search(); |
697 |
} |
698 |
}); |
699 |
dialog.show(WindowManager.MODE.DIALOG); |
700 |
|
701 |
} |
702 |
|
703 |
@Override
|
704 |
public ImageIcon loadImage(String imageName) { |
705 |
String name = FilenameUtils.getBaseName(imageName);
|
706 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
707 |
if (theme.exists(name)) {
|
708 |
return theme.get(name);
|
709 |
} |
710 |
URL url = this.getClass().getResource(name + ".png"); |
711 |
if (url == null) { |
712 |
return null; |
713 |
} |
714 |
return new ImageIcon(url); |
715 |
} |
716 |
|
717 |
@Override
|
718 |
public int getSelectedFeatureCount() { |
719 |
if( this.conditionPanels==null ) { |
720 |
return 0; |
721 |
} |
722 |
return this.tblResults.getSelectedRowCount(); |
723 |
} |
724 |
|
725 |
@Override
|
726 |
public JComponent getActionButton(String name) { |
727 |
ActionButtons actionButton = this.actions.get(name);
|
728 |
if( actionButton==null ) { |
729 |
return null; |
730 |
} |
731 |
return actionButton.button;
|
732 |
} |
733 |
|
734 |
@Override
|
735 |
public void setShowActions(boolean showActions) { |
736 |
this.showActions = showActions;
|
737 |
} |
738 |
|
739 |
@Override
|
740 |
public boolean isShowActions() { |
741 |
return this.showActions; |
742 |
} |
743 |
|
744 |
public static String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc, String tableName) { |
745 |
String theLabel;
|
746 |
int theUseLabels;
|
747 |
if( useLabels == null ) { |
748 |
Tags tags = attrdesc.getTags(); |
749 |
if( tags.has(DAL_USE_LABELS) ) {
|
750 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
751 |
} else {
|
752 |
tags = attrdesc.getFeatureType().getTags(); |
753 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
754 |
} |
755 |
} else {
|
756 |
theUseLabels = useLabels; |
757 |
} |
758 |
switch(theUseLabels) {
|
759 |
case USE_LABELS_YES:
|
760 |
if( StringUtils.isBlank(tableName) ) {
|
761 |
theLabel = attrdesc.getLocalizedLabel(); |
762 |
} else {
|
763 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), tableName); |
764 |
} |
765 |
break;
|
766 |
default:
|
767 |
case USE_LABELS_NO:
|
768 |
if( StringUtils.isBlank(tableName) ) {
|
769 |
theLabel = attrdesc.getName(); |
770 |
} else {
|
771 |
theLabel = String.format("%s [%s]", attrdesc.getName(), tableName); |
772 |
} |
773 |
break;
|
774 |
case USE_LABELS_BOTH:
|
775 |
if( StringUtils.isBlank(tableName) ) {
|
776 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName()); |
777 |
} else {
|
778 |
theLabel = String.format("%s [%s/%s]", attrdesc.getLocalizedLabel(), attrdesc.getName(), tableName); |
779 |
} |
780 |
break;
|
781 |
} |
782 |
return theLabel;
|
783 |
} |
784 |
|
785 |
private void doCalculatedColumns() { |
786 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
787 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
788 |
final FeatureQueryCalculatedColumnsPanel panel = new DefaultFeatureQueryCalculatedColumnsPanel(); |
789 |
panel.setStore(this.store);
|
790 |
panel.put(this.parameters.getQuery());
|
791 |
final Dialog dialog = winmanager.createDialog( |
792 |
panel.asJComponent(), |
793 |
i18n.getTranslation("_Calculated_columns"),
|
794 |
null,
|
795 |
WindowManager_v2.BUTTONS_OK_CANCEL |
796 |
); |
797 |
dialog.addActionListener((ActionEvent e) -> {
|
798 |
if( dialog.getAction()==WindowManager_v2.BUTTONS_OK ) {
|
799 |
panel.fetch(this.parameters.getQuery());
|
800 |
search(); |
801 |
} |
802 |
}); |
803 |
dialog.show(WindowManager.MODE.DIALOG); |
804 |
} |
805 |
|
806 |
private void doGroupBy() { |
807 |
int allowGroupBy = ((FeatureStoreProviderFactory)(this.store.getProviderFactory())).allowGroupBy(); |
808 |
if( allowGroupBy!=DataType.YES ) {
|
809 |
// FIXME: mensaje al usaurio.
|
810 |
return;
|
811 |
} |
812 |
|
813 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
814 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
815 |
final FeatureQueryGroupByPanel panel = new DefaultFeatureQueryGroupByPanel(); |
816 |
panel.setStore(this.store);
|
817 |
panel.put(this.parameters.getQuery());
|
818 |
final Dialog dialog = winmanager.createDialog( |
819 |
panel.asJComponent(), |
820 |
i18n.getTranslation("_Select_group_columns_and_aggregate_functions"),
|
821 |
null,
|
822 |
WindowManager_v2.BUTTONS_OK_CANCEL |
823 |
); |
824 |
dialog.addActionListener((ActionEvent e) -> {
|
825 |
if( dialog.getAction()==WindowManager_v2.BUTTONS_OK ) {
|
826 |
panel.fetch(this.parameters.getQuery());
|
827 |
search(); |
828 |
} |
829 |
}); |
830 |
dialog.show(WindowManager.MODE.DIALOG); |
831 |
} |
832 |
|
833 |
private void doSelectResultColumnNames() { |
834 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
835 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
836 |
final FeatureAttributeSelectionPanel panel = DALSwingLocator.getManager().createFeatureAttributeSelectionPanel();
|
837 |
panel.setFeatureType(this.getFeatureType());
|
838 |
panel.setSelectedNames(this.parameters.getResultColumnNames());
|
839 |
final Dialog dialog = winmanager.createDialog( |
840 |
panel.asJComponent(), |
841 |
i18n.getTranslation("_Select_the_columns_to_display"),
|
842 |
null,
|
843 |
WindowManager_v2.BUTTONS_OK_CANCEL |
844 |
); |
845 |
dialog.addActionListener((ActionEvent e) -> {
|
846 |
if( dialog.getAction()==WindowManager_v2.BUTTONS_OK ) {
|
847 |
this.setResultColumnNames(panel.getSelectedNames());
|
848 |
} |
849 |
}); |
850 |
dialog.show(WindowManager.MODE.DIALOG); |
851 |
} |
852 |
|
853 |
|
854 |
public static void selfRegister() { |
855 |
String[][] iconNames = new String[][]{ |
856 |
new String[]{"dalswing", "featurestore-column"}, |
857 |
new String[]{"dalswing", "featurestore-foreing-key"}, |
858 |
new String[]{"dalswing", "featurestore-table"}, |
859 |
new String[]{"dalswing", "search-action-showform"}, |
860 |
new String[]{"dalswing", "search-action-select"}, |
861 |
new String[]{"dalswing", "search-action-select-add"}, |
862 |
new String[]{"dalswing", "search-action-select-filter"} |
863 |
}; |
864 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
865 |
for (String[] icon : iconNames) { |
866 |
URL url = DefaultSearchPanel.class.getResource(icon[1] + ".png"); |
867 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
868 |
} |
869 |
|
870 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
871 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsYesAction());
|
872 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsNoAction());
|
873 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsBothAction());
|
874 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new SelectColumnsAction());
|
875 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new CalculatedColumnsAction());
|
876 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new GroupByAction());
|
877 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new OrderByAction());
|
878 |
} |
879 |
} |