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 @ 45326
History | View | Annotate | Download (47.3 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.awt.event.ComponentAdapter; |
10 |
import java.awt.event.ComponentEvent; |
11 |
import java.awt.event.KeyAdapter; |
12 |
import java.awt.event.KeyEvent; |
13 |
import java.net.URL; |
14 |
import java.text.DateFormat; |
15 |
import java.text.SimpleDateFormat; |
16 |
import java.util.ArrayList; |
17 |
import java.util.Calendar; |
18 |
import java.util.Collection; |
19 |
import java.util.Collections; |
20 |
import java.util.Date; |
21 |
import java.util.HashMap; |
22 |
import java.util.List; |
23 |
import java.util.Map; |
24 |
import java.util.Objects; |
25 |
import javax.swing.AbstractAction; |
26 |
import javax.swing.Action; |
27 |
import static javax.swing.Action.ACTION_COMMAND_KEY; |
28 |
import static javax.swing.Action.NAME; |
29 |
import javax.swing.BorderFactory; |
30 |
import javax.swing.ImageIcon; |
31 |
import javax.swing.JButton; |
32 |
import javax.swing.JComponent; |
33 |
import javax.swing.JOptionPane; |
34 |
import javax.swing.ListSelectionModel; |
35 |
import javax.swing.SwingUtilities; |
36 |
import javax.swing.event.ListSelectionEvent; |
37 |
import javax.swing.event.ListSelectionListener; |
38 |
import javax.swing.table.DefaultTableModel; |
39 |
import javax.swing.table.TableModel; |
40 |
import org.apache.commons.io.FilenameUtils; |
41 |
import org.apache.commons.lang.mutable.MutableObject; |
42 |
import org.apache.commons.lang3.StringUtils; |
43 |
import org.apache.commons.lang3.mutable.MutableLong; |
44 |
import org.gvsig.configurableactions.ConfigurableActionsMamager; |
45 |
import org.gvsig.expressionevaluator.Expression; |
46 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
47 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
48 |
import static org.gvsig.fmap.dal.DataManager.DAL_USE_LABELS; |
49 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_BOTH; |
50 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_NO; |
51 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_YES; |
52 |
import org.gvsig.fmap.dal.DataStore; |
53 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
54 |
import org.gvsig.fmap.dal.complements.Search; |
55 |
import org.gvsig.fmap.dal.exception.DataException; |
56 |
import org.gvsig.fmap.dal.feature.Feature; |
57 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
58 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
59 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
60 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
61 |
import org.gvsig.fmap.dal.feature.FeatureType; |
62 |
import org.gvsig.fmap.dal.feature.paging.FacadeOfAFeaturePagingHelper; |
63 |
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory.AbstractDALActionContext; |
64 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
65 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
66 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryCalculatedColumnsPanel; |
67 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModel; |
68 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryGroupByPanel; |
69 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
70 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel; |
71 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory; |
72 |
import org.gvsig.tools.ToolsLocator; |
73 |
import org.gvsig.tools.dataTypes.DataType; |
74 |
import org.gvsig.tools.dynobject.Tags; |
75 |
import org.gvsig.tools.i18n.I18nManager; |
76 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
77 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
78 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
79 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
80 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
81 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
82 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
83 |
import org.gvsig.tools.util.ToolsUtilLocator; |
84 |
import org.slf4j.Logger; |
85 |
import org.slf4j.LoggerFactory; |
86 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryGroupByPanel; |
87 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryOrderPanel; |
88 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryCalculatedColumnsPanel; |
89 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel; |
90 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters; |
91 |
import org.gvsig.tools.bookmarksandhistory.Bookmark; |
92 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
93 |
import org.gvsig.tools.bookmarksandhistory.History; |
94 |
import org.gvsig.tools.dispose.Disposable; |
95 |
import org.gvsig.tools.dispose.DisposeUtils; |
96 |
import org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue; |
97 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_GETVALUE; |
98 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_SETVALUE; |
99 |
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController; |
100 |
import org.gvsig.tools.swing.api.bookmarkshistory.HistoryController; |
101 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
102 |
|
103 |
/**
|
104 |
*
|
105 |
* @author jjdelcerro
|
106 |
*/
|
107 |
@SuppressWarnings({"UseSpecificCatch"}) |
108 |
public class DefaultSearchPanel |
109 |
extends DefaultSearchPanelView
|
110 |
implements FeatureStoreSearchPanel {
|
111 |
|
112 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class); |
113 |
|
114 |
static /* friend */ Integer useLabels = null; |
115 |
private BookmarksController bookmarksController;
|
116 |
private HistoryController historyController;
|
117 |
private FeatureQuery lastQuery;
|
118 |
|
119 |
public static class UseLabelsYesAction extends AbstractAction { |
120 |
|
121 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
122 |
public UseLabelsYesAction() {
|
123 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
124 |
|
125 |
this.putValue(NAME, i18n.getTranslation("_Use_labels")); |
126 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsYes"); |
127 |
} |
128 |
|
129 |
@Override
|
130 |
public Object getValue(String key) { |
131 |
if (NAME.equals(key)) {
|
132 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
133 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
134 |
return i18n.getTranslation("_Use_labels"); |
135 |
} |
136 |
return super.getValue(key); |
137 |
} |
138 |
|
139 |
@Override
|
140 |
public void actionPerformed(ActionEvent ae) { |
141 |
DefaultSearchPanel.useLabels = USE_LABELS_YES; |
142 |
} |
143 |
} |
144 |
|
145 |
public static class UseLabelsNoAction extends AbstractAction { |
146 |
|
147 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
148 |
public UseLabelsNoAction() {
|
149 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
150 |
this.putValue(NAME, i18n.getTranslation("_Use_names")); |
151 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsNo"); |
152 |
} |
153 |
|
154 |
@Override
|
155 |
public Object getValue(String key) { |
156 |
if (NAME.equals(key)) {
|
157 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
158 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
159 |
return i18n.getTranslation("_Use_names"); |
160 |
} |
161 |
return super.getValue(key); |
162 |
} |
163 |
|
164 |
@Override
|
165 |
public void actionPerformed(ActionEvent ae) { |
166 |
DefaultSearchPanel.useLabels = USE_LABELS_NO; |
167 |
} |
168 |
} |
169 |
|
170 |
public static class UseLabelsBothAction extends AbstractAction { |
171 |
|
172 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
173 |
public UseLabelsBothAction() {
|
174 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
175 |
|
176 |
this.putValue(NAME, i18n.getTranslation("_Use_labels_and_names")); |
177 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsBoth"); |
178 |
} |
179 |
|
180 |
@Override
|
181 |
public Object getValue(String key) { |
182 |
if (NAME.equals(key)) {
|
183 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
184 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
185 |
return i18n.getTranslation("_Use_labels_and_names"); |
186 |
} |
187 |
return super.getValue(key); |
188 |
} |
189 |
|
190 |
@Override
|
191 |
public void actionPerformed(ActionEvent ae) { |
192 |
DefaultSearchPanel.useLabels = USE_LABELS_BOTH; |
193 |
} |
194 |
} |
195 |
|
196 |
public static class SelectColumnsAction extends AbstractAction { |
197 |
|
198 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
199 |
public SelectColumnsAction() {
|
200 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
201 |
|
202 |
this.putValue(NAME, i18n.getTranslation("_Select_columns_to_display")); |
203 |
this.putValue(ACTION_COMMAND_KEY, "SelectColumns"); |
204 |
} |
205 |
|
206 |
@Override
|
207 |
public Object getValue(String key) { |
208 |
if (NAME.equals(key)) {
|
209 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
210 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
211 |
return i18n.getTranslation("_Select_columns_to_display"); |
212 |
} |
213 |
return super.getValue(key); |
214 |
} |
215 |
|
216 |
@Override
|
217 |
public void actionPerformed(ActionEvent ae) { |
218 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
219 |
panel.doSelectResultColumnNames(); |
220 |
} |
221 |
} |
222 |
|
223 |
public static class CalculatedColumnsAction extends AbstractAction { |
224 |
|
225 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
226 |
public CalculatedColumnsAction() {
|
227 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
228 |
|
229 |
this.putValue(NAME, i18n.getTranslation("_Calculated_columns")); |
230 |
this.putValue(ACTION_COMMAND_KEY, "CalculatedColumns"); |
231 |
} |
232 |
|
233 |
@Override
|
234 |
public Object getValue(String key) { |
235 |
if (NAME.equals(key)) {
|
236 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
237 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
238 |
return i18n.getTranslation("_Calculated_columns"); |
239 |
} |
240 |
return super.getValue(key); |
241 |
} |
242 |
|
243 |
@Override
|
244 |
public void actionPerformed(ActionEvent ae) { |
245 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
246 |
panel.doCalculatedColumns(); |
247 |
} |
248 |
} |
249 |
|
250 |
public static class GroupByAction extends AbstractAction { |
251 |
|
252 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
253 |
public GroupByAction() {
|
254 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
255 |
|
256 |
this.putValue(NAME, i18n.getTranslation("_Group_by")); |
257 |
this.putValue(ACTION_COMMAND_KEY, "GroupBy"); |
258 |
} |
259 |
|
260 |
@Override
|
261 |
public Object getValue(String key) { |
262 |
if (NAME.equals(key)) {
|
263 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
264 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
265 |
return i18n.getTranslation("_Group_by"); |
266 |
} |
267 |
return super.getValue(key); |
268 |
} |
269 |
|
270 |
@Override
|
271 |
public void actionPerformed(ActionEvent ae) { |
272 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
273 |
panel.doGroupBy(); |
274 |
} |
275 |
} |
276 |
|
277 |
public static class OrderByAction extends AbstractAction { |
278 |
|
279 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
280 |
public OrderByAction() {
|
281 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
282 |
|
283 |
this.putValue(NAME, i18n.getTranslation("_Order_by")); |
284 |
this.putValue(ACTION_COMMAND_KEY, "SelectOrderBy"); |
285 |
} |
286 |
|
287 |
@Override
|
288 |
public Object getValue(String key) { |
289 |
if (NAME.equals(key)) {
|
290 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
291 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
292 |
return i18n.getTranslation("_Order_by"); |
293 |
} |
294 |
return super.getValue(key); |
295 |
} |
296 |
|
297 |
@Override
|
298 |
public void actionPerformed(ActionEvent ae) { |
299 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
300 |
panel.doOrderBy(); |
301 |
} |
302 |
} |
303 |
|
304 |
private class ActionButtons { |
305 |
|
306 |
private final DALActionFactory factory; |
307 |
private final Action action; |
308 |
private final JButton button; |
309 |
|
310 |
public ActionButtons(DALActionFactory factory, Action action, JButton button) { |
311 |
this.factory = factory;
|
312 |
this.action = action;
|
313 |
this.button = button;
|
314 |
} |
315 |
} |
316 |
|
317 |
public static class SearchActionContext extends AbstractDALActionContext { |
318 |
|
319 |
private final DefaultSearchPanel panel; |
320 |
|
321 |
public SearchActionContext(DefaultSearchPanel panel) {
|
322 |
super(FeatureStoreSearchPanel.ACTION_CONTEXT_NAME);
|
323 |
this.panel = panel;
|
324 |
} |
325 |
|
326 |
@Override
|
327 |
public DataStore getStore() {
|
328 |
return this.panel.getStore(); |
329 |
} |
330 |
|
331 |
@Override
|
332 |
public JComponent getActionButton(String actionName) { |
333 |
return this.panel.getActionButton(actionName); |
334 |
} |
335 |
|
336 |
@Override
|
337 |
public int getSelectedsCount() { |
338 |
return this.panel.getSelectedFeatureCount(); |
339 |
} |
340 |
|
341 |
@Override
|
342 |
public Expression getFilterForSelecteds() { |
343 |
return this.panel.getFilterForSelectedFeature(); |
344 |
} |
345 |
|
346 |
@Override
|
347 |
public FeatureQuery getQuery() {
|
348 |
return this.panel.getQuery(); |
349 |
} |
350 |
} |
351 |
|
352 |
private FeatureStore store;
|
353 |
private final ActionListenerSupport acctionListeners; |
354 |
private final Map<String, ActionButtons> actions; |
355 |
private boolean showActions = true; |
356 |
private DefaultSearchParameters parameters;
|
357 |
|
358 |
private List<SearchConditionPanel> conditionPanels; |
359 |
|
360 |
public static final int PANEL_SIMPLIFIED = 0; |
361 |
public static final int PANEL_ADVANCED = 1; |
362 |
private static final String BOOKMARKSANDHISTORY_NAME = "SearchPanel"; |
363 |
private final Bookmarks<Object> bookmarks; |
364 |
private final History<Object> history; |
365 |
|
366 |
public DefaultSearchPanel(FeatureStore store) {
|
367 |
this.store = store;
|
368 |
DisposeUtils.bind(store); |
369 |
this.acctionListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
|
370 |
this.actions = new HashMap<>(); |
371 |
this.parameters = new DefaultSearchParameters(); |
372 |
FeatureQuery featureQuery = this.store.createFeatureQuery();
|
373 |
featureQuery.retrievesAllAttributes(); |
374 |
this.parameters.setQuery(featureQuery);
|
375 |
|
376 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
377 |
Search.COMPLEMENT_MANE, getFeatureType() |
378 |
); |
379 |
List<Search.OrderedAttribute> attributos = search.getOrderedAttributes(
|
380 |
Search.BASIC_TYPES_FILTER, |
381 |
Search.STR_INT_LONG_LABEL_ORDER, |
382 |
12
|
383 |
); |
384 |
for (Search.OrderedAttribute attrdesc : attributos) {
|
385 |
this.parameters.getResultColumnNames().add(attrdesc.getDescriptor().getName());
|
386 |
} |
387 |
this.bookmarks = ToolsLocator.getBookmarksAndHistoryManager().getBookmarksGroup(BOOKMARKSANDHISTORY_NAME);
|
388 |
this.history = ToolsLocator.getBookmarksAndHistoryManager().getHistoryGroup(BOOKMARKSANDHISTORY_NAME);
|
389 |
} |
390 |
|
391 |
@Override
|
392 |
public void dispose() { |
393 |
DisposeUtils.disposeQuietly(store); |
394 |
TableModel m = this.tblResults.getModel(); |
395 |
if( m instanceof Disposable ) { |
396 |
DisposeUtils.disposeQuietly((Disposable) m); |
397 |
} |
398 |
this.store = null; |
399 |
this.tblResults.setModel(new DefaultTableModel()); |
400 |
} |
401 |
|
402 |
@Override
|
403 |
public JComponent asJComponent() { |
404 |
if (this.conditionPanels == null) { |
405 |
this.initComponents();
|
406 |
} |
407 |
return this; |
408 |
} |
409 |
|
410 |
private void addActions() { |
411 |
if (!this.showActions) { |
412 |
return;
|
413 |
} |
414 |
this.pnlActions.removeAll();
|
415 |
this.pnlActions.setLayout(new FlowLayout(FlowLayout.TRAILING, 8, 4)); |
416 |
SearchActionContext actionContext = new SearchActionContext(this); |
417 |
Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions();
|
418 |
for (DALActionFactory factory : factories) {
|
419 |
Action action = factory.createAction(actionContext);
|
420 |
JButton button = new JButton(action); |
421 |
this.actions.put(factory.getName(), new ActionButtons(factory, action, button)); |
422 |
button.setBorder(BorderFactory.createEmptyBorder());
|
423 |
button.setBorderPainted(false);
|
424 |
button.setFocusPainted(false);
|
425 |
button.setContentAreaFilled(false);
|
426 |
button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
427 |
this.pnlActions.add(button);
|
428 |
} |
429 |
this.pnlActions.revalidate();
|
430 |
this.pnlActions.repaint();
|
431 |
} |
432 |
|
433 |
@Override
|
434 |
public void addActionListener(ActionListener listener) { |
435 |
this.acctionListeners.addActionListener(listener);
|
436 |
} |
437 |
|
438 |
@Override
|
439 |
public ActionListener[] getActionListeners() { |
440 |
return this.acctionListeners.getActionListeners(); |
441 |
} |
442 |
|
443 |
@Override
|
444 |
public void removeActionListener(ActionListener listener) { |
445 |
this.acctionListeners.removeActionListener(listener);
|
446 |
} |
447 |
|
448 |
@Override
|
449 |
public void removeAllActionListener() { |
450 |
this.acctionListeners.removeAllActionListener();
|
451 |
} |
452 |
|
453 |
@Override
|
454 |
public void fireActionEvent(ActionEvent event) { |
455 |
this.acctionListeners.fireActionEvent(event);
|
456 |
} |
457 |
|
458 |
@Override
|
459 |
public boolean hasActionListeners() { |
460 |
return this.acctionListeners.hasActionListeners(); |
461 |
} |
462 |
|
463 |
private void initComponents() { |
464 |
this.conditionPanels = new ArrayList<>(); |
465 |
|
466 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
467 |
swingManager.translate(this.tabSearchMode);
|
468 |
swingManager.translate(this.btnSearch);
|
469 |
swingManager.translate(this.btnClear);
|
470 |
swingManager.translate(this.lblExpressionDeBusqueda);
|
471 |
swingManager.translate(this.btnAddAccumulatedFilter);
|
472 |
swingManager.translate(this.btnRemoveAccumulatedFilter);
|
473 |
swingManager.translate(this.btnViewAccumulatedFilter);
|
474 |
|
475 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
476 |
JComponent c = cfgActionsManager.getConfigurableActionsComponent(CONFIGURABLE_PANEL_ID, this); |
477 |
this.pnlCfgActions.setLayout(new BorderLayout(0, 0)); |
478 |
this.pnlCfgActions.add(c, BorderLayout.CENTER); |
479 |
|
480 |
this.conditionPanels.add(
|
481 |
new SearchConditionPanelSimplified(
|
482 |
parameters, |
483 |
store, |
484 |
btnAddAccumulatedFilter, |
485 |
btnRemoveAccumulatedFilter, |
486 |
btnViewAccumulatedFilter, |
487 |
lblField1, |
488 |
lblExtraFields1, |
489 |
lblRelationalOperator1, |
490 |
cboValue1, |
491 |
lblNull1, |
492 |
lblLogicalOperators1, |
493 |
lblField2, |
494 |
lblExtraFields2, |
495 |
lblRelationalOperator2, |
496 |
cboValue2, |
497 |
lblNull2, |
498 |
lblLogicalOperators2, |
499 |
lblField3, |
500 |
lblExtraFields3, |
501 |
lblRelationalOperator3, |
502 |
cboValue3, |
503 |
lblNull3, |
504 |
lblLogicalOperators3, |
505 |
lblField4, |
506 |
lblExtraFields4, |
507 |
lblRelationalOperator4, |
508 |
cboValue4, |
509 |
lblNull4, |
510 |
null
|
511 |
) |
512 |
); |
513 |
this.conditionPanels.add(
|
514 |
new SearchConditionPanelAdvanced(
|
515 |
this.store,
|
516 |
txtAdvancedExpression, |
517 |
btnAdvancedExpression, |
518 |
btnAdvancedExpressionHistory, |
519 |
btnAdvancedExpressionBookmarks |
520 |
) |
521 |
); |
522 |
for (SearchConditionPanelFactory factory : DALSwingLocator.getManager().getSearchConditionPanels()) {
|
523 |
String factoryName = "unknown"; |
524 |
try {
|
525 |
factoryName = factory.getName(); |
526 |
if (factory.isApplicable(store)) {
|
527 |
SearchConditionPanel panel = factory.create(this);
|
528 |
this.conditionPanels.add(panel);
|
529 |
this.tabSearchMode.add(factory.getName(), panel.asJComponent());
|
530 |
} |
531 |
} catch (Throwable th) { |
532 |
LOGGER.warn("Can't create search panel '" + factoryName + "'."); |
533 |
} |
534 |
} |
535 |
|
536 |
this.btnSearch.addActionListener((ActionEvent e) -> { |
537 |
search(); |
538 |
}); |
539 |
|
540 |
this.tblResults.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { |
541 |
for (ActionButtons actionButton : actions.values()) {
|
542 |
if (actionButton.action instanceof ListSelectionListener) { |
543 |
((ListSelectionListener) actionButton.action).valueChanged(e);
|
544 |
} |
545 |
} |
546 |
}); |
547 |
this.btnClear.addActionListener((ActionEvent e) -> { |
548 |
clear(); |
549 |
}); |
550 |
addActions(); |
551 |
|
552 |
swingManager.createTableColumnAdjuster(tblResults); |
553 |
|
554 |
this.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT)); |
555 |
|
556 |
this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(this.bookmarks, btnBookmarks); |
557 |
this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(this.history, btnHistory); |
558 |
|
559 |
this.historyController.setFilter(null); |
560 |
|
561 |
ActionListener bookmarksAndHistoryListener = new ActionListener() { |
562 |
@Override
|
563 |
public void actionPerformed(ActionEvent e) { |
564 |
ActionEventWithCurrentValue<DefaultSearchParameters> b = (ActionEventWithCurrentValue<DefaultSearchParameters>) e; |
565 |
switch (b.getID()) {
|
566 |
case ID_GETVALUE:
|
567 |
DefaultSearchParameters actualParams = (DefaultSearchParameters) fetch(null);
|
568 |
b.setCurrentValue(actualParams); |
569 |
break;
|
570 |
|
571 |
case ID_SETVALUE:
|
572 |
if (b.getCurrentValue() == null) { |
573 |
return;
|
574 |
} |
575 |
DefaultSearchParameters searchParams; |
576 |
try {
|
577 |
searchParams = b.getCurrentValue().getCopy(); |
578 |
} catch (Exception ex) { |
579 |
LOGGER.warn("Not been able to clone export parameters", ex);
|
580 |
return;
|
581 |
} |
582 |
clear(); |
583 |
put(searchParams); |
584 |
Thread th = new Thread(() -> { |
585 |
doSearch(searchParams); |
586 |
}); |
587 |
th.start(); |
588 |
break;
|
589 |
} |
590 |
|
591 |
} |
592 |
}; |
593 |
this.historyController.addActionListener(bookmarksAndHistoryListener);
|
594 |
this.bookmarksController.addActionListener(bookmarksAndHistoryListener);
|
595 |
this.addComponentListener(new ComponentAdapter() { |
596 |
@Override
|
597 |
public void componentHidden(ComponentEvent e) { |
598 |
dispose(); |
599 |
} |
600 |
}); |
601 |
this.tblResults.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
602 |
this.tblResults.addKeyListener(new KeyAdapter() { |
603 |
@Override
|
604 |
public void keyPressed(KeyEvent e) { |
605 |
if( e.getKeyCode()==KeyEvent.VK_F4 ) { |
606 |
doShowCellInDialog(); |
607 |
} |
608 |
} |
609 |
}); |
610 |
if (this.bookmarks.hasBookmark(this.store.getName())) { |
611 |
Bookmark<DefaultSearchParameters> initBookmark = this.bookmarks.get(this.store.getName()); |
612 |
DefaultSearchParameters initSearchParams = initBookmark.getValue().getCopy(); |
613 |
put(initSearchParams); |
614 |
Thread th = new Thread(() -> { |
615 |
doSearch(initSearchParams); |
616 |
}); |
617 |
th.start(); |
618 |
return;
|
619 |
} |
620 |
search(); |
621 |
} |
622 |
|
623 |
private void doShowCellInDialog() { |
624 |
int row = this.tblResults.getSelectedRow(); |
625 |
if( row < 0 ) { |
626 |
return;
|
627 |
} |
628 |
int col = this.tblResults.getSelectedColumn(); |
629 |
if( col < 0 ) { |
630 |
return;
|
631 |
} |
632 |
String s = Objects.toString(this.tblResults.getValueAt(row, col),null); |
633 |
if( StringUtils.isBlank(s) ) {
|
634 |
return;
|
635 |
} |
636 |
ToolsSwingLocator.getToolsSwingManager().showZoomDialog( |
637 |
this,
|
638 |
this.tblResults.getColumnName(col),
|
639 |
s, |
640 |
false
|
641 |
); |
642 |
} |
643 |
|
644 |
private FeatureType getFeatureType() {
|
645 |
try {
|
646 |
return store.getDefaultFeatureType();
|
647 |
} catch (Exception ex) { |
648 |
throw new RuntimeException("Can't retrieve the feature type.", ex); |
649 |
} |
650 |
} |
651 |
|
652 |
@Override
|
653 |
public void setEnabled(boolean enabled) { |
654 |
if (this.conditionPanels == null) { |
655 |
this.initComponents();
|
656 |
} |
657 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
658 |
conditionPanel.setEnabled(enabled); |
659 |
} |
660 |
|
661 |
this.btnClear.setEnabled(enabled);
|
662 |
this.btnSearch.setEnabled(enabled);
|
663 |
for (ActionButtons actionButton : actions.values()) {
|
664 |
actionButton.action.setEnabled(enabled); |
665 |
} |
666 |
} |
667 |
|
668 |
@Override
|
669 |
public void clear() { |
670 |
this.lblMsg.setText(""); |
671 |
if (this.conditionPanels == null) { |
672 |
return;
|
673 |
} |
674 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
675 |
conditionPanel.clear(); |
676 |
} |
677 |
FeatureQuery emptyQuery = this.store.createFeatureQuery();
|
678 |
emptyQuery.retrievesAllAttributes(); |
679 |
this.parameters.setQuery(emptyQuery);
|
680 |
// Mantener las columnas visualizadas
|
681 |
// Elimina las que no existen en el store como campos calculados que
|
682 |
// pudieran existir en el fquery
|
683 |
List<String> resultColumnNames = this.parameters.getResultColumnNames(); |
684 |
ArrayList<String> toDeleteAlreadyDontExist = new ArrayList<String>(); |
685 |
for (String resultColumnName : resultColumnNames) { |
686 |
try {
|
687 |
FeatureAttributeDescriptor attr = this.store.getDefaultFeatureType().getAttributeDescriptor(resultColumnName);
|
688 |
if (attr == null) { |
689 |
toDeleteAlreadyDontExist.add(resultColumnName); |
690 |
} |
691 |
} catch (DataException ex) {
|
692 |
|
693 |
} |
694 |
} |
695 |
resultColumnNames.removeAll(toDeleteAlreadyDontExist); |
696 |
resetTable(); |
697 |
} |
698 |
|
699 |
@Override
|
700 |
public FeatureQuery getLastQuery() {
|
701 |
return this.lastQuery; |
702 |
} |
703 |
|
704 |
public boolean isValid(StringBuilder message) { |
705 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
706 |
SearchConditionPanel panel = this.conditionPanels.get(searchMode);
|
707 |
boolean valid = panel.isValid(message);
|
708 |
return valid;
|
709 |
} |
710 |
|
711 |
@Override
|
712 |
public void search() { |
713 |
StringBuilder message = new StringBuilder(); |
714 |
if (!this.isValid(message)) { |
715 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
716 |
dialogManager.messageDialog( |
717 |
"_The_specified_search_condition_is_not_valid",
|
718 |
"_Search",
|
719 |
JOptionPane.WARNING_MESSAGE
|
720 |
); |
721 |
return;
|
722 |
} |
723 |
lblMsg.setText(ToolsLocator.getI18nManager().getTranslation("_Searching")+"..."); |
724 |
setEnabled(false);
|
725 |
Thread th = new Thread(() -> { |
726 |
try {
|
727 |
|
728 |
SearchParameters searchParams; |
729 |
try {
|
730 |
searchParams = this.fetch(this.parameters.getCopy()); // esto lo actualiza a la ultima // decidir si se devuelve clonado |
731 |
|
732 |
Date date = Calendar.getInstance().getTime(); |
733 |
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
734 |
String strDate = dateFormat.format(date);
|
735 |
searchParams.setName("Params: " + strDate);
|
736 |
} catch (Exception ex) { |
737 |
LOGGER.warn("Not able to create search parameters.", ex);
|
738 |
lblMsg.setText(ToolsLocator.getI18nManager().getTranslation("_Errors_fetching_new_query")+"..."); |
739 |
resetTable(); |
740 |
return;
|
741 |
} |
742 |
doSearch(searchParams); |
743 |
} catch (Exception ex) { |
744 |
LOGGER.warn("Search panel has errors during the search", ex);
|
745 |
resetTable(); |
746 |
} finally {
|
747 |
SwingUtilities.invokeLater(() -> {
|
748 |
setEnabled(true);
|
749 |
}); |
750 |
} |
751 |
|
752 |
}); |
753 |
th.start(); |
754 |
} |
755 |
|
756 |
private void doSearch(SearchParameters searchParams) { |
757 |
final MutableObject model = new MutableObject(null); |
758 |
final MutableLong rowCount=new MutableLong(); |
759 |
try {
|
760 |
final List<Feature> features; |
761 |
FeatureQuery myQuery; |
762 |
// myQuery = this.getQuery().getCopy();
|
763 |
List<String> resultColumnNames = searchParams.getResultColumnNames(); |
764 |
myQuery = searchParams.getQuery(); |
765 |
features = store.getFeatures(myQuery, 50);
|
766 |
FacadeOfAFeaturePagingHelper facade = (FacadeOfAFeaturePagingHelper) features; |
767 |
FeatureType ftype = facade.getFeaturePagingHelper().getFeatureSet().getDefaultFeatureType(); |
768 |
// al modelo le pasamos el ftype de esas features
|
769 |
SimpleFeaturesTableModel tableModel = new SimpleFeaturesTableModel(
|
770 |
ftype, |
771 |
resultColumnNames, |
772 |
features |
773 |
); |
774 |
model.setValue(tableModel); |
775 |
rowCount.setValue(tableModel.getRowCount()); |
776 |
} catch (Exception ex) { |
777 |
LOGGER.warn("Search not able to be executed. Can't get features or create table model", ex);
|
778 |
lblMsg.setText(ToolsLocator.getI18nManager().getTranslation("_Errors_getting_new_feature_set") + "..."); |
779 |
resetTable(); |
780 |
} finally {
|
781 |
SwingUtilities.invokeLater(() -> {
|
782 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
783 |
try {
|
784 |
TableModel oldmodel = tblResults.getModel();
|
785 |
SimpleFeaturesTableModel m = (SimpleFeaturesTableModel) model.getValue(); |
786 |
tblResults.setModel(m); |
787 |
SimpleFeaturesTableModel.setCellRenderers(tblResults); |
788 |
if (oldmodel instanceof SimpleFeaturesTableModel) { |
789 |
((SimpleFeaturesTableModel) oldmodel).dispose(); |
790 |
} |
791 |
if (m.hasErrors()) {
|
792 |
lblMsg.setText(i18n.getTranslation("_Errors_occurred_during_search"));
|
793 |
} else {
|
794 |
lblMsg.setText(String.format("%d " + i18n.getTranslation("_elements"), rowCount.getValue())); |
795 |
} |
796 |
if (this.parameters != null && this.parameters.getQuery() != null) { |
797 |
this.history.add(searchParams);
|
798 |
} |
799 |
} catch (Exception ex) { |
800 |
LOGGER.warn(" Errors occurred during search getting old model", ex);
|
801 |
lblMsg.setText(i18n.getTranslation("_Errors_occurred_during_search"));
|
802 |
} finally {
|
803 |
setEnabled(true);
|
804 |
} |
805 |
}); |
806 |
} |
807 |
} |
808 |
|
809 |
|
810 |
|
811 |
private void resetTable() { |
812 |
if(!SwingUtilities.isEventDispatchThread()) { |
813 |
SwingUtilities.invokeLater(this::resetTable); |
814 |
return;
|
815 |
} |
816 |
List<String> resultColumnNames = null; |
817 |
try {
|
818 |
resultColumnNames = this.parameters.getResultColumnNames();
|
819 |
} catch(Exception ex) { |
820 |
|
821 |
} |
822 |
FeatureType ftype = this.store.getDefaultFeatureTypeQuietly();
|
823 |
SimpleFeaturesTableModel emptyTableModel = new SimpleFeaturesTableModel(
|
824 |
ftype, |
825 |
resultColumnNames, |
826 |
null
|
827 |
); |
828 |
this.tblResults.setModel(emptyTableModel);
|
829 |
|
830 |
} |
831 |
|
832 |
public void setResultColumnNames(List<String> names) { |
833 |
this.parameters.getResultColumnNames().clear();
|
834 |
this.parameters.getResultColumnNames().addAll(names);
|
835 |
if (this.conditionPanels == null) { |
836 |
return;
|
837 |
} |
838 |
SimpleFeaturesTableModel model; |
839 |
// model = (SimpleFeaturesTableModel) this.tblResults.getModel();
|
840 |
List<Feature> features = store.getFeatures(this.parameters.getQuery()); |
841 |
FacadeOfAFeaturePagingHelper facade = (FacadeOfAFeaturePagingHelper) features; |
842 |
FeatureType ftype = facade.getFeaturePagingHelper().getFeatureSet().getDefaultFeatureType(); |
843 |
model = new SimpleFeaturesTableModel(
|
844 |
ftype, |
845 |
this.parameters.getResultColumnNames(),
|
846 |
features |
847 |
); |
848 |
tblResults.setModel(model); |
849 |
} |
850 |
|
851 |
@Override
|
852 |
public boolean setFilter(Expression filter) { |
853 |
try {
|
854 |
if (this.conditionPanels == null) { |
855 |
this.initComponents();
|
856 |
} |
857 |
if (ExpressionUtils.isPhraseEmpty(filter)) {
|
858 |
this.clear();
|
859 |
return true; |
860 |
} |
861 |
int panel = 0; |
862 |
int selected = PANEL_ADVANCED;
|
863 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
864 |
if (panel != PANEL_ADVANCED && conditionPanel.set(filter)) {
|
865 |
selected = panel; |
866 |
} |
867 |
panel++; |
868 |
} |
869 |
this.tabSearchMode.setSelectedIndex(selected);
|
870 |
|
871 |
// SimpleFeaturesTableModel model = new SimpleFeaturesTableModel(this.getStore());
|
872 |
// tblResults.setModel(model);
|
873 |
// lblMsg.setText("");
|
874 |
return true; |
875 |
} catch (Exception ex) { |
876 |
LOGGER.warn("Can't set current search", ex);
|
877 |
return false; |
878 |
} |
879 |
} |
880 |
|
881 |
@Override
|
882 |
public List<SearchConditionPanel> getConditionPanels() { |
883 |
return Collections.unmodifiableList(this.conditionPanels); |
884 |
} |
885 |
|
886 |
@Override
|
887 |
public SearchConditionPanel getConditionPanel(String name) { |
888 |
for (SearchConditionPanel panel : conditionPanels) {
|
889 |
if (StringUtils.equalsIgnoreCase(name, panel.getFactory().getName())) {
|
890 |
return panel;
|
891 |
} |
892 |
} |
893 |
return null; |
894 |
} |
895 |
|
896 |
@Override
|
897 |
public Expression getFilterForSelectedFeature() { |
898 |
if (this.conditionPanels == null) { |
899 |
return null; |
900 |
} |
901 |
int selectedRow = this.tblResults.getSelectedRow(); |
902 |
if (selectedRow < 0) { |
903 |
return null; |
904 |
} |
905 |
try {
|
906 |
List<Feature> features = ((SimpleFeaturesTableModel) this.tblResults.getModel()).getFeatures(); |
907 |
Feature feature = features.get(selectedRow); |
908 |
|
909 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
910 |
FeatureType ftype = this.store.getDefaultFeatureType();
|
911 |
for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
|
912 |
builder.and( |
913 |
builder.eq( |
914 |
builder.column(attrdesc.getName()), |
915 |
builder.constant(feature.get(attrdesc.getName())) |
916 |
) |
917 |
); |
918 |
} |
919 |
Expression filter = ExpressionUtils.createExpression(builder.toString());
|
920 |
return filter;
|
921 |
} catch (Exception ex) { |
922 |
LOGGER.warn("Can't build search for the selected feature.", ex);
|
923 |
return null; |
924 |
} |
925 |
} |
926 |
|
927 |
@Override
|
928 |
public FeatureStore getStore() {
|
929 |
return store;
|
930 |
} |
931 |
|
932 |
private void doOrderBy() { |
933 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
934 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
935 |
FeatureQueryOrderPanel orderPanel = DALSwingLocator.getDataSwingManager().createFeatureStoreOrderPanel(); |
936 |
orderPanel.setStore(store); |
937 |
orderPanel.put(parameters.getQuery()); |
938 |
Dialog dialog = windowManager.createDialog(
|
939 |
orderPanel.asJComponent(), |
940 |
i18n.getTranslation("_Select_order"),
|
941 |
null,
|
942 |
WindowManager_v2.BUTTONS_OK_CANCEL |
943 |
); |
944 |
dialog.addActionListener((ActionEvent e) -> {
|
945 |
if (dialog.getAction() == WindowManager_v2.BUTTON_OK) {
|
946 |
orderPanel.fetch(this.parameters.getQuery());
|
947 |
search(); |
948 |
} |
949 |
}); |
950 |
dialog.show(WindowManager.MODE.DIALOG); |
951 |
|
952 |
} |
953 |
|
954 |
@Override
|
955 |
public ImageIcon loadImage(String imageName) { |
956 |
String name = FilenameUtils.getBaseName(imageName);
|
957 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
958 |
if (theme.exists(name)) {
|
959 |
return theme.get(name);
|
960 |
} |
961 |
URL url = this.getClass().getResource(name + ".png"); |
962 |
if (url == null) { |
963 |
return null; |
964 |
} |
965 |
return new ImageIcon(url); |
966 |
} |
967 |
|
968 |
@Override
|
969 |
public int getSelectedFeatureCount() { |
970 |
if (this.conditionPanels == null) { |
971 |
return 0; |
972 |
} |
973 |
return this.tblResults.getSelectedRowCount(); |
974 |
} |
975 |
|
976 |
@Override
|
977 |
public JComponent getActionButton(String name) { |
978 |
ActionButtons actionButton = this.actions.get(name);
|
979 |
if (actionButton == null) { |
980 |
return null; |
981 |
} |
982 |
return actionButton.button;
|
983 |
} |
984 |
|
985 |
@Override
|
986 |
public void setShowActions(boolean showActions) { |
987 |
this.showActions = showActions;
|
988 |
} |
989 |
|
990 |
@Override
|
991 |
public boolean isShowActions() { |
992 |
return this.showActions; |
993 |
} |
994 |
|
995 |
public static String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc, String tableName) { |
996 |
String theLabel;
|
997 |
int theUseLabels;
|
998 |
if (useLabels == null) { |
999 |
Tags tags = attrdesc.getTags(); |
1000 |
if (tags.has(DAL_USE_LABELS)) {
|
1001 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
1002 |
} else {
|
1003 |
if (attrdesc.getFeatureType()!=null) { |
1004 |
tags = attrdesc.getFeatureType().getTags(); |
1005 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
1006 |
} else {
|
1007 |
theUseLabels = USE_LABELS_NO; |
1008 |
} |
1009 |
} |
1010 |
} else {
|
1011 |
theUseLabels = useLabels; |
1012 |
} |
1013 |
switch (theUseLabels) {
|
1014 |
case USE_LABELS_YES:
|
1015 |
if (StringUtils.isBlank(tableName)) {
|
1016 |
theLabel = attrdesc.getLocalizedLabel(); |
1017 |
} else {
|
1018 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), tableName); |
1019 |
} |
1020 |
break;
|
1021 |
default:
|
1022 |
case USE_LABELS_NO:
|
1023 |
if (StringUtils.isBlank(tableName)) {
|
1024 |
theLabel = attrdesc.getName(); |
1025 |
} else {
|
1026 |
theLabel = String.format("%s [%s]", attrdesc.getName(), tableName); |
1027 |
} |
1028 |
break;
|
1029 |
case USE_LABELS_BOTH:
|
1030 |
if (StringUtils.isBlank(tableName)) {
|
1031 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName()); |
1032 |
} else {
|
1033 |
theLabel = String.format("%s [%s/%s]", attrdesc.getLocalizedLabel(), attrdesc.getName(), tableName); |
1034 |
} |
1035 |
break;
|
1036 |
} |
1037 |
return theLabel;
|
1038 |
} |
1039 |
|
1040 |
private void doCalculatedColumns() { |
1041 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
1042 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1043 |
final FeatureQueryCalculatedColumnsPanel panel = new DefaultFeatureQueryCalculatedColumnsPanel(); |
1044 |
panel.setStore(this.store);
|
1045 |
panel.put(this.parameters.getQuery());
|
1046 |
final Dialog dialog = winmanager.createDialog( |
1047 |
panel.asJComponent(), |
1048 |
i18n.getTranslation("_Calculated_columns"),
|
1049 |
null,
|
1050 |
WindowManager_v2.BUTTONS_OK_CANCEL |
1051 |
); |
1052 |
dialog.addActionListener((ActionEvent e) -> {
|
1053 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) {
|
1054 |
panel.fetch(this.parameters.getQuery());
|
1055 |
search(); |
1056 |
} |
1057 |
}); |
1058 |
dialog.show(WindowManager.MODE.DIALOG); |
1059 |
} |
1060 |
|
1061 |
private void doGroupBy() { |
1062 |
DataStoreProviderFactory dataFactory = this.store.getProviderFactory();
|
1063 |
int allowGroupBy = ((FeatureStoreProviderFactory) dataFactory).allowGroupBy();
|
1064 |
if (allowGroupBy != DataType.YES) {
|
1065 |
// FIXME: mensaje al usaurio.
|
1066 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1067 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
1068 |
dialogs.messageDialog( |
1069 |
i18n.getTranslation("_The_group_function_is_not_available_for_this_table"),
|
1070 |
i18n.getTranslation("_Information"),
|
1071 |
JOptionPane.INFORMATION_MESSAGE
|
1072 |
); |
1073 |
return;
|
1074 |
} |
1075 |
|
1076 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
1077 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1078 |
final FeatureQueryGroupByPanel panelGroupBy = new DefaultFeatureQueryGroupByPanel(); |
1079 |
panelGroupBy.setStore(this.store);
|
1080 |
panelGroupBy.put(this.parameters.getQuery());
|
1081 |
final Dialog dialog = winmanager.createDialog( |
1082 |
panelGroupBy.asJComponent(), |
1083 |
i18n.getTranslation("_Select_group_columns_and_aggregate_functions"),
|
1084 |
null,
|
1085 |
WindowManager_v2.BUTTONS_OK_CANCEL |
1086 |
); |
1087 |
dialog.addActionListener((ActionEvent e) -> {
|
1088 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) {
|
1089 |
panelGroupBy.fetch(this.parameters.getQuery());
|
1090 |
search(); |
1091 |
} |
1092 |
}); |
1093 |
dialog.show(WindowManager.MODE.DIALOG); |
1094 |
} |
1095 |
|
1096 |
private void doSelectResultColumnNames() { |
1097 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
1098 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1099 |
final FeatureAttributesSelectionPanel panelSelectColumns = DALSwingLocator.getManager().createFeatureAttributeSelectionPanel();
|
1100 |
panelSelectColumns.allowCalculatedAttributes(false);
|
1101 |
FeatureType ftype = this.getFeatureType();
|
1102 |
try {
|
1103 |
Feature f = store.findFirst(this.parameters.getQuery());
|
1104 |
if( f!=null ) { |
1105 |
ftype = f.getType(); |
1106 |
} |
1107 |
} catch (Throwable ex) { |
1108 |
LOGGER.warn("Can't retrieve the feature type from the first feature.",ex);
|
1109 |
} |
1110 |
panelSelectColumns.setFeatureType(ftype); |
1111 |
panelSelectColumns.setSelectedNames(this.parameters.getResultColumnNames());
|
1112 |
final Dialog dialog = winmanager.createDialog( |
1113 |
panelSelectColumns.asJComponent(), |
1114 |
i18n.getTranslation("_Select_the_columns_to_display"),
|
1115 |
null,
|
1116 |
WindowManager_v2.BUTTONS_OK_CANCEL |
1117 |
); |
1118 |
dialog.addActionListener((ActionEvent e) -> {
|
1119 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) {
|
1120 |
this.setResultColumnNames(panelSelectColumns.getSelectedNames());
|
1121 |
} |
1122 |
}); |
1123 |
dialog.show(WindowManager.MODE.DIALOG); |
1124 |
} |
1125 |
|
1126 |
@Override
|
1127 |
public void put(SearchParameters inParams) { |
1128 |
this.parameters = (DefaultSearchParameters) inParams;
|
1129 |
for (SearchConditionPanel conditionPanel : this.conditionPanels) { |
1130 |
try {
|
1131 |
conditionPanel.put(inParams); |
1132 |
} catch (Exception ex) { |
1133 |
LOGGER.warn("Can't open panel", ex);
|
1134 |
} |
1135 |
} |
1136 |
this.tabSearchMode.setSelectedIndex(inParams.getSearchMode());
|
1137 |
// this.resetTable();
|
1138 |
|
1139 |
} |
1140 |
|
1141 |
private FeatureQuery getQuery() {
|
1142 |
FeatureQuery query; |
1143 |
try {
|
1144 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
1145 |
SearchConditionPanel panel = this.conditionPanels.get(searchMode);
|
1146 |
Expression filter = panel.get();
|
1147 |
if (searchMode != PANEL_ADVANCED) {
|
1148 |
this.conditionPanels.get(PANEL_ADVANCED).set(filter);
|
1149 |
} |
1150 |
query = (FeatureQuery) this.parameters.getQuery().clone();
|
1151 |
query.retrievesAllAttributes(); |
1152 |
if (ExpressionUtils.isPhraseEmpty(filter)) {
|
1153 |
return query;
|
1154 |
} |
1155 |
query.setFilter(filter); |
1156 |
query.retrievesAllAttributes(); |
1157 |
return query;
|
1158 |
} catch (Exception ex) { |
1159 |
LOGGER.warn("Can't build query.", ex);
|
1160 |
return null; |
1161 |
} |
1162 |
} |
1163 |
|
1164 |
@Override
|
1165 |
public SearchParameters fetch(SearchParameters outParams) {
|
1166 |
// Actualiza el fquery del parameters con los paneles
|
1167 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
1168 |
try {
|
1169 |
conditionPanel.fetch(this.parameters);
|
1170 |
} catch (Exception ex) { |
1171 |
LOGGER.warn("Panel not able to fetch values", ex);
|
1172 |
} |
1173 |
} |
1174 |
|
1175 |
// Actualiza el filtro con el panel activo
|
1176 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
1177 |
SearchConditionPanel panel = this.conditionPanels.get(searchMode);
|
1178 |
Expression filter = panel.get();
|
1179 |
if (searchMode != PANEL_ADVANCED) {
|
1180 |
this.conditionPanels.get(PANEL_ADVANCED).set(filter);
|
1181 |
} |
1182 |
this.parameters.setSearchMode(searchMode);
|
1183 |
FeatureQuery query = (FeatureQuery) this.parameters.getQuery();
|
1184 |
this.lastQuery = query.getCopy();
|
1185 |
query.retrievesAllAttributes(); |
1186 |
query.clearFilter(); |
1187 |
if (!ExpressionUtils.isPhraseEmpty(filter)) {
|
1188 |
query.setFilter(filter); |
1189 |
query.retrievesAllAttributes(); |
1190 |
} |
1191 |
|
1192 |
if (outParams == null) { |
1193 |
return this.parameters.getCopy(); |
1194 |
} |
1195 |
outParams.copyFrom(this.parameters.getCopy());
|
1196 |
return outParams;
|
1197 |
} |
1198 |
|
1199 |
public static void selfRegister() { |
1200 |
String[][] iconNames = new String[][]{ |
1201 |
new String[]{"dalswing", "featurestore-column"}, |
1202 |
new String[]{"dalswing", "featurestore-foreing-key"}, |
1203 |
new String[]{"dalswing", "featurestore-table"}, |
1204 |
new String[]{"dalswing", "search-action-showform"}, |
1205 |
new String[]{"dalswing", "search-action-select"}, |
1206 |
new String[]{"dalswing", "search-action-select-add"}, |
1207 |
new String[]{"dalswing", "search-action-select-filter"}, |
1208 |
new String[]{"dalswing", "search-nullbehavior-null"}, |
1209 |
new String[]{"dalswing", "search-nullbehavior-true"}, |
1210 |
new String[]{"dalswing", "search-nullbehavior-false2"} |
1211 |
|
1212 |
}; |
1213 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
1214 |
for (String[] icon : iconNames) { |
1215 |
URL url = DefaultSearchPanel.class.getResource(icon[1] + ".png"); |
1216 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
1217 |
} |
1218 |
|
1219 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
1220 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsYesAction());
|
1221 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsNoAction());
|
1222 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsBothAction());
|
1223 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new SelectColumnsAction());
|
1224 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new CalculatedColumnsAction());
|
1225 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new GroupByAction());
|
1226 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new OrderByAction());
|
1227 |
} |
1228 |
} |