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