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