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 @ 46063
History | View | Annotate | Download (61.7 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.searchpanel; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Cursor; |
5 |
import java.awt.FlowLayout; |
6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.event.ActionListener; |
8 |
import java.awt.event.ComponentAdapter; |
9 |
import java.awt.event.ComponentEvent; |
10 |
import java.awt.event.KeyAdapter; |
11 |
import java.awt.event.KeyEvent; |
12 |
import java.net.URL; |
13 |
import java.text.DateFormat; |
14 |
import java.text.SimpleDateFormat; |
15 |
import java.util.ArrayList; |
16 |
import java.util.Calendar; |
17 |
import java.util.Collection; |
18 |
import java.util.Collections; |
19 |
import java.util.Date; |
20 |
import java.util.HashMap; |
21 |
import java.util.List; |
22 |
import java.util.Map; |
23 |
import java.util.Objects; |
24 |
import javax.swing.AbstractAction; |
25 |
import javax.swing.Action; |
26 |
import static javax.swing.Action.ACTION_COMMAND_KEY; |
27 |
import static javax.swing.Action.NAME; |
28 |
import javax.swing.BorderFactory; |
29 |
import javax.swing.ImageIcon; |
30 |
import javax.swing.JButton; |
31 |
import javax.swing.JComponent; |
32 |
import javax.swing.JMenuItem; |
33 |
import javax.swing.JOptionPane; |
34 |
import javax.swing.JPopupMenu; |
35 |
import javax.swing.JTable; |
36 |
import javax.swing.ListSelectionModel; |
37 |
import javax.swing.SwingUtilities; |
38 |
import javax.swing.event.ChangeEvent; |
39 |
import javax.swing.event.ListSelectionEvent; |
40 |
import javax.swing.event.ListSelectionListener; |
41 |
import javax.swing.table.DefaultTableModel; |
42 |
import javax.swing.table.TableCellRenderer; |
43 |
import javax.swing.table.TableModel; |
44 |
import org.apache.commons.io.FilenameUtils; |
45 |
import org.apache.commons.lang.mutable.MutableObject; |
46 |
import org.apache.commons.lang3.StringUtils; |
47 |
import org.apache.commons.lang3.mutable.MutableLong; |
48 |
import org.gvsig.configurableactions.ConfigurableActionsMamager; |
49 |
import org.gvsig.expressionevaluator.Expression; |
50 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
51 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
52 |
import static org.gvsig.fmap.dal.DataManager.DAL_USE_LABELS; |
53 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_BOTH; |
54 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_NO; |
55 |
import static org.gvsig.fmap.dal.DataManager.USE_LABELS_YES; |
56 |
import org.gvsig.fmap.dal.DataStore; |
57 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
58 |
import org.gvsig.fmap.dal.complements.Search; |
59 |
import org.gvsig.fmap.dal.exception.DataException; |
60 |
import org.gvsig.fmap.dal.feature.Feature; |
61 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
62 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
63 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
64 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
65 |
import org.gvsig.fmap.dal.feature.FeatureType; |
66 |
import org.gvsig.fmap.dal.feature.paging.FacadeOfAFeaturePagingHelper; |
67 |
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory.AbstractDALActionContext; |
68 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
69 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
70 |
import org.gvsig.fmap.dal.swing.DataSwingManager; |
71 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryCalculatedColumnsPanel; |
72 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryGroupByPanel; |
73 |
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel; |
74 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel; |
75 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory; |
76 |
import org.gvsig.tools.ToolsLocator; |
77 |
import org.gvsig.tools.dataTypes.DataType; |
78 |
import org.gvsig.tools.dynobject.Tags; |
79 |
import org.gvsig.tools.i18n.I18nManager; |
80 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
81 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
82 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
83 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
84 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
85 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
86 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
87 |
import org.gvsig.tools.util.ToolsUtilLocator; |
88 |
import org.slf4j.Logger; |
89 |
import org.slf4j.LoggerFactory; |
90 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryGroupByPanel; |
91 |
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryOrderPanel; |
92 |
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel; |
93 |
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryCalculatedColumnsPanel; |
94 |
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel; |
95 |
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModelImpl; |
96 |
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcess; |
97 |
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory; |
98 |
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters; |
99 |
import org.gvsig.tools.bookmarksandhistory.Bookmark; |
100 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
101 |
import org.gvsig.tools.bookmarksandhistory.History; |
102 |
import org.gvsig.tools.dispose.Disposable; |
103 |
import org.gvsig.tools.dispose.DisposeUtils; |
104 |
import org.gvsig.tools.dynform.DynFormLocator; |
105 |
import org.gvsig.tools.dynform.JDynForm; |
106 |
import org.gvsig.tools.dynobject.DynObject; |
107 |
import org.gvsig.tools.swing.api.SupportIsEnable; |
108 |
import org.gvsig.tools.swing.api.SupportIsVisible; |
109 |
import org.gvsig.tools.swing.api.ToolsSwingUtils; |
110 |
import org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue; |
111 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_GETVALUE; |
112 |
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_SETVALUE; |
113 |
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController; |
114 |
import org.gvsig.tools.swing.api.bookmarkshistory.HistoryController; |
115 |
import org.gvsig.tools.swing.api.task.TaskStatusController; |
116 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
117 |
import org.gvsig.tools.task.SimpleTaskStatus; |
118 |
import org.gvsig.tools.util.PropertiesSupportHelper; |
119 |
|
120 |
/**
|
121 |
*
|
122 |
* @author jjdelcerro
|
123 |
*/
|
124 |
@SuppressWarnings({"UseSpecificCatch"}) |
125 |
public class DefaultSearchPanel |
126 |
extends DefaultSearchPanelView2
|
127 |
implements FeatureStoreSearchPanel, SupportIsEnable, SupportIsVisible {
|
128 |
|
129 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class); |
130 |
|
131 |
static /* friend */ Integer useLabels = null; |
132 |
private BookmarksController bookmarksController;
|
133 |
private HistoryController historyController;
|
134 |
private FeatureQuery lastQuery;
|
135 |
private Feature lastSelectedFeature;
|
136 |
private final PropertiesSupportHelper propertiesHelper; |
137 |
private TaskStatusController taskStatusController;
|
138 |
|
139 |
public static class UseLabelsYesAction extends AbstractAction { |
140 |
|
141 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
142 |
public UseLabelsYesAction() {
|
143 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
144 |
|
145 |
this.putValue(NAME, i18n.getTranslation("_Use_labels")); |
146 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsYes"); |
147 |
} |
148 |
|
149 |
@Override
|
150 |
public Object getValue(String key) { |
151 |
if (NAME.equals(key)) {
|
152 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
153 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
154 |
return i18n.getTranslation("_Use_labels"); |
155 |
} |
156 |
return super.getValue(key); |
157 |
} |
158 |
|
159 |
@Override
|
160 |
public void actionPerformed(ActionEvent ae) { |
161 |
DefaultSearchPanel.useLabels = USE_LABELS_YES; |
162 |
} |
163 |
} |
164 |
|
165 |
public static class UseLabelsNoAction extends AbstractAction { |
166 |
|
167 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
168 |
public UseLabelsNoAction() {
|
169 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
170 |
this.putValue(NAME, i18n.getTranslation("_Use_names")); |
171 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsNo"); |
172 |
} |
173 |
|
174 |
@Override
|
175 |
public Object getValue(String key) { |
176 |
if (NAME.equals(key)) {
|
177 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
178 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
179 |
return i18n.getTranslation("_Use_names"); |
180 |
} |
181 |
return super.getValue(key); |
182 |
} |
183 |
|
184 |
@Override
|
185 |
public void actionPerformed(ActionEvent ae) { |
186 |
DefaultSearchPanel.useLabels = USE_LABELS_NO; |
187 |
} |
188 |
} |
189 |
|
190 |
public static class UseLabelsBothAction extends AbstractAction { |
191 |
|
192 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
193 |
public UseLabelsBothAction() {
|
194 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
195 |
|
196 |
this.putValue(NAME, i18n.getTranslation("_Use_labels_and_names")); |
197 |
this.putValue(ACTION_COMMAND_KEY, "UseLabelsBoth"); |
198 |
} |
199 |
|
200 |
@Override
|
201 |
public Object getValue(String key) { |
202 |
if (NAME.equals(key)) {
|
203 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
204 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
205 |
return i18n.getTranslation("_Use_labels_and_names"); |
206 |
} |
207 |
return super.getValue(key); |
208 |
} |
209 |
|
210 |
@Override
|
211 |
public void actionPerformed(ActionEvent ae) { |
212 |
DefaultSearchPanel.useLabels = USE_LABELS_BOTH; |
213 |
} |
214 |
} |
215 |
|
216 |
public static class SelectColumnsAction extends AbstractAction { |
217 |
|
218 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
219 |
public SelectColumnsAction() {
|
220 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
221 |
|
222 |
this.putValue(NAME, i18n.getTranslation("_Select_columns_to_display")); |
223 |
this.putValue(ACTION_COMMAND_KEY, "SelectColumns"); |
224 |
} |
225 |
|
226 |
@Override
|
227 |
public Object getValue(String key) { |
228 |
if (NAME.equals(key)) {
|
229 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
230 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
231 |
return i18n.getTranslation("_Select_columns_to_display"); |
232 |
} |
233 |
return super.getValue(key); |
234 |
} |
235 |
|
236 |
@Override
|
237 |
public void actionPerformed(ActionEvent ae) { |
238 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
239 |
panel.doSelectResultColumnNames(); |
240 |
} |
241 |
} |
242 |
|
243 |
public static class CalculatedColumnsAction extends AbstractAction { |
244 |
|
245 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
246 |
public CalculatedColumnsAction() {
|
247 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
248 |
|
249 |
this.putValue(NAME, i18n.getTranslation("_Calculated_columns")); |
250 |
this.putValue(ACTION_COMMAND_KEY, "CalculatedColumns"); |
251 |
} |
252 |
|
253 |
@Override
|
254 |
public Object getValue(String key) { |
255 |
if (NAME.equals(key)) {
|
256 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
257 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
258 |
return i18n.getTranslation("_Calculated_columns"); |
259 |
} |
260 |
return super.getValue(key); |
261 |
} |
262 |
|
263 |
@Override
|
264 |
public void actionPerformed(ActionEvent ae) { |
265 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
266 |
panel.doCalculatedColumns(); |
267 |
} |
268 |
} |
269 |
|
270 |
public static class GroupByAction extends AbstractAction { |
271 |
|
272 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
273 |
public GroupByAction() {
|
274 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
275 |
|
276 |
this.putValue(NAME, i18n.getTranslation("_Group_by")); |
277 |
this.putValue(ACTION_COMMAND_KEY, "GroupBy"); |
278 |
} |
279 |
|
280 |
@Override
|
281 |
public Object getValue(String key) { |
282 |
if (NAME.equals(key)) {
|
283 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
284 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
285 |
return i18n.getTranslation("_Group_by"); |
286 |
} |
287 |
return super.getValue(key); |
288 |
} |
289 |
|
290 |
@Override
|
291 |
public void actionPerformed(ActionEvent ae) { |
292 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
293 |
panel.doGroupBy(); |
294 |
} |
295 |
} |
296 |
|
297 |
public static class OrderByAction extends AbstractAction { |
298 |
|
299 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
300 |
public OrderByAction() {
|
301 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
302 |
|
303 |
this.putValue(NAME, i18n.getTranslation("_Order_by")); |
304 |
this.putValue(ACTION_COMMAND_KEY, "SelectOrderBy"); |
305 |
} |
306 |
|
307 |
@Override
|
308 |
public Object getValue(String key) { |
309 |
if (NAME.equals(key)) {
|
310 |
// Cuando se registra la accion aun no se han cargado las traducciones
|
311 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
312 |
return i18n.getTranslation("_Order_by"); |
313 |
} |
314 |
return super.getValue(key); |
315 |
} |
316 |
|
317 |
@Override
|
318 |
public void actionPerformed(ActionEvent ae) { |
319 |
DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource(); |
320 |
panel.doOrderBy(); |
321 |
} |
322 |
} |
323 |
|
324 |
private class TablePopupMenu extends JPopupMenu { |
325 |
|
326 |
public final JTable table; |
327 |
|
328 |
@SuppressWarnings("OverridableMethodCallInConstructor") |
329 |
public TablePopupMenu(JTable inputTable) { |
330 |
this.table = inputTable;
|
331 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
332 |
JMenuItem copyRowsActionMenu = new JMenuItem(i18n.getTranslation("_Copy_rows")); |
333 |
copyRowsActionMenu.addActionListener((ActionEvent e) -> {
|
334 |
doCopyRows(table); |
335 |
}); |
336 |
this.add(copyRowsActionMenu);
|
337 |
} |
338 |
} |
339 |
|
340 |
private class ActionButtons { |
341 |
|
342 |
private final DALActionFactory factory; |
343 |
private final Action action; |
344 |
private final JButton button; |
345 |
|
346 |
public ActionButtons(DALActionFactory factory, Action action, JButton button) { |
347 |
this.factory = factory;
|
348 |
this.action = action;
|
349 |
this.button = button;
|
350 |
} |
351 |
} |
352 |
|
353 |
public static class SearchActionContext extends AbstractDALActionContext { |
354 |
|
355 |
private final DefaultSearchPanel panel; |
356 |
|
357 |
public SearchActionContext(DefaultSearchPanel panel) {
|
358 |
super(FeatureStoreSearchPanel.ACTION_CONTEXT_NAME);
|
359 |
this.panel = panel;
|
360 |
} |
361 |
|
362 |
@Override
|
363 |
public DataStore getStore() {
|
364 |
if (this.panel.currentPostProcess == null || this.panel.tabResults.getSelectedIndex() == 0) { |
365 |
return this.panel.getStore(); |
366 |
} else {
|
367 |
return this.panel.postProcessStore; |
368 |
// DataSwingManager manager = DALSwingLocator.getDataSwingManager();
|
369 |
// SearchPostProcessFactory factory= manager.getSearchPostProcess(this.panel.currentPostProcess);
|
370 |
// SearchParameters searchParams = this.panel.parameters.getCopy();
|
371 |
// if (factory.hasProcessParameters()){
|
372 |
// SearchPostProcess.SearchPostProcessResult searchPostProcessResult = this.panel.doExecuteSearchPostProcess(this.panel.store, this.panel.parameters.getQuery(), factory, this.panel.postProcessParams, searchParams);
|
373 |
// return searchPostProcessResult.getStore();
|
374 |
// }
|
375 |
// SearchPostProcess.SearchPostProcessResult searchPostProcessResult = this.panel.doExecuteSearchPostProcess(this.panel.store, this.panel.parameters.getQuery(), factory, null, searchParams);
|
376 |
// return searchPostProcessResult.getStore();
|
377 |
} |
378 |
} |
379 |
|
380 |
@Override
|
381 |
public JComponent getActionButton(String actionName) { |
382 |
return this.panel.getActionButton(actionName); |
383 |
} |
384 |
|
385 |
@Override
|
386 |
public int getSelectedsCount() { |
387 |
return this.panel.getSelectedFeatureCount(); |
388 |
} |
389 |
|
390 |
@Override
|
391 |
public Expression getFilterForSelecteds() { |
392 |
return this.panel.getFilterForSelectedFeature(); |
393 |
} |
394 |
|
395 |
@Override
|
396 |
public FeatureQuery getQuery() {
|
397 |
if (this.panel.currentPostProcess == null || this.panel.tabResults.getSelectedIndex() == 0) { |
398 |
return this.panel.parameters.getQuery(); |
399 |
} else {
|
400 |
return this.panel.postProcessQuery; |
401 |
// DataSwingManager manager = DALSwingLocator.getDataSwingManager();
|
402 |
// SearchPostProcessFactory factory= manager.getSearchPostProcess(this.panel.currentPostProcess);
|
403 |
// SearchParameters searchParams =this.panel.parameters.getCopy();
|
404 |
// if (factory.hasProcessParameters()){
|
405 |
// SearchPostProcess.SearchPostProcessResult searchPostProcessResult = this.panel.doExecuteSearchPostProcess(this.panel.store, this.panel.parameters.getQuery(), factory, this.panel.postProcessParams, searchParams);
|
406 |
// return searchPostProcessResult.getQuery();
|
407 |
// }
|
408 |
// SearchPostProcess.SearchPostProcessResult searchPostProcessResult = this.panel.doExecuteSearchPostProcess(this.panel.store, this.panel.parameters.getQuery(), factory, null, searchParams);
|
409 |
// return searchPostProcessResult.getQuery();
|
410 |
} |
411 |
} |
412 |
} |
413 |
|
414 |
// private class SearchPostProcessListener implements ActionListener {
|
415 |
//
|
416 |
// private final FeatureStore input;
|
417 |
// private final SearchPostProcessFactory factory;
|
418 |
// private final FeatureQuery query;
|
419 |
//
|
420 |
// public SearchPostProcessListener(
|
421 |
// FeatureStore input,
|
422 |
// FeatureQuery query,
|
423 |
// SearchPostProcessFactory factory
|
424 |
// ) {
|
425 |
// this.input = input;
|
426 |
// this.query = query;
|
427 |
// this.factory = factory;
|
428 |
// }
|
429 |
//
|
430 |
// @Override
|
431 |
// public void actionPerformed(ActionEvent e) {
|
432 |
// // habilita la pesta�a del tab con los resultados del post procesado
|
433 |
// if (this.factory.hasProcessParameters()) {
|
434 |
// DynObject parameters = this.factory.createProcessParameters(this.input);
|
435 |
// JDynForm form = DynFormLocator.getDynFormManager().createJDynForm(parameters);
|
436 |
// form.asJComponent().setPreferredSize(new Dimension(350, 250));
|
437 |
//
|
438 |
// I18nManager i18n = ToolsLocator.getI18nManager();
|
439 |
// WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
|
440 |
//
|
441 |
// Dialog dialog = windowManager.createDialog(
|
442 |
// form.asJComponent(),
|
443 |
// i18n.getTranslation("_create_parameters"),
|
444 |
// i18n.getTranslation("_parameters_list"),
|
445 |
// WindowManager_v2.BUTTONS_OK_CANCEL);
|
446 |
//
|
447 |
// dialog.addActionListener((ActionEvent e2) -> {
|
448 |
// if (dialog.getAction() == WindowManager_v2.BUTTON_OK) {
|
449 |
// form.getValues(parameters); // actualiza el valor de lo los parametros con los valores introducidos por el usuario
|
450 |
// doExecuteSearchPostProcess(this.input, this.query, this.factory, parameters);
|
451 |
// postProcessParams = parameters;
|
452 |
// }
|
453 |
// });
|
454 |
//
|
455 |
// dialog.show(WindowManager.MODE.DIALOG);
|
456 |
//
|
457 |
// } else {
|
458 |
// doExecuteSearchPostProcess(this.input, this.query, this.factory, null);
|
459 |
// }
|
460 |
// }
|
461 |
// }
|
462 |
private FeatureStore store;
|
463 |
private final ActionListenerSupport acctionListeners; |
464 |
private final Map<String, ActionButtons> actions; |
465 |
private boolean showActions = true; |
466 |
private DefaultSearchParameters parameters;
|
467 |
|
468 |
private List<SearchConditionPanel> conditionPanels; |
469 |
|
470 |
public static final int PANEL_SIMPLIFIED = 0; |
471 |
public static final int PANEL_ADVANCED = 1; |
472 |
private static final String BOOKMARKSANDHISTORY_NAME = "SearchPanel"; |
473 |
private final Bookmarks<Object> bookmarks; |
474 |
private final History<Object> history; |
475 |
private boolean filterOnlyMode; |
476 |
|
477 |
private String currentPostProcess; |
478 |
|
479 |
private DynObject postProcessParams;
|
480 |
private FeatureStore postProcessStore;
|
481 |
private FeatureQuery postProcessQuery;
|
482 |
private SimpleFeaturesTableModel resultModel;
|
483 |
private SimpleFeaturesTableModel resultPostProcessModel;
|
484 |
|
485 |
private boolean processing; |
486 |
private JComponent configurableActions; |
487 |
|
488 |
@SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) |
489 |
public DefaultSearchPanel(FeatureStore store) {
|
490 |
this.store = store;
|
491 |
this.filterOnlyMode = false; |
492 |
DisposeUtils.bind(store); |
493 |
this.acctionListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
|
494 |
this.actions = new HashMap<>(); |
495 |
this.parameters = new DefaultSearchParameters(); |
496 |
FeatureQuery featureQuery = this.store.createFeatureQuery();
|
497 |
featureQuery.retrievesAllAttributes(); |
498 |
this.parameters.setQuery(featureQuery);
|
499 |
this.currentPostProcess = null; |
500 |
this.postProcessParams = null; |
501 |
this.postProcessStore = null; |
502 |
this.postProcessQuery = null; |
503 |
this.processing = false; |
504 |
this.configurableActions = null; |
505 |
this.resultModel = null; |
506 |
this.resultPostProcessModel = null; |
507 |
this.propertiesHelper = new PropertiesSupportHelper(); |
508 |
this.propertiesHelper.setProperty("SearchPanel", this); |
509 |
|
510 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
511 |
Search.COMPLEMENT_MANE, getFeatureType() |
512 |
); |
513 |
List<Search.OrderedAttribute> attributos = search.getOrderedAttributes(
|
514 |
Search.BASIC_TYPES_FILTER, |
515 |
Search.STR_INT_LONG_LABEL_ORDER, |
516 |
12
|
517 |
); |
518 |
for (Search.OrderedAttribute attrdesc : attributos) {
|
519 |
this.parameters.getResultColumnNames().add(attrdesc.getDescriptor().getName());
|
520 |
} |
521 |
this.bookmarks = ToolsLocator.getBookmarksAndHistoryManager().getBookmarksGroup(BOOKMARKSANDHISTORY_NAME);
|
522 |
this.history = ToolsLocator.getBookmarksAndHistoryManager().getHistoryGroup(BOOKMARKSANDHISTORY_NAME);
|
523 |
} |
524 |
|
525 |
@Override
|
526 |
public void dispose() { |
527 |
DisposeUtils.disposeQuietly(store); |
528 |
TableModel m = this.tblResults.getModel(); |
529 |
if (m instanceof Disposable) { |
530 |
DisposeUtils.disposeQuietly((Disposable) m); |
531 |
} |
532 |
this.store = null; |
533 |
this.tblResults.setModel(new DefaultTableModel()); |
534 |
} |
535 |
|
536 |
@Override
|
537 |
public JComponent asJComponent() { |
538 |
if (this.conditionPanels == null) { |
539 |
this.initComponents();
|
540 |
} |
541 |
return this; |
542 |
} |
543 |
|
544 |
private void addActions() { |
545 |
if (!this.showActions) { |
546 |
return;
|
547 |
} |
548 |
this.pnlActions.removeAll();
|
549 |
this.pnlActions.setLayout(new FlowLayout(FlowLayout.TRAILING, 8, 4)); |
550 |
SearchActionContext actionContext = new SearchActionContext(this); |
551 |
Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions();
|
552 |
for (DALActionFactory factory : factories) {
|
553 |
if (!factory.isApplicable(actionContext)) {
|
554 |
continue;
|
555 |
} |
556 |
Action action = factory.createAction(actionContext);
|
557 |
JButton button = new JButton(action); |
558 |
this.actions.put(factory.getName(), new ActionButtons(factory, action, button)); |
559 |
button.setBorder(BorderFactory.createEmptyBorder());
|
560 |
button.setBorderPainted(false);
|
561 |
button.setFocusPainted(false);
|
562 |
button.setContentAreaFilled(false);
|
563 |
button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
564 |
this.pnlActions.add(button);
|
565 |
} |
566 |
this.pnlActions.revalidate();
|
567 |
this.pnlActions.repaint();
|
568 |
} |
569 |
|
570 |
@Override
|
571 |
public void addActionListener(ActionListener listener) { |
572 |
this.acctionListeners.addActionListener(listener);
|
573 |
} |
574 |
|
575 |
@Override
|
576 |
public ActionListener[] getActionListeners() { |
577 |
return this.acctionListeners.getActionListeners(); |
578 |
} |
579 |
|
580 |
@Override
|
581 |
public void removeActionListener(ActionListener listener) { |
582 |
this.acctionListeners.removeActionListener(listener);
|
583 |
} |
584 |
|
585 |
@Override
|
586 |
public void removeAllActionListener() { |
587 |
this.acctionListeners.removeAllActionListener();
|
588 |
} |
589 |
|
590 |
@Override
|
591 |
public void fireActionEvent(ActionEvent event) { |
592 |
this.acctionListeners.fireActionEvent(event);
|
593 |
} |
594 |
|
595 |
@Override
|
596 |
public boolean hasActionListeners() { |
597 |
return this.acctionListeners.hasActionListeners(); |
598 |
} |
599 |
|
600 |
private void initComponents() { |
601 |
this.conditionPanels = new ArrayList<>(); |
602 |
|
603 |
ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager(); |
604 |
swingManager.translate(this.tabSearchMode);
|
605 |
swingManager.translate(this.tabResults);
|
606 |
swingManager.translate(this.btnSearch);
|
607 |
swingManager.translate(this.btnClear);
|
608 |
swingManager.translate(this.btnSearchPostProcess);
|
609 |
swingManager.translate(this.lblExpressionDeBusqueda);
|
610 |
swingManager.translate(this.btnAddAccumulatedFilter);
|
611 |
swingManager.translate(this.btnRemoveAccumulatedFilter);
|
612 |
swingManager.translate(this.btnViewAccumulatedFilter);
|
613 |
|
614 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
615 |
this.configurableActions = cfgActionsManager.getConfigurableActionsComponent(CONFIGURABLE_PANEL_ID, this); |
616 |
this.pnlCfgActions.setLayout(new BorderLayout(0, 0)); |
617 |
this.pnlCfgActions.add(configurableActions, BorderLayout.CENTER); |
618 |
|
619 |
this.taskStatusController = ToolsSwingLocator.getTaskStatusSwingManager().createTaskStatusController(
|
620 |
this.lblStatusTitle,
|
621 |
this.lblMsg,
|
622 |
this.pgbStatus);
|
623 |
this.pgbStatus.setVisible(false); |
624 |
|
625 |
this.conditionPanels.add(
|
626 |
new SearchConditionPanelSimplified(
|
627 |
parameters, |
628 |
store, |
629 |
btnAddAccumulatedFilter, |
630 |
btnRemoveAccumulatedFilter, |
631 |
btnViewAccumulatedFilter, |
632 |
lblField1, |
633 |
lblExtraFields1, |
634 |
lblRelationalOperator1, |
635 |
cboValue1, |
636 |
lblNull1, |
637 |
lblLogicalOperators1, |
638 |
lblField2, |
639 |
lblExtraFields2, |
640 |
lblRelationalOperator2, |
641 |
cboValue2, |
642 |
lblNull2, |
643 |
lblLogicalOperators2, |
644 |
lblField3, |
645 |
lblExtraFields3, |
646 |
lblRelationalOperator3, |
647 |
cboValue3, |
648 |
lblNull3, |
649 |
lblLogicalOperators3, |
650 |
lblField4, |
651 |
lblExtraFields4, |
652 |
lblRelationalOperator4, |
653 |
cboValue4, |
654 |
lblNull4, |
655 |
null
|
656 |
) |
657 |
); |
658 |
|
659 |
SearchConditionPanelAdvanced advancedPanel = new SearchConditionPanelAdvanced(
|
660 |
this.store,
|
661 |
txtAdvancedExpression, |
662 |
btnAdvancedExpression, |
663 |
btnAdvancedExpressionHistory, |
664 |
btnAdvancedExpressionBookmarks |
665 |
); |
666 |
this.conditionPanels.add(advancedPanel);
|
667 |
|
668 |
for (SearchConditionPanelFactory factory : DALSwingLocator.getManager().getSearchConditionPanels()) {
|
669 |
String factoryName = "unknown"; |
670 |
try {
|
671 |
factoryName = factory.getName(); |
672 |
if (factory.isApplicable(store)) {
|
673 |
SearchConditionPanel panel = factory.create(this);
|
674 |
this.conditionPanels.add(panel);
|
675 |
this.tabSearchMode.add(factory.getName(), panel.asJComponent());
|
676 |
} |
677 |
} catch (Throwable th) { |
678 |
LOGGER.warn("Can't create search panel '" + factoryName + "'."); |
679 |
} |
680 |
} |
681 |
|
682 |
this.btnSearch.addActionListener((ActionEvent e) -> { |
683 |
this.tabResults.setEnabledAt(1, false); |
684 |
search(); |
685 |
}); |
686 |
|
687 |
this.tblResults.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { |
688 |
try {
|
689 |
lastSelectedFeature = resultModel.getFeatureAt(tblResults.getSelectedRow()); |
690 |
} catch (Throwable th) { |
691 |
LOGGER.debug("Can't retrieve last selected feature.", th);
|
692 |
} |
693 |
for (ActionButtons actionButton : actions.values()) {
|
694 |
if (actionButton.action instanceof ListSelectionListener) { |
695 |
((ListSelectionListener) actionButton.action).valueChanged(e);
|
696 |
} |
697 |
} |
698 |
}); |
699 |
this.btnClear.addActionListener((ActionEvent e) -> { |
700 |
clear(); |
701 |
}); |
702 |
addActions(); |
703 |
|
704 |
//swingManager.createTableColumnAdjuster(tblResults);
|
705 |
//swingManager.createTableColumnAdjuster(tblSearchPostProcessResults);
|
706 |
// this.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
|
707 |
ToolsSwingUtils.ensureRowsCols(this, 20, 100, 30, 120); |
708 |
|
709 |
this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(this.bookmarks, btnBookmarks); |
710 |
this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(this.history, btnHistory); |
711 |
|
712 |
this.historyController.setFilter(null); |
713 |
|
714 |
ActionListener bookmarksAndHistoryListener = (ActionEvent e) -> { |
715 |
ActionEventWithCurrentValue<DefaultSearchParameters> b = (ActionEventWithCurrentValue<DefaultSearchParameters>) e; |
716 |
switch (b.getID()) {
|
717 |
case ID_GETVALUE:
|
718 |
DefaultSearchParameters actualParams = (DefaultSearchParameters) fetch(null);
|
719 |
b.setCurrentValue(actualParams); |
720 |
break;
|
721 |
|
722 |
case ID_SETVALUE:
|
723 |
if (b.getCurrentValue() == null) { |
724 |
return;
|
725 |
} |
726 |
DefaultSearchParameters searchParams; |
727 |
try {
|
728 |
searchParams = b.getCurrentValue().getCopy(); |
729 |
} catch (Exception ex) { |
730 |
LOGGER.warn("Not been able to clone export parameters", ex);
|
731 |
return;
|
732 |
} |
733 |
clear(); |
734 |
put(searchParams); |
735 |
Thread th = new Thread(() -> { |
736 |
doSearch(searchParams); |
737 |
}); |
738 |
th.start(); |
739 |
break;
|
740 |
} |
741 |
}; |
742 |
this.historyController.addActionListener(bookmarksAndHistoryListener);
|
743 |
this.bookmarksController.addActionListener(bookmarksAndHistoryListener);
|
744 |
this.addComponentListener(new ComponentAdapter() { |
745 |
@Override
|
746 |
public void componentHidden(ComponentEvent e) { |
747 |
dispose(); |
748 |
} |
749 |
}); |
750 |
|
751 |
this.btnSearchPostProcess.addActionListener((ActionEvent e) -> { |
752 |
try {
|
753 |
doSelectSearchPostprocess(); |
754 |
} catch (DataException ex) {
|
755 |
LOGGER.warn("Can't select a Search Post Process", ex);
|
756 |
} |
757 |
}); |
758 |
|
759 |
this.tabResults.setEnabledAt(1, false); |
760 |
|
761 |
this.tblResults.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
762 |
this.tblResults.addKeyListener(new KeyAdapter() { |
763 |
@Override
|
764 |
public void keyPressed(KeyEvent e) { |
765 |
if (e.getKeyCode() == KeyEvent.VK_F4) { |
766 |
doShowCellInDialog(); |
767 |
} |
768 |
} |
769 |
}); |
770 |
|
771 |
this.tblResults.setComponentPopupMenu(new TablePopupMenu(this.tblResults)); |
772 |
this.tblSearchPostProcessResults.setComponentPopupMenu(new TablePopupMenu(this.tblSearchPostProcessResults)); |
773 |
|
774 |
//this.tblResults.add
|
775 |
if (this.bookmarks.hasBookmark(this.store.getName())) { |
776 |
Bookmark<DefaultSearchParameters> initBookmark = this.bookmarks.get(this.store.getName()); |
777 |
DefaultSearchParameters initSearchParams = initBookmark.getValue().getCopy(); |
778 |
put(initSearchParams); |
779 |
Thread th = new Thread(() -> { |
780 |
doSearch(initSearchParams); |
781 |
}); |
782 |
th.start(); |
783 |
return;
|
784 |
} |
785 |
|
786 |
this.tabResults.addChangeListener((ChangeEvent evt) -> { |
787 |
SwingUtilities.invokeLater(() -> {
|
788 |
if (tabResults.getSelectedIndex() == 0) { |
789 |
updateNumberElementsMsg(resultModel); |
790 |
} else {
|
791 |
updateNumberElementsMsg(resultPostProcessModel); |
792 |
} |
793 |
}); |
794 |
}); |
795 |
if (this.filterOnlyMode) { |
796 |
this.btnSearchPostProcess.setVisible(false); |
797 |
} |
798 |
clear(); |
799 |
search(); |
800 |
} |
801 |
|
802 |
private void doShowCellInDialog() { |
803 |
int row = this.tblResults.getSelectedRow(); |
804 |
if (row < 0) { |
805 |
return;
|
806 |
} |
807 |
int col = this.tblResults.getSelectedColumn(); |
808 |
if (col < 0) { |
809 |
return;
|
810 |
} |
811 |
String s = Objects.toString(this.tblResults.getValueAt(row, col), null); |
812 |
if (StringUtils.isBlank(s)) {
|
813 |
return;
|
814 |
} |
815 |
ToolsSwingLocator.getToolsSwingManager().showZoomDialog( |
816 |
this,
|
817 |
this.tblResults.getColumnName(col),
|
818 |
s, |
819 |
false
|
820 |
); |
821 |
} |
822 |
|
823 |
@Override
|
824 |
public FeatureType getFeatureType() {
|
825 |
try {
|
826 |
return store.getDefaultFeatureType();
|
827 |
} catch (Exception ex) { |
828 |
throw new RuntimeException("Can't retrieve the feature type.", ex); |
829 |
} |
830 |
} |
831 |
|
832 |
@Override
|
833 |
public void setEnabled(boolean enabled) { |
834 |
if (!SwingUtilities.isEventDispatchThread()) { |
835 |
SwingUtilities.invokeLater(() -> {
|
836 |
setEnabled(enabled); |
837 |
}); |
838 |
return;
|
839 |
} |
840 |
|
841 |
if (this.conditionPanels == null) { |
842 |
this.initComponents();
|
843 |
} |
844 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
845 |
conditionPanel.setEnabled(enabled); |
846 |
} |
847 |
|
848 |
this.btnClear.setEnabled(enabled);
|
849 |
this.btnSearch.setEnabled(enabled);
|
850 |
for (ActionButtons actionButton : actions.values()) {
|
851 |
actionButton.action.setEnabled(enabled); |
852 |
} |
853 |
this.btnSearchPostProcess.setEnabled(enabled);
|
854 |
//bookmarkController,historyController,configurableActions
|
855 |
} |
856 |
|
857 |
@Override
|
858 |
public void clear() { |
859 |
this.taskStatusController.setTitle(""); |
860 |
if (this.conditionPanels == null) { |
861 |
return;
|
862 |
} |
863 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
864 |
conditionPanel.clear(); |
865 |
} |
866 |
FeatureQuery emptyQuery = this.store.createFeatureQuery();
|
867 |
emptyQuery.retrievesAllAttributes(); |
868 |
this.parameters.setQuery(emptyQuery);
|
869 |
// Mantener las columnas visualizadas
|
870 |
// Elimina las que no existen en el store como campos calculados que
|
871 |
// pudieran existir en el fquery
|
872 |
List<String> resultColumnNames = this.parameters.getResultColumnNames(); |
873 |
ArrayList<String> toDeleteAlreadyDontExist = new ArrayList<>(); |
874 |
for (String resultColumnName : resultColumnNames) { |
875 |
try {
|
876 |
FeatureAttributeDescriptor attr = this.store.getDefaultFeatureType().getAttributeDescriptor(resultColumnName);
|
877 |
if (attr == null) { |
878 |
toDeleteAlreadyDontExist.add(resultColumnName); |
879 |
} |
880 |
} catch (DataException ex) {
|
881 |
|
882 |
} |
883 |
} |
884 |
resultColumnNames.removeAll(toDeleteAlreadyDontExist); |
885 |
resetTable(); |
886 |
} |
887 |
|
888 |
@Override
|
889 |
public FeatureQuery getLastQuery() {
|
890 |
return this.lastQuery; |
891 |
} |
892 |
|
893 |
public boolean isValid(StringBuilder message) { |
894 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
895 |
SearchConditionPanel panel = this.conditionPanels.get(searchMode);
|
896 |
boolean valid = panel.isValid(message);
|
897 |
return valid;
|
898 |
} |
899 |
|
900 |
@Override
|
901 |
public void search() { |
902 |
StringBuilder message = new StringBuilder(); |
903 |
if (!this.isValid(message)) { |
904 |
ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
905 |
dialogManager.messageDialog( |
906 |
"_The_specified_search_condition_is_not_valid",
|
907 |
"_Search",
|
908 |
JOptionPane.WARNING_MESSAGE
|
909 |
); |
910 |
return;
|
911 |
} |
912 |
lblMsg.setText(ToolsLocator.getI18nManager().getTranslation("_Searching") + "..."); |
913 |
setEnabled(false);
|
914 |
Thread th = new Thread(() -> { |
915 |
try {
|
916 |
SearchParameters searchParams; |
917 |
try {
|
918 |
searchParams = this.fetch(this.parameters.getCopy()); // esto lo actualiza a la ultima // decidir si se devuelve clonado |
919 |
|
920 |
Date date = Calendar.getInstance().getTime(); |
921 |
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
922 |
String strDate = dateFormat.format(date);
|
923 |
searchParams.setName("Params: " + strDate);
|
924 |
} catch (Exception ex) { |
925 |
LOGGER.warn("Not able to create search parameters.", ex);
|
926 |
this.taskStatusController.setTitle(ToolsLocator.getI18nManager().getTranslation("_Errors_fetching_new_query") + "..."); |
927 |
resetTable(); |
928 |
return;
|
929 |
} |
930 |
doSearch(searchParams); |
931 |
} catch (Exception ex) { |
932 |
LOGGER.warn("Search panel has errors during the search", ex);
|
933 |
resetTable(); |
934 |
} finally {
|
935 |
SwingUtilities.invokeLater(() -> {
|
936 |
setEnabled(true);
|
937 |
}); |
938 |
} |
939 |
}); |
940 |
th.start(); |
941 |
} |
942 |
|
943 |
private void doSearch(SearchParameters searchParams) { |
944 |
final MutableObject model = new MutableObject(null); |
945 |
final MutableLong rowCount = new MutableLong(); |
946 |
Cursor savedCursor = this.getCursor(); |
947 |
SimpleTaskStatus status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("");
|
948 |
status.setAutoremove(true);
|
949 |
status.add(); |
950 |
this.taskStatusController.bind(status);
|
951 |
try {
|
952 |
status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Processing_search"));
|
953 |
SwingUtilities.invokeLater(() -> {
|
954 |
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
955 |
}); |
956 |
final List<Feature> features; |
957 |
FeatureQuery myQuery; |
958 |
// myQuery = this.getQuery().getCopy();
|
959 |
this.tabResults.setSelectedIndex(0); |
960 |
List<String> resultColumnNames = searchParams.getResultColumnNames(); |
961 |
myQuery = searchParams.getQuery().getCopy(); |
962 |
features = store.getFeatures(myQuery, 50);
|
963 |
FacadeOfAFeaturePagingHelper facade = (FacadeOfAFeaturePagingHelper) features; |
964 |
FeatureType ftype = facade.getFeaturePagingHelper().getFeatureSet().getDefaultFeatureType(); |
965 |
// al modelo le pasamos el ftype de esas features
|
966 |
SimpleFeaturesTableModel tableModel = new SimpleFeaturesTableModelImpl(
|
967 |
ftype, |
968 |
resultColumnNames, |
969 |
features |
970 |
); |
971 |
model.setValue(tableModel); |
972 |
rowCount.setValue(tableModel.getRowCount()); |
973 |
} catch (Exception ex) { |
974 |
LOGGER.warn("Search not able to be executed. Can't get features or create table model", ex);
|
975 |
status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Errors_getting_new_feature_set") + "..."); |
976 |
status.abort(); |
977 |
resetTable(); |
978 |
} finally {
|
979 |
SwingUtilities.invokeLater(() -> {
|
980 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
981 |
try {
|
982 |
TableModel oldmodel = tblResults.getModel();
|
983 |
resultModel = (SimpleFeaturesTableModel) model.getValue(); |
984 |
tblResults.setModel(resultModel); |
985 |
resultModel.setCellRenderers(tblResults, getCustomRenderers(searchParams)); |
986 |
if (oldmodel instanceof SimpleFeaturesTableModelImpl) { |
987 |
((SimpleFeaturesTableModelImpl) oldmodel).dispose(); |
988 |
} |
989 |
if (resultModel.hasErrors()) {
|
990 |
status.setTitle(i18n.getTranslation("_Errors_occurred_during_search"));
|
991 |
} else {
|
992 |
status.setTitle(String.format("%d " + i18n.getTranslation("_elements"), rowCount.getValue())); |
993 |
} |
994 |
if (this.parameters != null && this.parameters.getQuery() != null) { |
995 |
this.history.add(searchParams);
|
996 |
} |
997 |
} catch (Exception ex) { |
998 |
LOGGER.warn(" Errors occurred during search getting old model", ex);
|
999 |
status.setTitle(i18n.getTranslation("_Errors_occurred_during_search"));
|
1000 |
} finally {
|
1001 |
setEnabled(true);
|
1002 |
status.terminate(); |
1003 |
this.setCursor(savedCursor);
|
1004 |
} |
1005 |
}); |
1006 |
} |
1007 |
} |
1008 |
|
1009 |
private Map<String, TableCellRenderer> getCustomRenderers(SearchParameters parameters) { |
1010 |
FeatureType ft = this.store.getDefaultFeatureTypeQuietly();
|
1011 |
HashMap<String, TableCellRenderer> renderers = new HashMap<String, TableCellRenderer>(); |
1012 |
for (FeatureAttributeDescriptor attr : ft) {
|
1013 |
if (attr.getDataType().isNumeric()) {
|
1014 |
// renderers.put(attr.getName(), new ColorRangeRenderer(attr, 20, 50));
|
1015 |
} |
1016 |
} |
1017 |
return renderers;
|
1018 |
} |
1019 |
|
1020 |
private void resetTable() { |
1021 |
if (!SwingUtilities.isEventDispatchThread()) { |
1022 |
SwingUtilities.invokeLater(this::resetTable); |
1023 |
return;
|
1024 |
} |
1025 |
List<String> resultColumnNames = null; |
1026 |
try {
|
1027 |
resultColumnNames = this.parameters.getResultColumnNames();
|
1028 |
} catch (Exception ex) { |
1029 |
|
1030 |
} |
1031 |
FeatureType ftype = this.store.getDefaultFeatureTypeQuietly();
|
1032 |
SimpleFeaturesTableModelImpl emptyTableModel = new SimpleFeaturesTableModelImpl(
|
1033 |
ftype, |
1034 |
resultColumnNames, |
1035 |
null
|
1036 |
); |
1037 |
this.tblResults.setModel(emptyTableModel);
|
1038 |
|
1039 |
} |
1040 |
|
1041 |
public void setResultColumnNames(List<String> names) { |
1042 |
this.parameters.getResultColumnNames().clear();
|
1043 |
this.parameters.getResultColumnNames().addAll(names);
|
1044 |
// if (this.conditionPanels == null) {
|
1045 |
// return;
|
1046 |
// }
|
1047 |
// SimpleFeaturesTableModelImpl model;
|
1048 |
//// model = (SimpleFeaturesTableModel) this.tblResults.getModel();
|
1049 |
// List<Feature> features = store.getFeatures(this.parameters.getQuery());
|
1050 |
// FacadeOfAFeaturePagingHelper facade = (FacadeOfAFeaturePagingHelper) features;
|
1051 |
// FeatureType ftype = facade.getFeaturePagingHelper().getFeatureSet().getDefaultFeatureType();
|
1052 |
// model = new SimpleFeaturesTableModelImpl(
|
1053 |
// ftype,
|
1054 |
// this.parameters.getResultColumnNames(),
|
1055 |
// features
|
1056 |
// );
|
1057 |
// tblResults.setModel(model);
|
1058 |
} |
1059 |
|
1060 |
@Override
|
1061 |
public boolean setFilter(Expression filter) { |
1062 |
try {
|
1063 |
if (this.conditionPanels == null) { |
1064 |
this.initComponents();
|
1065 |
} |
1066 |
if (ExpressionUtils.isPhraseEmpty(filter)) {
|
1067 |
this.clear();
|
1068 |
return true; |
1069 |
} |
1070 |
int panel = 0; |
1071 |
int selected = PANEL_ADVANCED;
|
1072 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
1073 |
if (panel != PANEL_ADVANCED && conditionPanel.set(filter)) {
|
1074 |
selected = panel; |
1075 |
} |
1076 |
panel++; |
1077 |
} |
1078 |
this.tabSearchMode.setSelectedIndex(selected);
|
1079 |
|
1080 |
// SimpleFeaturesTableModel model = new SimpleFeaturesTableModel(this.getStore());
|
1081 |
// tblResults.setModel(model);
|
1082 |
// lblMsg.setText("");
|
1083 |
return true; |
1084 |
} catch (Exception ex) { |
1085 |
LOGGER.warn("Can't set current search", ex);
|
1086 |
return false; |
1087 |
} |
1088 |
} |
1089 |
|
1090 |
@Override
|
1091 |
public List<SearchConditionPanel> getConditionPanels() { |
1092 |
return Collections.unmodifiableList(this.conditionPanels); |
1093 |
} |
1094 |
|
1095 |
@Override
|
1096 |
public SearchConditionPanel getConditionPanel(String name) { |
1097 |
if (conditionPanels == null) { |
1098 |
return null; |
1099 |
} |
1100 |
for (SearchConditionPanel panel : conditionPanels) {
|
1101 |
if (StringUtils.equalsIgnoreCase(name, panel.getFactory().getName())) {
|
1102 |
return panel;
|
1103 |
} |
1104 |
} |
1105 |
return null; |
1106 |
} |
1107 |
|
1108 |
@Override
|
1109 |
public Expression getFilterForSelectedFeature() { |
1110 |
if (this.conditionPanels == null) { |
1111 |
return null; |
1112 |
} |
1113 |
if (this.tabResults.getSelectedIndex() == 0) { |
1114 |
int selectedRow = this.tblResults.getSelectedRow(); |
1115 |
if (selectedRow < 0) { |
1116 |
return null; |
1117 |
} |
1118 |
try {
|
1119 |
List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblResults.getModel()).getFeatures(); |
1120 |
Feature feature = features.get(selectedRow); |
1121 |
|
1122 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
1123 |
FeatureType ftype = this.store.getDefaultFeatureType();
|
1124 |
for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
|
1125 |
builder.and( |
1126 |
builder.eq( |
1127 |
builder.column(attrdesc.getName()), |
1128 |
builder.constant(feature.get(attrdesc.getName())) |
1129 |
) |
1130 |
); |
1131 |
} |
1132 |
Expression filter = ExpressionUtils.createExpression(builder.toString());
|
1133 |
return filter;
|
1134 |
} catch (Exception ex) { |
1135 |
LOGGER.warn("Can't build search for the selected feature.", ex);
|
1136 |
return null; |
1137 |
} |
1138 |
} else {
|
1139 |
if (this.currentPostProcess == null) { |
1140 |
return null; |
1141 |
} |
1142 |
int selectedRow = this.tblSearchPostProcessResults.getSelectedRow(); |
1143 |
if (selectedRow < 0) { |
1144 |
return null; |
1145 |
} |
1146 |
try {
|
1147 |
List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblSearchPostProcessResults.getModel()).getFeatures(); |
1148 |
Feature feature = features.get(selectedRow); |
1149 |
|
1150 |
ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder(); |
1151 |
FeatureType ftype = this.postProcessStore.getDefaultFeatureType();
|
1152 |
for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
|
1153 |
builder.and( |
1154 |
builder.eq( |
1155 |
builder.column(attrdesc.getName()), |
1156 |
builder.constant(feature.get(attrdesc.getName())) |
1157 |
) |
1158 |
); |
1159 |
} |
1160 |
Expression filter = ExpressionUtils.createExpression(builder.toString());
|
1161 |
return filter;
|
1162 |
} catch (Exception ex) { |
1163 |
LOGGER.warn("Can't build search for the selected feature.", ex);
|
1164 |
return null; |
1165 |
} |
1166 |
} |
1167 |
|
1168 |
} |
1169 |
|
1170 |
@Override
|
1171 |
public FeatureStore getStore() {
|
1172 |
return store;
|
1173 |
} |
1174 |
|
1175 |
private void doOrderBy() { |
1176 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1177 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
1178 |
FeatureQueryOrderPanel orderPanel = DALSwingLocator.getDataSwingManager().createFeatureStoreOrderPanel(); |
1179 |
orderPanel.setStore(store); |
1180 |
orderPanel.put(parameters.getQuery()); |
1181 |
Dialog dialog = windowManager.createDialog(
|
1182 |
orderPanel.asJComponent(), |
1183 |
i18n.getTranslation("_Select_order"),
|
1184 |
null,
|
1185 |
WindowManager_v2.BUTTONS_OK_CANCEL |
1186 |
); |
1187 |
dialog.addActionListener((ActionEvent e) -> {
|
1188 |
if (dialog.getAction() == WindowManager_v2.BUTTON_OK) {
|
1189 |
orderPanel.fetch(this.parameters.getQuery());
|
1190 |
search(); |
1191 |
} |
1192 |
}); |
1193 |
dialog.show(WindowManager.MODE.DIALOG); |
1194 |
} |
1195 |
|
1196 |
private void doCopyRows(JTable table) { |
1197 |
Cursor savedCursor = this.getCursor(); |
1198 |
SimpleTaskStatus status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("");
|
1199 |
status.setAutoremove(true);
|
1200 |
status.add(); |
1201 |
this.taskStatusController.bind(status);
|
1202 |
Thread task = new Thread(() -> { |
1203 |
try {
|
1204 |
this.processing = true; |
1205 |
this.setEnabled(false); |
1206 |
status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Copying_rows_to_clipboard"));
|
1207 |
SwingUtilities.invokeLater(() -> {
|
1208 |
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
1209 |
}); |
1210 |
|
1211 |
SimpleFeaturesTableModel model = null;
|
1212 |
if (table.getModel() instanceof SimpleFeaturesTableModel) { |
1213 |
model = (SimpleFeaturesTableModel) table.getModel(); |
1214 |
} |
1215 |
|
1216 |
String LINE_BREAK = System.lineSeparator(); |
1217 |
String CELL_BREAK = "\t"; |
1218 |
char DELIMITER = '"'; |
1219 |
|
1220 |
int[] selection = table.getSelectedRows(); |
1221 |
for (int i = 0; i < selection.length; i++) { |
1222 |
selection[i] = table.convertRowIndexToModel(selection[i]); |
1223 |
} |
1224 |
|
1225 |
int numCols = table.getColumnCount();
|
1226 |
StringBuilder excelStr = new StringBuilder(); |
1227 |
boolean valueIsNumeric;
|
1228 |
|
1229 |
for (int j = 0; j < numCols; j++) { |
1230 |
|
1231 |
excelStr.append(DELIMITER); |
1232 |
excelStr.append(escape(table.getColumnName(j), LINE_BREAK, CELL_BREAK)); |
1233 |
excelStr.append(DELIMITER); |
1234 |
|
1235 |
if (j < numCols - 1) { |
1236 |
excelStr.append(CELL_BREAK); |
1237 |
} |
1238 |
} |
1239 |
|
1240 |
//from( 0, selection.length)
|
1241 |
status.setRangeOfValues(0, selection.length);
|
1242 |
excelStr.append(LINE_BREAK); |
1243 |
for (int i : selection) { |
1244 |
if (status.isCancellationRequested()) {
|
1245 |
status.message("");
|
1246 |
status.cancel(); |
1247 |
return;
|
1248 |
} |
1249 |
for (int j = 0; j < numCols; j++) { |
1250 |
valueIsNumeric = false;
|
1251 |
FeatureAttributeDescriptor descriptor = null;
|
1252 |
if (model != null) { |
1253 |
descriptor = model.getFeatureDescriptor(j); |
1254 |
if (descriptor.getDataType().isNumeric()) {
|
1255 |
if (!descriptor.hasAvailableValues()) {
|
1256 |
valueIsNumeric = true;
|
1257 |
} |
1258 |
} |
1259 |
} |
1260 |
if (!valueIsNumeric) {
|
1261 |
excelStr.append(DELIMITER); |
1262 |
} |
1263 |
Object value = table.getValueAt(i, j);
|
1264 |
String valueStr;
|
1265 |
if (descriptor != null) { |
1266 |
valueStr = escape(descriptor.format(value), LINE_BREAK, CELL_BREAK); |
1267 |
} else {
|
1268 |
valueStr = escape(value, LINE_BREAK, CELL_BREAK); |
1269 |
|
1270 |
} |
1271 |
excelStr.append(valueStr); |
1272 |
|
1273 |
if (!valueIsNumeric) {
|
1274 |
excelStr.append(DELIMITER); |
1275 |
} |
1276 |
if (j < numCols - 1) { |
1277 |
excelStr.append(CELL_BREAK); |
1278 |
} |
1279 |
} |
1280 |
status.setCurValue(i); |
1281 |
excelStr.append(LINE_BREAK); |
1282 |
} |
1283 |
String toStr = excelStr.toString();
|
1284 |
|
1285 |
status.terminate(); |
1286 |
doPostCopyRows(status, toStr); |
1287 |
|
1288 |
} catch (Exception ex) { |
1289 |
LOGGER.warn("Not able to copy rows to the clipboard", ex);
|
1290 |
status.message("Not able to copy rows to the clipboard");
|
1291 |
status.abort(); |
1292 |
} finally {
|
1293 |
this.processing = false; |
1294 |
SwingUtilities.invokeLater(() -> {
|
1295 |
this.setCursor(savedCursor);
|
1296 |
}); |
1297 |
status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Copy_ended"));
|
1298 |
this.updateComponentState();
|
1299 |
} |
1300 |
}, "SearchPanelCopyRows");
|
1301 |
task.start(); |
1302 |
} |
1303 |
|
1304 |
private void doPostCopyRows(SimpleTaskStatus status, String toStr) { |
1305 |
if (!SwingUtilities.isEventDispatchThread()) { |
1306 |
SwingUtilities.invokeLater(() -> {
|
1307 |
doPostCopyRows(status, toStr); |
1308 |
}); |
1309 |
return;
|
1310 |
} |
1311 |
ToolsSwingLocator.getToolsSwingManager().putInClipboard(toStr); |
1312 |
// StringSelection sel = new StringSelection(toStr);
|
1313 |
// Clipboard CLIPBOARD = Toolkit.getDefaultToolkit().getSystemClipboard();
|
1314 |
// CLIPBOARD.setContents(sel, null);
|
1315 |
} |
1316 |
|
1317 |
private String escape(Object cell, String LINE_BREAK, String CELL_BREAK) { |
1318 |
return (cell == null ? "" : cell.toString() |
1319 |
.replace(CELL_BREAK, " ")
|
1320 |
.replace("\n", " ") |
1321 |
.replace("\r", " ")); |
1322 |
} |
1323 |
|
1324 |
@Override
|
1325 |
public ImageIcon loadImage(String imageName) { |
1326 |
String name = FilenameUtils.getBaseName(imageName);
|
1327 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
1328 |
if (theme.exists(name)) {
|
1329 |
return theme.get(name);
|
1330 |
} |
1331 |
URL url = this.getClass().getResource(name + ".png"); |
1332 |
if (url == null) { |
1333 |
return null; |
1334 |
} |
1335 |
return new ImageIcon(url); |
1336 |
} |
1337 |
|
1338 |
@Override
|
1339 |
public int getSelectedFeatureCount() { |
1340 |
if (this.conditionPanels == null) { |
1341 |
return 0; |
1342 |
} |
1343 |
if (this.currentPostProcess == null || this.tabResults.getSelectedIndex() == 0) { |
1344 |
return this.tblResults.getSelectedRowCount(); |
1345 |
} |
1346 |
return this.tblSearchPostProcessResults.getSelectedRowCount(); |
1347 |
} |
1348 |
|
1349 |
@Override
|
1350 |
public JComponent getActionButton(String name) { |
1351 |
ActionButtons actionButton = this.actions.get(name);
|
1352 |
if (actionButton == null) { |
1353 |
return null; |
1354 |
} |
1355 |
return actionButton.button;
|
1356 |
} |
1357 |
|
1358 |
@Override
|
1359 |
public void setShowActions(boolean showActions) { |
1360 |
this.showActions = showActions;
|
1361 |
} |
1362 |
|
1363 |
@Override
|
1364 |
public boolean isShowActions() { |
1365 |
return this.showActions; |
1366 |
} |
1367 |
|
1368 |
public static String getAttributeDescriptorLabel(FeatureAttributeDescriptor attrdesc, String tableName) { |
1369 |
String theLabel;
|
1370 |
int theUseLabels;
|
1371 |
if (useLabels == null) { |
1372 |
Tags tags = attrdesc.getTags(); |
1373 |
if (tags.has(DAL_USE_LABELS)) {
|
1374 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
1375 |
} else {
|
1376 |
if (attrdesc.getFeatureType() != null) { |
1377 |
tags = attrdesc.getFeatureType().getTags(); |
1378 |
theUseLabels = tags.getInt(DAL_USE_LABELS, USE_LABELS_NO); |
1379 |
} else {
|
1380 |
theUseLabels = USE_LABELS_NO; |
1381 |
} |
1382 |
} |
1383 |
} else {
|
1384 |
theUseLabels = useLabels; |
1385 |
} |
1386 |
switch (theUseLabels) {
|
1387 |
case USE_LABELS_YES:
|
1388 |
if (StringUtils.isBlank(tableName)) {
|
1389 |
theLabel = attrdesc.getLocalizedLabel(); |
1390 |
} else {
|
1391 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), tableName); |
1392 |
} |
1393 |
break;
|
1394 |
default:
|
1395 |
case USE_LABELS_NO:
|
1396 |
if (StringUtils.isBlank(tableName)) {
|
1397 |
theLabel = attrdesc.getName(); |
1398 |
} else {
|
1399 |
theLabel = String.format("%s [%s]", attrdesc.getName(), tableName); |
1400 |
} |
1401 |
break;
|
1402 |
case USE_LABELS_BOTH:
|
1403 |
if (StringUtils.isBlank(tableName)) {
|
1404 |
theLabel = String.format("%s [%s]", attrdesc.getLocalizedLabel(), attrdesc.getName()); |
1405 |
} else {
|
1406 |
theLabel = String.format("%s [%s/%s]", attrdesc.getLocalizedLabel(), attrdesc.getName(), tableName); |
1407 |
} |
1408 |
break;
|
1409 |
} |
1410 |
return theLabel;
|
1411 |
} |
1412 |
|
1413 |
private void doCalculatedColumns() { |
1414 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
1415 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1416 |
final FeatureQueryCalculatedColumnsPanel panel = new DefaultFeatureQueryCalculatedColumnsPanel(); |
1417 |
panel.setStore(this.store);
|
1418 |
panel.put(this.parameters.getQuery());
|
1419 |
final Dialog dialog = winmanager.createDialog( |
1420 |
panel.asJComponent(), |
1421 |
i18n.getTranslation("_Calculated_columns"),
|
1422 |
null,
|
1423 |
WindowManager_v2.BUTTONS_OK_CANCEL |
1424 |
); |
1425 |
dialog.addActionListener((ActionEvent e) -> {
|
1426 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) {
|
1427 |
panel.fetch(this.parameters.getQuery());
|
1428 |
search(); |
1429 |
} |
1430 |
}); |
1431 |
dialog.show(WindowManager.MODE.DIALOG); |
1432 |
} |
1433 |
|
1434 |
private void doGroupBy() { |
1435 |
DataStoreProviderFactory dataFactory = this.store.getProviderFactory();
|
1436 |
int allowGroupBy = ((FeatureStoreProviderFactory) dataFactory).allowGroupBy();
|
1437 |
if (allowGroupBy != DataType.YES) {
|
1438 |
// FIXME: mensaje al usaurio.
|
1439 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1440 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
1441 |
dialogs.messageDialog( |
1442 |
i18n.getTranslation("_The_group_function_is_not_available_for_this_table"),
|
1443 |
i18n.getTranslation("_Information"),
|
1444 |
JOptionPane.INFORMATION_MESSAGE
|
1445 |
); |
1446 |
return;
|
1447 |
} |
1448 |
|
1449 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
1450 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1451 |
final FeatureQueryGroupByPanel panelGroupBy = new DefaultFeatureQueryGroupByPanel(); |
1452 |
panelGroupBy.setStore(this.store);
|
1453 |
panelGroupBy.put(this.parameters.getQuery());
|
1454 |
final Dialog dialog = winmanager.createDialog( |
1455 |
panelGroupBy.asJComponent(), |
1456 |
i18n.getTranslation("_Select_group_columns_and_aggregate_functions"),
|
1457 |
null,
|
1458 |
WindowManager_v2.BUTTONS_OK_CANCEL |
1459 |
); |
1460 |
dialog.addActionListener((ActionEvent e) -> {
|
1461 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) {
|
1462 |
panelGroupBy.fetch(this.parameters.getQuery());
|
1463 |
search(); |
1464 |
} |
1465 |
}); |
1466 |
dialog.show(WindowManager.MODE.DIALOG); |
1467 |
} |
1468 |
|
1469 |
private void doSelectResultColumnNames() { |
1470 |
WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
1471 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1472 |
final FeatureAttributesSelectionPanel panelSelectColumns = DALSwingLocator.getManager().createFeatureAttributeSelectionPanel();
|
1473 |
panelSelectColumns.allowCalculatedAttributes(false);
|
1474 |
FeatureType ftype = this.getFeatureType();
|
1475 |
try {
|
1476 |
Feature f = store.findFirst(this.parameters.getQuery());
|
1477 |
if (f != null) { |
1478 |
ftype = f.getType(); |
1479 |
} |
1480 |
} catch (Throwable ex) { |
1481 |
LOGGER.warn("Can't retrieve the feature type from the first feature.", ex);
|
1482 |
} |
1483 |
panelSelectColumns.setFeatureType(ftype); |
1484 |
panelSelectColumns.setSelectedNames(this.parameters.getResultColumnNames());
|
1485 |
final Dialog dialog = winmanager.createDialog( |
1486 |
panelSelectColumns.asJComponent(), |
1487 |
i18n.getTranslation("_Select_the_columns_to_display"),
|
1488 |
null,
|
1489 |
WindowManager_v2.BUTTONS_OK_CANCEL |
1490 |
); |
1491 |
dialog.addActionListener((ActionEvent e) -> {
|
1492 |
if (dialog.getAction() == WindowManager_v2.BUTTONS_OK) {
|
1493 |
this.setResultColumnNames(panelSelectColumns.getSelectedNames());
|
1494 |
search(); |
1495 |
} |
1496 |
}); |
1497 |
dialog.show(WindowManager.MODE.DIALOG); |
1498 |
} |
1499 |
|
1500 |
@Override
|
1501 |
public void put(SearchParameters inParams) { |
1502 |
this.parameters = (DefaultSearchParameters) inParams;
|
1503 |
for (SearchConditionPanel conditionPanel : this.conditionPanels) { |
1504 |
try {
|
1505 |
conditionPanel.put(inParams); |
1506 |
} catch (Exception ex) { |
1507 |
LOGGER.warn("Can't open panel", ex);
|
1508 |
} |
1509 |
} |
1510 |
this.tabSearchMode.setSelectedIndex(inParams.getSearchMode());
|
1511 |
// this.resetTable();
|
1512 |
|
1513 |
} |
1514 |
|
1515 |
private FeatureQuery getQuery() {
|
1516 |
FeatureQuery query; |
1517 |
try {
|
1518 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
1519 |
SearchConditionPanel panel = this.conditionPanels.get(searchMode);
|
1520 |
Expression filter = panel.get();
|
1521 |
if (searchMode != PANEL_ADVANCED) {
|
1522 |
this.conditionPanels.get(PANEL_ADVANCED).set(filter);
|
1523 |
} |
1524 |
query = (FeatureQuery) this.parameters.getQuery().clone();
|
1525 |
query.retrievesAllAttributes(); |
1526 |
if (ExpressionUtils.isPhraseEmpty(filter)) {
|
1527 |
return query;
|
1528 |
} |
1529 |
query.setFilter(filter); |
1530 |
query.retrievesAllAttributes(); |
1531 |
return query;
|
1532 |
} catch (Exception ex) { |
1533 |
LOGGER.warn("Can't build query.", ex);
|
1534 |
return null; |
1535 |
} |
1536 |
} |
1537 |
|
1538 |
@Override
|
1539 |
public SearchParameters fetch(SearchParameters outParams) {
|
1540 |
// Actualiza el fquery del parameters con los paneles
|
1541 |
for (SearchConditionPanel conditionPanel : conditionPanels) {
|
1542 |
try {
|
1543 |
conditionPanel.fetch(this.parameters);
|
1544 |
} catch (Exception ex) { |
1545 |
LOGGER.warn("Panel not able to fetch values", ex);
|
1546 |
} |
1547 |
} |
1548 |
|
1549 |
// Actualiza el filtro con el panel activo
|
1550 |
int searchMode = this.tabSearchMode.getSelectedIndex(); |
1551 |
SearchConditionPanel panel = this.conditionPanels.get(searchMode);
|
1552 |
Expression filter = panel.get();
|
1553 |
if (searchMode != PANEL_ADVANCED) {
|
1554 |
this.conditionPanels.get(PANEL_ADVANCED).set(filter);
|
1555 |
} |
1556 |
this.parameters.setSearchMode(searchMode);
|
1557 |
FeatureQuery query = (FeatureQuery) this.parameters.getQuery();
|
1558 |
this.lastQuery = query.getCopy();
|
1559 |
query.retrievesAllAttributes(); |
1560 |
query.clearFilter(); |
1561 |
if (!ExpressionUtils.isPhraseEmpty(filter)) {
|
1562 |
query.setFilter(filter); |
1563 |
query.retrievesAllAttributes(); |
1564 |
} |
1565 |
|
1566 |
if (outParams == null) { |
1567 |
return this.parameters.getCopy(); |
1568 |
} |
1569 |
outParams.copyFrom(this.parameters.getCopy());
|
1570 |
return outParams;
|
1571 |
} |
1572 |
|
1573 |
public static void selfRegister() { |
1574 |
String[][] iconNames = new String[][]{ |
1575 |
new String[]{"dalswing", "featurestore-column"}, |
1576 |
new String[]{"dalswing", "featurestore-foreing-key"}, |
1577 |
new String[]{"dalswing", "featurestore-table"}, |
1578 |
new String[]{"dalswing", "search-action-select"}, |
1579 |
new String[]{"dalswing", "search-action-select-add"}, |
1580 |
new String[]{"dalswing", "search-action-select-filter"}, |
1581 |
new String[]{"dalswing", "search-nullbehavior-null"}, |
1582 |
new String[]{"dalswing", "search-nullbehavior-true"}, |
1583 |
new String[]{"dalswing", "search-nullbehavior-false2"} |
1584 |
|
1585 |
}; |
1586 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
1587 |
for (String[] icon : iconNames) { |
1588 |
URL url = DefaultSearchPanel.class.getResource(icon[1] + ".png"); |
1589 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
1590 |
} |
1591 |
|
1592 |
ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager(); |
1593 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsYesAction());
|
1594 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsNoAction());
|
1595 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new UseLabelsBothAction());
|
1596 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new SelectColumnsAction());
|
1597 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new CalculatedColumnsAction());
|
1598 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new GroupByAction());
|
1599 |
cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new OrderByAction());
|
1600 |
} |
1601 |
|
1602 |
private void doSelectSearchPostprocess() throws DataException { |
1603 |
DataSwingManager manager = DALSwingLocator.getDataSwingManager(); |
1604 |
Map<String, SearchPostProcessFactory> searchPostProcessFactoryMap = manager.getSearchPostProcess(); |
1605 |
|
1606 |
JPopupMenu menu = new JPopupMenu(); |
1607 |
for (String factory : searchPostProcessFactoryMap.keySet()) { |
1608 |
JMenuItem item;
|
1609 |
item = new JMenuItem(factory); |
1610 |
SearchParameters searchParams = this.fetch(this.parameters.getCopy()); |
1611 |
FeatureQuery myQuery = searchParams.getQuery().getCopy(); |
1612 |
// item.addActionListener(new SearchPostProcessListener(this.store, myQuery, manager.getSearchPostProcess(factory)));
|
1613 |
item.addActionListener((ActionEvent e) -> {
|
1614 |
doSearchPostProcess(store, myQuery, manager.getSearchPostProcess(factory), searchParams); |
1615 |
}); |
1616 |
menu.add(item); |
1617 |
} |
1618 |
menu.show(this.btnSearchPostProcess, 0, this.btnSearchPostProcess.getHeight()); |
1619 |
} |
1620 |
|
1621 |
private void doExecuteSearchPostProcess( |
1622 |
FeatureStore input, |
1623 |
FeatureQuery query, |
1624 |
SearchPostProcessFactory factory, |
1625 |
DynObject parameters |
1626 |
) { |
1627 |
Cursor savedCursor = this.getCursor(); |
1628 |
SimpleTaskStatus status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("");
|
1629 |
status.setAutoremove(true);
|
1630 |
status.add(); |
1631 |
this.taskStatusController.bind(status);
|
1632 |
Thread task = new Thread(() -> { |
1633 |
try {
|
1634 |
SwingUtilities.invokeLater(() -> {
|
1635 |
this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
1636 |
}); |
1637 |
this.processing = true; |
1638 |
this.updateComponentState();
|
1639 |
SearchPostProcess process = factory.createProcess(factory, input, query, parameters); |
1640 |
|
1641 |
if (parameters != null) { |
1642 |
process.setParameters(parameters); |
1643 |
} |
1644 |
//Ejecutar el execute en thread para no bloquear el software
|
1645 |
SearchPostProcess.SearchPostProcessResult output = process.execute(input, query, parameters, status); |
1646 |
if (output != null) { |
1647 |
this.postProcessStore = output.getStore();
|
1648 |
this.postProcessQuery = output.getQuery();
|
1649 |
|
1650 |
doLoadSearchPostProccessResults(this.postProcessStore);
|
1651 |
|
1652 |
} |
1653 |
this.currentPostProcess = factory.getName();
|
1654 |
status.terminate(); |
1655 |
|
1656 |
} catch (Exception ex) { |
1657 |
LOGGER.warn("SearchPostProcess not able to be executed.", ex);
|
1658 |
resetPostProcessTable(); |
1659 |
status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Error_in_post_process_operation"));
|
1660 |
status.message("");
|
1661 |
status.abort(); |
1662 |
} finally {
|
1663 |
SwingUtilities.invokeLater(() -> {
|
1664 |
this.setCursor(savedCursor);
|
1665 |
}); |
1666 |
this.processing = false; |
1667 |
this.updateComponentState();
|
1668 |
} |
1669 |
}, "ExecuteSearchPostProcess");
|
1670 |
|
1671 |
task.start(); |
1672 |
|
1673 |
} |
1674 |
|
1675 |
private void doLoadSearchPostProccessResults(FeatureStore input) { |
1676 |
if (!SwingUtilities.isEventDispatchThread()) { |
1677 |
SwingUtilities.invokeLater(() -> {
|
1678 |
doLoadSearchPostProccessResults(input); |
1679 |
}); |
1680 |
return;
|
1681 |
} |
1682 |
|
1683 |
final List<Feature> featuresSearchPostProccessResults; |
1684 |
final FeatureQuery finalQuery;
|
1685 |
finalQuery = null;
|
1686 |
try {
|
1687 |
this.tabResults.setEnabledAt(1, true); |
1688 |
this.tabResults.setSelectedIndex(1); |
1689 |
featuresSearchPostProccessResults = input.getFeatures(finalQuery, 20);
|
1690 |
FacadeOfAFeaturePagingHelper facadeSearchPostProccessResults = (FacadeOfAFeaturePagingHelper) featuresSearchPostProccessResults; |
1691 |
FeatureType ftypeSearchPostProccessResults = facadeSearchPostProccessResults.getFeaturePagingHelper().getFeatureSet().getDefaultFeatureType(); |
1692 |
// al modelo le pasamos el ftype de esas features
|
1693 |
resultPostProcessModel = new SimpleFeaturesTableModelImpl(
|
1694 |
ftypeSearchPostProccessResults, |
1695 |
this.parameters.getResultColumnNames(),
|
1696 |
featuresSearchPostProccessResults |
1697 |
); |
1698 |
|
1699 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1700 |
TableModel oldmodel = tblSearchPostProcessResults.getModel();
|
1701 |
tblSearchPostProcessResults.setModel(resultPostProcessModel); |
1702 |
resultPostProcessModel.setCellRenderers(tblSearchPostProcessResults); |
1703 |
if (oldmodel instanceof SimpleFeaturesTableModel) { |
1704 |
((SimpleFeaturesTableModel) oldmodel).dispose(); |
1705 |
} |
1706 |
updateNumberElementsMsg(resultPostProcessModel); |
1707 |
// if (resultPostProcessModel.hasErrors()) {
|
1708 |
// lblMsg.setText("_Errors_occurred_load_search_post_process");
|
1709 |
// } else {
|
1710 |
// lblMsg.setText(String.format("%d " + i18n.getTranslation("_elements"), resultPostProcessModel.getRowCount()));
|
1711 |
// }
|
1712 |
} catch (Exception ex) { |
1713 |
resetPostProcessTable(); |
1714 |
LOGGER.warn("SearchPostProcess not able to be executed. Can't get features or create table model", ex);
|
1715 |
} |
1716 |
} |
1717 |
|
1718 |
private void updateComponentState() { |
1719 |
if (!SwingUtilities.isEventDispatchThread()) { |
1720 |
SwingUtilities.invokeLater(this::updateComponentState); |
1721 |
return;
|
1722 |
} |
1723 |
this.pgbStatus.setVisible(processing);
|
1724 |
this.setEnabled(!processing);
|
1725 |
} |
1726 |
|
1727 |
private void resetPostProcessTable() { |
1728 |
if (!SwingUtilities.isEventDispatchThread()) { |
1729 |
SwingUtilities.invokeLater(this::resetPostProcessTable); |
1730 |
return;
|
1731 |
} |
1732 |
|
1733 |
this.tblSearchPostProcessResults.setModel(new DefaultTableModel()); |
1734 |
} |
1735 |
|
1736 |
private void doSearchPostProcess(FeatureStore store, FeatureQuery query, SearchPostProcessFactory factory, SearchParameters searchParams) { |
1737 |
if (factory.hasProcessParameters()) {
|
1738 |
DynObject parametersPostProcess = factory.createProcessParameters(store, query, searchParams); |
1739 |
JDynForm form = DynFormLocator.getDynFormManager().createJDynForm(parametersPostProcess); |
1740 |
form.setLayoutMode(JDynForm.USE_SEPARATORS); |
1741 |
|
1742 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1743 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
1744 |
|
1745 |
Dialog dialog = windowManager.createDialog(
|
1746 |
form.asJComponent(), |
1747 |
i18n.getTranslation("_Postprocess_parameters"),
|
1748 |
i18n.getTranslation( |
1749 |
"_Parameters_for_XpostprocessNameX_postprocess_on_XtableNameX",
|
1750 |
new String[]{ |
1751 |
factory.getName(), |
1752 |
this.store.getName()
|
1753 |
} |
1754 |
), |
1755 |
WindowManager_v2.BUTTONS_OK_CANCEL); |
1756 |
|
1757 |
ToolsSwingUtils.ensureRowsCols(dialog.asJComponent(), 20, 60, 30, 100); |
1758 |
dialog.addActionListener((ActionEvent e2) -> {
|
1759 |
if (dialog.getAction() == WindowManager_v2.BUTTON_OK) {
|
1760 |
form.getValues(parametersPostProcess); // actualiza el valor de lo los parametros con los valores introducidos por el usuario
|
1761 |
doExecuteSearchPostProcess(store, query, factory, parametersPostProcess); |
1762 |
this.postProcessParams = parametersPostProcess;
|
1763 |
} |
1764 |
}); |
1765 |
|
1766 |
dialog.show(WindowManager.MODE.DIALOG); |
1767 |
|
1768 |
} else {
|
1769 |
doExecuteSearchPostProcess(store, query, factory, null);
|
1770 |
} |
1771 |
} |
1772 |
|
1773 |
private void updateNumberElementsMsg(SimpleFeaturesTableModel model) { |
1774 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
1775 |
|
1776 |
if (model.hasErrors()) {
|
1777 |
this.taskStatusController.setTitle(i18n.getTranslation("_Errors_occurred_load_search_post_process")); |
1778 |
} else {
|
1779 |
this.taskStatusController.setTitle(String.format("%d " + i18n.getTranslation("_elements"), model.getRowCount())); |
1780 |
} |
1781 |
} |
1782 |
|
1783 |
@Override
|
1784 |
public boolean isVisible(Object component) { |
1785 |
if (this.filterOnlyMode) { |
1786 |
if (component instanceof GroupByAction) { |
1787 |
return false; |
1788 |
} |
1789 |
// if( component instanceof OrderByAction ) {
|
1790 |
// return false;
|
1791 |
// }
|
1792 |
// if( component instanceof CalculatedColumnsAction ) {
|
1793 |
// return false;
|
1794 |
// }
|
1795 |
} |
1796 |
return true; |
1797 |
} |
1798 |
|
1799 |
@Override
|
1800 |
public boolean isEnabled(Object component) { |
1801 |
if (component instanceof GroupByAction) { |
1802 |
DataStoreProviderFactory dataFactory = this.store.getProviderFactory();
|
1803 |
int allowGroupBy = ((FeatureStoreProviderFactory) dataFactory).allowGroupBy();
|
1804 |
if (allowGroupBy != DataType.YES) {
|
1805 |
return false; |
1806 |
} |
1807 |
} |
1808 |
return true; |
1809 |
} |
1810 |
|
1811 |
@Override
|
1812 |
public void setFilterOnlyMode(boolean filterOnlyMode) { |
1813 |
if (this.conditionPanels != null) { |
1814 |
throw new IllegalStateException("Cannot change filter-only-mode after invoking asJComponent."); |
1815 |
} |
1816 |
this.filterOnlyMode = filterOnlyMode;
|
1817 |
this.showActions = false; |
1818 |
} |
1819 |
|
1820 |
@Override
|
1821 |
public boolean isFilterOnlyMode() { |
1822 |
return this.filterOnlyMode; |
1823 |
} |
1824 |
|
1825 |
@Override
|
1826 |
public Feature getLastSelectedFeature() {
|
1827 |
return this.lastSelectedFeature; |
1828 |
} |
1829 |
|
1830 |
@Override
|
1831 |
public Object getProperty(String name) { |
1832 |
return this.propertiesHelper.getProperty(name); |
1833 |
} |
1834 |
|
1835 |
@Override
|
1836 |
public void setProperty(String name, Object value) { |
1837 |
this.propertiesHelper.setProperty(name, value);
|
1838 |
} |
1839 |
|
1840 |
@Override
|
1841 |
public Map<String, Object> getProperties() { |
1842 |
return this.propertiesHelper.getProperties(); |
1843 |
} |
1844 |
|
1845 |
} |