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