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