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 @ 44729
History | View | Annotate | Download (32.1 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.impl.featuretable.SimpleFeaturesTableModel; |
52 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryGroupByPanel; |
53 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
54 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel; |
55 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory; |
56 |
import org.gvsig.tools.ToolsLocator; |
57 |
import org.gvsig.tools.dataTypes.DataType; |
58 |
import org.gvsig.tools.dynobject.Tags; |
59 |
import org.gvsig.tools.i18n.I18nManager; |
60 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
61 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
62 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
63 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
64 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
65 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
66 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
67 |
import org.gvsig.tools.util.ToolsUtilLocator; |
68 |
import org.slf4j.Logger; |
69 |
import org.slf4j.LoggerFactory; |
70 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryGroupByPanel; |
71 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryOrderPanel; |
72 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryCalculatedColumnsPanel; |
73 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel; |
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 |
@Override
|
318 |
public FeatureQuery getQuery() {
|
319 |
return this.panel.getQuery(); |
320 |
} |
321 |
} |
322 |
|
323 |
private final FeatureStore store; |
324 |
private final ActionListenerSupport acctionListeners; |
325 |
private final Map<String, ActionButtons> actions; |
326 |
private boolean showActions = true; |
327 |
private SearchParameters parameters;
|
328 |
|
329 |
private List<SearchConditionPanel> conditionPanels; |
330 |
|
331 |
|
332 |
private static final int PANEL_SIMPLIFIED = 0; |
333 |
private static final int PANEL_ADVANCED = 1; |
334 |
|
335 |
|
336 |
public DefaultSearchPanel(FeatureStore store) {
|
337 |
this.store = store;
|
338 |
this.acctionListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
|
339 |
this.actions = new HashMap<>(); |
340 |
this.parameters = new SearchParameters(); |
341 |
FeatureQuery featureQuery = this.store.createFeatureQuery();
|
342 |
featureQuery.retrievesAllAttributes(); |
343 |
this.parameters.setQuery(featureQuery);
|
344 |
|
345 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
346 |
Search.COMPLEMENT_MANE, getFeatureType() |
347 |
); |
348 |
List<Search.OrderedAttribute> attributos = search.getOrderedAttributes(
|
349 |
Search.BASIC_TYPES_FILTER, |
350 |
Search.STR_INT_LONG_LABEL_ORDER, |
351 |
12
|
352 |
); |
353 |
for (Search.OrderedAttribute attrdesc : attributos) {
|
354 |
this.parameters.getResultColumnNames().add(attrdesc.getDescriptor().getName());
|
355 |
} |
356 |
} |
357 |
|
358 |
@Override
|
359 |
public JComponent asJComponent() { |
360 |
if( this.conditionPanels==null ) { |
361 |
this.initComponents();
|
362 |
} |
363 |
return this; |
364 |
} |
365 |
|
366 |
private void addActions() { |
367 |
if( !this.showActions ) { |
368 |
return;
|
369 |
} |
370 |
this.pnlActions.removeAll();
|
371 |
this.pnlActions.setLayout(new FlowLayout(FlowLayout.TRAILING, 8, 4)); |
372 |
SearchActionContext actionContext = new SearchActionContext(this); |
373 |
Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions();
|
374 |
for (DALActionFactory factory : factories) {
|
375 |
Action action = factory.createAction(actionContext);
|
376 |
JButton button = new JButton(action); |
377 |
this.actions.put(factory.getName(), new ActionButtons(factory, action, button)); |
378 |
button.setBorder(BorderFactory.createEmptyBorder());
|
379 |
button.setBorderPainted(false);
|
380 |
button.setFocusPainted(false);
|
381 |
button.setContentAreaFilled(false);
|
382 |
button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
383 |
this.pnlActions.add(button);
|
384 |
} |
385 |
this.pnlActions.revalidate();
|
386 |
this.pnlActions.repaint();
|
387 |
} |
388 |
|
389 |
@Override
|
390 |
public void addActionListener(ActionListener listener) { |
391 |
this.acctionListeners.addActionListener(listener);
|
392 |
} |
393 |
|
394 |
@Override
|
395 |
public ActionListener[] getActionListeners() { |
396 |
return this.acctionListeners.getActionListeners(); |
397 |
} |
398 |
|
399 |
@Override
|
400 |
public void removeActionListener(ActionListener listener) { |
401 |
this.acctionListeners.removeActionListener(listener);
|
402 |
} |
403 |
|
404 |
@Override
|
405 |
public void removeAllActionListener() { |
406 |
this.acctionListeners.removeAllActionListener();
|
407 |
} |
408 |
|
409 |
@Override
|
410 |
public void fireActionEvent(ActionEvent event) { |
411 |
this.acctionListeners.fireActionEvent(event);
|
412 |
} |
413 |
|
414 |
@Override
|
415 |
public boolean hasActionListeners() { |
416 |
return this.acctionListeners.hasActionListeners(); |
417 |
} |
418 |
|
419 |
private void initComponents() { |
420 |
this.conditionPanels = new ArrayList<>(); |
421 |
|
422 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
423 |
swingManager.translate(this.tabSearchMode);
|
424 |
swingManager.translate(this.btnSearch);
|
425 |
swingManager.translate(this.btnClear);
|
426 |
swingManager.translate(this.lblExpressionDeBusqueda);
|
427 |
swingManager.translate(this.btnAddAccumulatedFilter);
|
428 |
swingManager.translate(this.btnRemoveAccumulatedFilter);
|
429 |
swingManager.translate(this.btnViewAccumulatedFilter);
|
430 |
|
431 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
432 |
JComponent c = cfgActionsManager.getConfigurableActionsComponent(CONFIGURABLE_PANEL_ID, this); |
433 |
this.pnlCfgActions.setLayout(new BorderLayout(0,0)); |
434 |
this.pnlCfgActions.add(c, BorderLayout.CENTER); |
435 |
|
436 |
this.conditionPanels.add(
|
437 |
new SearchConditionPanelSimplified(
|
438 |
store, |
439 |
btnAddAccumulatedFilter, |
440 |
btnRemoveAccumulatedFilter, |
441 |
btnViewAccumulatedFilter, |
442 |
lblField1, |
443 |
lblExtraFields1, |
444 |
lblRelationalOperator1, |
445 |
cboValue1, |
446 |
lblLogicalOperators1, |
447 |
lblField2, |
448 |
lblExtraFields2, |
449 |
lblRelationalOperator2, |
450 |
cboValue2, |
451 |
lblLogicalOperators2, |
452 |
lblField3, |
453 |
lblExtraFields3, |
454 |
lblRelationalOperator3, |
455 |
cboValue3, |
456 |
lblLogicalOperators3, |
457 |
lblField4, |
458 |
lblExtraFields4, |
459 |
lblRelationalOperator4, |
460 |
cboValue4, |
461 |
null
|
462 |
) |
463 |
); |
464 |
this.conditionPanels.add(
|
465 |
new SearchConditionPanelAdvanced(
|
466 |
this.store,
|
467 |
txtAdvancedExpression, |
468 |
btnAdvancedExpression, |
469 |
btnAdvancedExpressionHistory, |
470 |
btnAdvancedExpressionBookmarks |
471 |
) |
472 |
); |
473 |
for (SearchConditionPanelFactory factory : DALSwingLocator.getManager().getSearchConditionPanels()) {
|
474 |
if( factory.isApplicable(store) ) {
|
475 |
SearchConditionPanel panel = factory.create(this);
|
476 |
this.conditionPanels.add(panel);
|
477 |
this.tabSearchMode.add(factory.getName(), panel.asJComponent());
|
478 |
} |
479 |
} |
480 |
|
481 |
this.btnSearch.addActionListener((ActionEvent e) -> { |
482 |
search(); |
483 |
}); |
484 |
|
485 |
this.tblResults.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { |
486 |
for (ActionButtons actionButton : actions.values()) {
|
487 |
if( actionButton.action instanceof ListSelectionListener) { |
488 |
((ListSelectionListener) actionButton.action).valueChanged(e);
|
489 |
} |
490 |
} |
491 |
}); |
492 |
this.btnClear.addActionListener((ActionEvent e) -> { |
493 |
clear(); |
494 |
}); |
495 |
addActions(); |
496 |
this.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); |
497 |
|
498 |
search(); |
499 |
} |
500 |
|
501 |
private FeatureType getFeatureType() {
|
502 |
try {
|
503 |
return store.getDefaultFeatureType();
|
504 |
} catch (Exception ex) { |
505 |
throw new RuntimeException("Can't retrieve the feature type.", ex); |
506 |
} |
507 |
} |
508 |
|
509 |
@Override
|
510 |
public void setEnabled(boolean enabled) { |
511 |
if( this.conditionPanels==null ) { |
512 |
this.initComponents();
|
513 |
} |
514 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
515 |
conditionPanel.setEnabled(enabled); |
516 |
} |
517 |
|
518 |
this.btnClear.setEnabled(enabled);
|
519 |
this.btnSearch.setEnabled(enabled);
|
520 |
for (ActionButtons actionButton : actions.values()) {
|
521 |
actionButton.action.setEnabled(enabled); |
522 |
} |
523 |
} |
524 |
|
525 |
@Override
|
526 |
public void clear() { |
527 |
if( this.conditionPanels==null ) { |
528 |
return;
|
529 |
} |
530 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
531 |
conditionPanel.clear(); |
532 |
} |
533 |
} |
534 |
|
535 |
@Override
|
536 |
public FeatureQuery getQuery() {
|
537 |
FeatureQuery query; |
538 |
try {
|
539 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
540 |
SearchConditionPanel panel = this.conditionPanels.get(searchMode);
|
541 |
Expression filter = panel.get();
|
542 |
if( searchMode!=PANEL_ADVANCED ) {
|
543 |
this.conditionPanels.get(PANEL_ADVANCED).set(filter);
|
544 |
} |
545 |
query = (FeatureQuery) this.parameters.getQuery().clone();
|
546 |
query.retrievesAllAttributes(); |
547 |
if (ExpressionUtils.isPhraseEmpty(filter)) {
|
548 |
return query;
|
549 |
} |
550 |
query.setFilter(filter); |
551 |
query.retrievesAllAttributes(); |
552 |
return query;
|
553 |
} catch (Exception ex) { |
554 |
LOGGER.warn("Can't build query.",ex);
|
555 |
return null; |
556 |
} |
557 |
} |
558 |
|
559 |
@Override
|
560 |
public FeatureQuery getLastQuery() {
|
561 |
return this.parameters.getQuery(); |
562 |
} |
563 |
|
564 |
@Override
|
565 |
public void search() { |
566 |
final MutableObject model = new MutableObject(null); |
567 |
|
568 |
lblMsg.setText("Searching...");
|
569 |
setEnabled(false);
|
570 |
Thread th = new Thread(() -> { |
571 |
try {
|
572 |
final List<Feature> features; |
573 |
features = store.getFeatures(this.getQuery());
|
574 |
model.setValue( new SimpleFeaturesTableModel(
|
575 |
getFeatureType(), |
576 |
parameters.getResultColumnNames(), |
577 |
features |
578 |
) |
579 |
); |
580 |
} catch (Exception ex) { |
581 |
LOGGER.warn("Can't get features or create table model",ex);
|
582 |
} finally {
|
583 |
SwingUtilities.invokeLater(() -> {
|
584 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
585 |
TableModel m = (TableModel) model.getValue(); |
586 |
tblResults.setModel(m); |
587 |
lblMsg.setText(String.format("%d "+i18n.getTranslation("_elements"), m.getRowCount())); |
588 |
setEnabled(true);
|
589 |
}); |
590 |
} |
591 |
}); |
592 |
th.start(); |
593 |
} |
594 |
|
595 |
public void setResultColumnNames(List<String> names) { |
596 |
this.parameters.getResultColumnNames().clear();
|
597 |
this.parameters.getResultColumnNames().addAll(names);
|
598 |
if( this.conditionPanels==null ) { |
599 |
return;
|
600 |
} |
601 |
SimpleFeaturesTableModel model = (SimpleFeaturesTableModel) this.tblResults.getModel();
|
602 |
List<Feature> features = model.getFeatures();
|
603 |
model = new SimpleFeaturesTableModel(
|
604 |
getFeatureType(), |
605 |
this.parameters.getResultColumnNames(),
|
606 |
features |
607 |
); |
608 |
tblResults.setModel(model); |
609 |
} |
610 |
|
611 |
@Override
|
612 |
public boolean setFilter(Expression filter) { |
613 |
try {
|
614 |
if( this.conditionPanels==null ) { |
615 |
this.initComponents();
|
616 |
} |
617 |
if( ExpressionUtils.isPhraseEmpty(filter) ) {
|
618 |
this.clear();
|
619 |
return true; |
620 |
} |
621 |
int panel = 0; |
622 |
int selected = PANEL_ADVANCED;
|
623 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
624 |
if( panel!=PANEL_ADVANCED && conditionPanel.set(filter) ) {
|
625 |
selected = panel; |
626 |
} |
627 |
panel++; |
628 |
} |
629 |
this.tabSearchMode.setSelectedIndex(selected);
|
630 |
|
631 |
SimpleFeaturesTableModel model = new SimpleFeaturesTableModel(this.getStore()); |
632 |
tblResults.setModel(model); |
633 |
lblMsg.setText("");
|
634 |
return true; |
635 |
} catch(Exception ex) { |
636 |
LOGGER.warn("Can't set current search", ex);
|
637 |
return false; |
638 |
} |
639 |
} |
640 |
|
641 |
@Override
|
642 |
public List<SearchConditionPanel> getConditionPanels() { |
643 |
return Collections.unmodifiableList(this.conditionPanels); |
644 |
} |
645 |
|
646 |
@Override
|
647 |
public SearchConditionPanel getConditionPanel(String name) { |
648 |
for (SearchConditionPanel panel : conditionPanels) {
|
649 |
if( StringUtils.equalsIgnoreCase(name, panel.getFactory().getName()) ) {
|
650 |
return panel;
|
651 |
} |
652 |
} |
653 |
return null; |
654 |
} |
655 |
|
656 |
@Override
|
657 |
public Expression getFilterForSelectedFeature() { |
658 |
if( this.conditionPanels==null ) { |
659 |
return null; |
660 |
} |
661 |
int selectedRow = this.tblResults.getSelectedRow(); |
662 |
if (selectedRow < 0) { |
663 |
return null; |
664 |
} |
665 |
try {
|
666 |
List<Feature> features = ((SimpleFeaturesTableModel) this.tblResults.getModel()).getFeatures(); |
667 |
Feature feature = features.get(selectedRow); |
668 |
|
669 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
670 |
FeatureType ftype = this.store.getDefaultFeatureType();
|
671 |
for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
|
672 |
builder.and( |
673 |
builder.eq( |
674 |
builder.column(attrdesc.getName()), |
675 |
builder.constant(feature.get(attrdesc.getName())) |
676 |
) |
677 |
); |
678 |
} |
679 |
Expression filter = ExpressionUtils.createExpression(builder.toString());
|
680 |
return filter;
|
681 |
} catch (Exception ex) { |
682 |
LOGGER.warn("Can't build search for the selected feature.", ex);
|
683 |
return null; |
684 |
} |
685 |
} |
686 |
|
687 |
@Override
|
688 |
public FeatureStore getStore() {
|
689 |
return store;
|
690 |
} |
691 |
|
692 |
private void doOrderBy() { |
693 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
694 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
695 |
FeatureQueryOrderPanel orderPanel = DALSwingLocator.getDataSwingManager().createFeatureStoreOrderPanel(); |
696 |
orderPanel.setStore(store); |
697 |
orderPanel.put(parameters.getQuery()); |
698 |
Dialog dialog = windowManager.createDialog(
|
699 |
orderPanel.asJComponent(), |
700 |
i18n.getTranslation("_Select_order"),
|
701 |
null,
|
702 |
WindowManager_v2.BUTTONS_OK_CANCEL |
703 |
); |
704 |
dialog.addActionListener((ActionEvent e) -> {
|
705 |
if( dialog.getAction()==WindowManager_v2.BUTTON_OK ) {
|
706 |
orderPanel.fetch(this.parameters.getQuery());
|
707 |
search(); |
708 |
} |
709 |
}); |
710 |
dialog.show(WindowManager.MODE.DIALOG); |
711 |
|
712 |
} |
713 |
|
714 |
@Override
|
715 |
public ImageIcon loadImage(String imageName) { |
716 |
String name = FilenameUtils.getBaseName(imageName);
|
717 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
718 |
if (theme.exists(name)) {
|
719 |
return theme.get(name);
|
720 |
} |
721 |
URL url = this.getClass().getResource(name + ".png"); |
722 |
if (url == null) { |
723 |
return null; |
724 |
} |
725 |
return new ImageIcon(url); |
726 |
} |
727 |
|
728 |
@Override
|
729 |
public int getSelectedFeatureCount() { |
730 |
if( this.conditionPanels==null ) { |
731 |
return 0; |
732 |
} |
733 |
return this.tblResults.getSelectedRowCount(); |
734 |
} |
735 |
|
736 |
@Override
|
737 |
public JComponent getActionButton(String name) { |
738 |
ActionButtons actionButton = this.actions.get(name);
|
739 |
if( actionButton==null ) { |
740 |
return null; |
741 |
} |
742 |
return actionButton.button;
|
743 |
} |
744 |
|
745 |
@Override
|
746 |
public void setShowActions(boolean showActions) { |
747 |
this.showActions = showActions;
|
748 |
} |
749 |
|
750 |
@Override
|
751 |
public boolean isShowActions() { |
752 |
return this.showActions; |
753 |
} |
754 |
|
755 |
public static String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc, String tableName) { |
756 |
String theLabel;
|
757 |
int theUseLabels;
|
758 |
if( useLabels == null ) { |
759 |
Tags tags = attrdesc.getTags(); |
760 |
if( tags.has(DAL_USE_LABELS) ) {
|
761 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
762 |
} else {
|
763 |
tags = attrdesc.getFeatureType().getTags(); |
764 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
765 |
} |
766 |
} else {
|
767 |
theUseLabels = useLabels; |
768 |
} |
769 |
switch(theUseLabels) {
|
770 |
case USE_LABELS_YES:
|
771 |
if( StringUtils.isBlank(tableName) ) {
|
772 |
theLabel = attrdesc.getLocalizedLabel(); |
773 |
} else {
|
774 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), tableName); |
775 |
} |
776 |
break;
|
777 |
default:
|
778 |
case USE_LABELS_NO:
|
779 |
if( StringUtils.isBlank(tableName) ) {
|
780 |
theLabel = attrdesc.getName(); |
781 |
} else {
|
782 |
theLabel = String.format("%s [%s]", attrdesc.getName(), tableName); |
783 |
} |
784 |
break;
|
785 |
case USE_LABELS_BOTH:
|
786 |
if( StringUtils.isBlank(tableName) ) {
|
787 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName()); |
788 |
} else {
|
789 |
theLabel = String.format("%s [%s/%s]", attrdesc.getLocalizedLabel(), attrdesc.getName(), tableName); |
790 |
} |
791 |
break;
|
792 |
} |
793 |
return theLabel;
|
794 |
} |
795 |
|
796 |
private void doCalculatedColumns() { |
797 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
798 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
799 |
final FeatureQueryCalculatedColumnsPanel panel = new DefaultFeatureQueryCalculatedColumnsPanel(); |
800 |
panel.setStore(this.store);
|
801 |
panel.put(this.parameters.getQuery());
|
802 |
final Dialog dialog = winmanager.createDialog( |
803 |
panel.asJComponent(), |
804 |
i18n.getTranslation("_Calculated_columns"),
|
805 |
null,
|
806 |
WindowManager_v2.BUTTONS_OK_CANCEL |
807 |
); |
808 |
dialog.addActionListener((ActionEvent e) -> {
|
809 |
if( dialog.getAction()==WindowManager_v2.BUTTONS_OK ) {
|
810 |
panel.fetch(this.parameters.getQuery());
|
811 |
search(); |
812 |
} |
813 |
}); |
814 |
dialog.show(WindowManager.MODE.DIALOG); |
815 |
} |
816 |
|
817 |
private void doGroupBy() { |
818 |
int allowGroupBy = ((FeatureStoreProviderFactory)(this.store.getProviderFactory())).allowGroupBy(); |
819 |
if( allowGroupBy!=DataType.YES ) {
|
820 |
// FIXME: mensaje al usaurio.
|
821 |
return;
|
822 |
} |
823 |
|
824 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
825 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
826 |
final FeatureQueryGroupByPanel panel = new DefaultFeatureQueryGroupByPanel(); |
827 |
panel.setStore(this.store);
|
828 |
panel.put(this.parameters.getQuery());
|
829 |
final Dialog dialog = winmanager.createDialog( |
830 |
panel.asJComponent(), |
831 |
i18n.getTranslation("_Select_group_columns_and_aggregate_functions"),
|
832 |
null,
|
833 |
WindowManager_v2.BUTTONS_OK_CANCEL |
834 |
); |
835 |
dialog.addActionListener((ActionEvent e) -> {
|
836 |
if( dialog.getAction()==WindowManager_v2.BUTTONS_OK ) {
|
837 |
panel.fetch(this.parameters.getQuery());
|
838 |
search(); |
839 |
} |
840 |
}); |
841 |
dialog.show(WindowManager.MODE.DIALOG); |
842 |
} |
843 |
|
844 |
private void doSelectResultColumnNames() { |
845 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
846 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
847 |
final FeatureAttributesSelectionPanel panel = DALSwingLocator.getManager().createFeatureAttributeSelectionPanel();
|
848 |
panel.setFeatureType(this.getFeatureType());
|
849 |
panel.setSelectedNames(this.parameters.getResultColumnNames());
|
850 |
final Dialog dialog = winmanager.createDialog( |
851 |
panel.asJComponent(), |
852 |
i18n.getTranslation("_Select_the_columns_to_display"),
|
853 |
null,
|
854 |
WindowManager_v2.BUTTONS_OK_CANCEL |
855 |
); |
856 |
dialog.addActionListener((ActionEvent e) -> {
|
857 |
if( dialog.getAction()==WindowManager_v2.BUTTONS_OK ) {
|
858 |
this.setResultColumnNames(panel.getSelectedNames());
|
859 |
} |
860 |
}); |
861 |
dialog.show(WindowManager.MODE.DIALOG); |
862 |
} |
863 |
|
864 |
|
865 |
public static void selfRegister() { |
866 |
String[][] iconNames = new String[][]{ |
867 |
new String[]{"dalswing", "featurestore-column"}, |
868 |
new String[]{"dalswing", "featurestore-foreing-key"}, |
869 |
new String[]{"dalswing", "featurestore-table"}, |
870 |
new String[]{"dalswing", "search-action-showform"}, |
871 |
new String[]{"dalswing", "search-action-select"}, |
872 |
new String[]{"dalswing", "search-action-select-add"}, |
873 |
new String[]{"dalswing", "search-action-select-filter"} |
874 |
}; |
875 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
876 |
for (String[] icon : iconNames) { |
877 |
URL url = DefaultSearchPanel.class.getResource(icon[1] + ".png"); |
878 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
879 |
} |
880 |
|
881 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
882 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsYesAction());
|
883 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsNoAction());
|
884 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsBothAction());
|
885 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new SelectColumnsAction());
|
886 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new CalculatedColumnsAction());
|
887 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new GroupByAction());
|
888 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new OrderByAction());
|
889 |
} |
890 |
} |