Statistics
| Revision:

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 44259 jjdelcerro
package org.gvsig.fmap.dal.swing.impl.searchpanel;
2
3 44351 jjdelcerro
import java.awt.BorderLayout;
4 44263 jjdelcerro
import java.awt.Cursor;
5
import java.awt.FlowLayout;
6 44259 jjdelcerro
import java.awt.event.ActionEvent;
7
import java.awt.event.ActionListener;
8 45100 jjdelcerro
import java.awt.event.ComponentAdapter;
9
import java.awt.event.ComponentEvent;
10 45192 jjdelcerro
import java.awt.event.KeyAdapter;
11
import java.awt.event.KeyEvent;
12 46571 fdiaz
import java.io.File;
13 44259 jjdelcerro
import java.net.URL;
14 46571 fdiaz
import java.nio.charset.Charset;
15 46517 fdiaz
import java.sql.SQLException;
16 44829 omartinez
import java.text.DateFormat;
17
import java.text.SimpleDateFormat;
18 44259 jjdelcerro
import java.util.ArrayList;
19 44829 omartinez
import java.util.Calendar;
20 44263 jjdelcerro
import java.util.Collection;
21 44707 jjdelcerro
import java.util.Collections;
22 44829 omartinez
import java.util.Date;
23 44275 jjdelcerro
import java.util.HashMap;
24 44259 jjdelcerro
import java.util.List;
25 44275 jjdelcerro
import java.util.Map;
26 45192 jjdelcerro
import java.util.Objects;
27 44351 jjdelcerro
import javax.swing.AbstractAction;
28 44263 jjdelcerro
import javax.swing.Action;
29 44351 jjdelcerro
import static javax.swing.Action.ACTION_COMMAND_KEY;
30
import static javax.swing.Action.NAME;
31 44275 jjdelcerro
import javax.swing.BorderFactory;
32 44259 jjdelcerro
import javax.swing.ImageIcon;
33 44263 jjdelcerro
import javax.swing.JButton;
34 44259 jjdelcerro
import javax.swing.JComponent;
35 46571 fdiaz
import static javax.swing.JFileChooser.FILES_ONLY;
36 45537 jolivas
import javax.swing.JMenuItem;
37 44764 jjdelcerro
import javax.swing.JOptionPane;
38 46571 fdiaz
import static javax.swing.JOptionPane.YES_OPTION;
39 45537 jolivas
import javax.swing.JPopupMenu;
40 45695 omartinez
import javax.swing.JTable;
41 45191 jjdelcerro
import javax.swing.ListSelectionModel;
42 44262 jjdelcerro
import javax.swing.SwingUtilities;
43 45537 jolivas
import javax.swing.event.ChangeEvent;
44 44259 jjdelcerro
import javax.swing.event.ListSelectionEvent;
45
import javax.swing.event.ListSelectionListener;
46 46571 fdiaz
import javax.swing.filechooser.FileFilter;
47 45100 jjdelcerro
import javax.swing.table.DefaultTableModel;
48 46051 omartinez
import javax.swing.table.TableCellRenderer;
49 44262 jjdelcerro
import javax.swing.table.TableModel;
50 44259 jjdelcerro
import org.apache.commons.io.FilenameUtils;
51 44262 jjdelcerro
import org.apache.commons.lang.mutable.MutableObject;
52 44351 jjdelcerro
import org.apache.commons.lang3.StringUtils;
53 45162 omartinez
import org.apache.commons.lang3.mutable.MutableLong;
54 46571 fdiaz
import org.apache.commons.lang3.tuple.ImmutablePair;
55 44351 jjdelcerro
import org.gvsig.configurableactions.ConfigurableActionsMamager;
56 44259 jjdelcerro
import org.gvsig.expressionevaluator.Expression;
57
import org.gvsig.expressionevaluator.ExpressionBuilder;
58
import org.gvsig.expressionevaluator.ExpressionUtils;
59 46571 fdiaz
import static org.gvsig.filedialogchooser.FileDialogChooser.SAVE_DIALOG;
60 44351 jjdelcerro
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 44281 jjdelcerro
import org.gvsig.fmap.dal.DataStore;
64 44855 jjdelcerro
import org.gvsig.fmap.dal.DataStoreProviderFactory;
65 44262 jjdelcerro
import org.gvsig.fmap.dal.complements.Search;
66 45247 omartinez
import org.gvsig.fmap.dal.exception.DataException;
67 44259 jjdelcerro
import org.gvsig.fmap.dal.feature.Feature;
68
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
69 44712 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureQuery;
70 44259 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureStore;
71 44712 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
72 44259 jjdelcerro
import org.gvsig.fmap.dal.feature.FeatureType;
73 44794 omartinez
import org.gvsig.fmap.dal.feature.paging.FacadeOfAFeaturePagingHelper;
74 44281 jjdelcerro
import org.gvsig.fmap.dal.swing.AbstractDALActionFactory.AbstractDALActionContext;
75
import org.gvsig.fmap.dal.swing.DALActionFactory;
76 44259 jjdelcerro
import org.gvsig.fmap.dal.swing.DALSwingLocator;
77 45537 jolivas
import org.gvsig.fmap.dal.swing.DataSwingManager;
78 44712 jjdelcerro
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryCalculatedColumnsPanel;
79
import org.gvsig.fmap.dal.swing.featurequery.FeatureQueryOrderPanel;
80 45425 jjdelcerro
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel;
81 46536 fdiaz
import org.gvsig.fmap.dal.swing.featuretype.FeatureAttributesSelectionPanel;
82 44712 jjdelcerro
import org.gvsig.fmap.dal.swing.impl.featurequery.DefaultFeatureQueryCalculatedColumnsPanel;
83 45537 jolivas
import org.gvsig.fmap.dal.swing.impl.featuretable.SimpleFeaturesTableModelImpl;
84 46571 fdiaz
import static org.gvsig.fmap.dal.swing.impl.searchpanel.ExportTSV.EXPORT_TO_TSV;
85 45537 jolivas
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcess;
86
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory;
87 46536 fdiaz
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 44829 omartinez
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters;
91 46536 fdiaz
import org.gvsig.tools.ToolsLocator;
92 45274 omartinez
import org.gvsig.tools.bookmarksandhistory.Bookmark;
93 44829 omartinez
import org.gvsig.tools.bookmarksandhistory.Bookmarks;
94
import org.gvsig.tools.bookmarksandhistory.History;
95 46536 fdiaz
import org.gvsig.tools.dataTypes.DataType;
96 45100 jjdelcerro
import org.gvsig.tools.dispose.Disposable;
97
import org.gvsig.tools.dispose.DisposeUtils;
98 45537 jolivas
import org.gvsig.tools.dynform.DynFormLocator;
99
import org.gvsig.tools.dynform.JDynForm;
100
import org.gvsig.tools.dynobject.DynObject;
101 46571 fdiaz
import org.gvsig.tools.folders.FoldersManager;
102
import org.gvsig.tools.future.FutureUtils;
103 46536 fdiaz
import org.gvsig.tools.i18n.I18nManager;
104 46238 jjdelcerro
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
105 46536 fdiaz
import org.gvsig.tools.swing.api.ActionListenerSupport;
106 45379 jjdelcerro
import org.gvsig.tools.swing.api.SupportIsEnable;
107
import org.gvsig.tools.swing.api.SupportIsVisible;
108 46536 fdiaz
import org.gvsig.tools.swing.api.ToolsSwingLocator;
109
import org.gvsig.tools.swing.api.ToolsSwingManager;
110 45705 jolivas
import org.gvsig.tools.swing.api.ToolsSwingUtils;
111 44829 omartinez
import org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue;
112
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_GETVALUE;
113 46536 fdiaz
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_SETNAME;
114 44829 omartinez
import static org.gvsig.tools.swing.api.bookmarkshistory.ActionEventWithCurrentValue.ID_SETVALUE;
115
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController;
116 46463 fdiaz
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController.BookmarkEvent;
117 44829 omartinez
import org.gvsig.tools.swing.api.bookmarkshistory.HistoryController;
118 46051 omartinez
import org.gvsig.tools.swing.api.task.TaskStatusController;
119 44764 jjdelcerro
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
120 46536 fdiaz
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 46051 omartinez
import org.gvsig.tools.task.SimpleTaskStatus;
125 46010 jjdelcerro
import org.gvsig.tools.util.PropertiesSupportHelper;
126 46536 fdiaz
import org.gvsig.tools.util.ToolsUtilLocator;
127
import org.slf4j.Logger;
128
import org.slf4j.LoggerFactory;
129 44259 jjdelcerro
130
/**
131
 *
132
 * @author jjdelcerro
133
 */
134 44707 jjdelcerro
@SuppressWarnings({"UseSpecificCatch"})
135 44259 jjdelcerro
public class DefaultSearchPanel
136 46063 omartinez
        extends DefaultSearchPanelView2
137
        implements FeatureStoreSearchPanel, SupportIsEnable, SupportIsVisible {
138 44259 jjdelcerro
139 46063 omartinez
        private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class);
140 46571 fdiaz
141
        private static final String TSV_EXTENSION="tsv";
142 44829 omartinez
143 46063 omartinez
        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 46485 fdiaz
        private boolean automaticallySearch;
150 46517 fdiaz
        private String lastErrorMessage;
151 46505 fdiaz
    private boolean initialized;
152 44707 jjdelcerro
153 46063 omartinez
        public static class UseLabelsYesAction extends AbstractAction {
154 44351 jjdelcerro
155 46063 omartinez
                @SuppressWarnings("OverridableMethodCallInConstructor")
156
                public UseLabelsYesAction() {
157
                        I18nManager i18n = ToolsLocator.getI18nManager();
158 44351 jjdelcerro
159 46063 omartinez
                        this.putValue(NAME, i18n.getTranslation("_Use_labels"));
160
                        this.putValue(ACTION_COMMAND_KEY, "UseLabelsYes");
161
                }
162 44351 jjdelcerro
163 46063 omartinez
                @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 44481 jjdelcerro
173 46063 omartinez
                @Override
174
                public void actionPerformed(ActionEvent ae) {
175 46485 fdiaz
                    DALSwingLocator.getDataSwingManager().setUseLabels(USE_LABELS_YES);
176 46063 omartinez
                }
177
        }
178 44829 omartinez
179 46063 omartinez
        public static class UseLabelsNoAction extends AbstractAction {
180 44351 jjdelcerro
181 46063 omartinez
                @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 44351 jjdelcerro
188 46063 omartinez
                @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 44829 omartinez
198 46063 omartinez
                @Override
199
                public void actionPerformed(ActionEvent ae) {
200 46485 fdiaz
                    DALSwingLocator.getDataSwingManager().setUseLabels(USE_LABELS_NO);
201 46063 omartinez
                }
202
        }
203 44829 omartinez
204 46063 omartinez
        public static class UseLabelsBothAction extends AbstractAction {
205 44351 jjdelcerro
206 46063 omartinez
                @SuppressWarnings("OverridableMethodCallInConstructor")
207
                public UseLabelsBothAction() {
208
                        I18nManager i18n = ToolsLocator.getI18nManager();
209 44351 jjdelcerro
210 46063 omartinez
                        this.putValue(NAME, i18n.getTranslation("_Use_labels_and_names"));
211
                        this.putValue(ACTION_COMMAND_KEY, "UseLabelsBoth");
212
                }
213 44351 jjdelcerro
214 46063 omartinez
                @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 44481 jjdelcerro
224 46063 omartinez
                @Override
225
                public void actionPerformed(ActionEvent ae) {
226 46485 fdiaz
                    DALSwingLocator.getDataSwingManager().setUseLabels(USE_LABELS_BOTH);
227 46063 omartinez
                }
228
        }
229 44829 omartinez
230 46063 omartinez
        public static class SelectColumnsAction extends AbstractAction {
231 44644 jjdelcerro
232 46063 omartinez
                @SuppressWarnings("OverridableMethodCallInConstructor")
233
                public SelectColumnsAction() {
234
                        I18nManager i18n = ToolsLocator.getI18nManager();
235 44644 jjdelcerro
236 46063 omartinez
                        this.putValue(NAME, i18n.getTranslation("_Select_columns_to_display"));
237
                        this.putValue(ACTION_COMMAND_KEY, "SelectColumns");
238
                }
239 44644 jjdelcerro
240 46063 omartinez
                @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 44644 jjdelcerro
250 46063 omartinez
                @Override
251
                public void actionPerformed(ActionEvent ae) {
252
                        DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
253
                        panel.doSelectResultColumnNames();
254
                }
255
        }
256 44829 omartinez
257 46063 omartinez
        public static class CalculatedColumnsAction extends AbstractAction {
258 44707 jjdelcerro
259 46063 omartinez
                @SuppressWarnings("OverridableMethodCallInConstructor")
260
                public CalculatedColumnsAction() {
261
                        I18nManager i18n = ToolsLocator.getI18nManager();
262 44707 jjdelcerro
263 46063 omartinez
                        this.putValue(NAME, i18n.getTranslation("_Calculated_columns"));
264
                        this.putValue(ACTION_COMMAND_KEY, "CalculatedColumns");
265
                }
266 44707 jjdelcerro
267 46063 omartinez
                @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 44707 jjdelcerro
277 46063 omartinez
                @Override
278
                public void actionPerformed(ActionEvent ae) {
279
                        DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
280
                        panel.doCalculatedColumns();
281
                }
282
        }
283 44829 omartinez
284 46063 omartinez
        public static class GroupByAction extends AbstractAction {
285 44707 jjdelcerro
286 46063 omartinez
                @SuppressWarnings("OverridableMethodCallInConstructor")
287
                public GroupByAction() {
288
                        I18nManager i18n = ToolsLocator.getI18nManager();
289 44707 jjdelcerro
290 46063 omartinez
                        this.putValue(NAME, i18n.getTranslation("_Group_by"));
291
                        this.putValue(ACTION_COMMAND_KEY, "GroupBy");
292
                }
293 44707 jjdelcerro
294 46063 omartinez
                @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 44829 omartinez
304 46063 omartinez
                @Override
305
                public void actionPerformed(ActionEvent ae) {
306
                        DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
307
                        panel.doGroupBy();
308
                }
309
        }
310 44829 omartinez
311 46063 omartinez
        public static class OrderByAction extends AbstractAction {
312 44707 jjdelcerro
313 46063 omartinez
                @SuppressWarnings("OverridableMethodCallInConstructor")
314
                public OrderByAction() {
315
                        I18nManager i18n = ToolsLocator.getI18nManager();
316 44712 jjdelcerro
317 46063 omartinez
                        this.putValue(NAME, i18n.getTranslation("_Order_by"));
318
                        this.putValue(ACTION_COMMAND_KEY, "SelectOrderBy");
319
                }
320 44712 jjdelcerro
321 46063 omartinez
                @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 44712 jjdelcerro
331 46063 omartinez
                @Override
332
                public void actionPerformed(ActionEvent ae) {
333
                        DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
334
                        panel.doOrderBy();
335
                }
336
        }
337 44829 omartinez
338 46536 fdiaz
        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 46063 omartinez
        private class TablePopupMenu extends JPopupMenu {
366 44829 omartinez
367 46063 omartinez
                public final JTable table;
368 44259 jjdelcerro
369 46063 omartinez
                @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 46571 fdiaz
                        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 46063 omartinez
                }
386
        }
387 44281 jjdelcerro
388 46063 omartinez
        private class ActionButtons {
389 44829 omartinez
390 46063 omartinez
                private final DALActionFactory factory;
391
                private final Action action;
392
                private final JButton button;
393 44829 omartinez
394 46063 omartinez
                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 45537 jolivas
//                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 46063 omartinez
                        }
426
                }
427 44281 jjdelcerro
428 46063 omartinez
                @Override
429
                public JComponent getActionButton(String actionName) {
430
                        return this.panel.getActionButton(actionName);
431
                }
432 44829 omartinez
433 46063 omartinez
                @Override
434
                public int getSelectedsCount() {
435
                        return this.panel.getSelectedFeatureCount();
436
                }
437 44829 omartinez
438 46063 omartinez
                @Override
439
                public Expression getFilterForSelecteds() {
440
                        return this.panel.getFilterForSelectedFeature();
441
                }
442 44829 omartinez
443 46063 omartinez
                @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 45537 jolivas
//                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 46063 omartinez
                        }
459
                }
460
        }
461 44829 omartinez
462 45537 jolivas
//    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 46063 omartinez
        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 45537 jolivas
516 46063 omartinez
        private List<SearchConditionPanel> conditionPanels;
517 44259 jjdelcerro
518 46063 omartinez
        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 44829 omartinez
525 46063 omartinez
        private String currentPostProcess;
526 44829 omartinez
527 46063 omartinez
        private DynObject postProcessParams;
528
        private FeatureStore postProcessStore;
529
        private FeatureQuery postProcessQuery;
530
        private SimpleFeaturesTableModel resultModel;
531
        private SimpleFeaturesTableModel resultPostProcessModel;
532 45537 jolivas
533 46063 omartinez
        private boolean processing;
534
        private JComponent configurableActions;
535 45537 jolivas
536 46063 omartinez
        @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 46485 fdiaz
                this.automaticallySearch = true;
558 45537 jolivas
559 46063 omartinez
                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 46505 fdiaz
                this.initComponents0();
573
                this.initialized = false;
574 46063 omartinez
        }
575 44829 omartinez
576 46063 omartinez
        @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 44259 jjdelcerro
587 46063 omartinez
        @Override
588
        public JComponent asJComponent() {
589 46505 fdiaz
                if (!this.initialized) { //this.conditionPanels == null) {
590
                        this.initComponents1();
591 46063 omartinez
                }
592
                return this;
593
        }
594 45100 jjdelcerro
595 46063 omartinez
        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 44259 jjdelcerro
621 46063 omartinez
        @Override
622
        public void addActionListener(ActionListener listener) {
623
                this.acctionListeners.addActionListener(listener);
624
        }
625 44263 jjdelcerro
626 46063 omartinez
        @Override
627
        public ActionListener[] getActionListeners() {
628
                return this.acctionListeners.getActionListeners();
629
        }
630 44259 jjdelcerro
631 46063 omartinez
        @Override
632
        public void removeActionListener(ActionListener listener) {
633
                this.acctionListeners.removeActionListener(listener);
634
        }
635 44259 jjdelcerro
636 46063 omartinez
        @Override
637
        public void removeAllActionListener() {
638
                this.acctionListeners.removeAllActionListener();
639
        }
640 44259 jjdelcerro
641 46063 omartinez
        @Override
642
        public void fireActionEvent(ActionEvent event) {
643
                this.acctionListeners.fireActionEvent(event);
644
        }
645 44259 jjdelcerro
646 46063 omartinez
        @Override
647
        public boolean hasActionListeners() {
648
                return this.acctionListeners.hasActionListeners();
649
        }
650 44259 jjdelcerro
651 46505 fdiaz
        private void initComponents0() {
652 46063 omartinez
                this.conditionPanels = new ArrayList<>();
653 46505 fdiaz
                this.taskStatusController = ToolsSwingLocator.getTaskStatusSwingManager().createTaskStatusController(
654
                        this.lblStatusTitle,
655
                        this.lblMsg,
656
                        this.pgbStatus);
657
        }
658 44259 jjdelcerro
659 46505 fdiaz
        private void initComponents1() {
660
661 46063 omartinez
                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 44707 jjdelcerro
672 46063 omartinez
                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 46062 omartinez
                this.pgbStatus.setVisible(false);
678 44829 omartinez
679 46063 omartinez
                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 44829 omartinez
713 46063 omartinez
                SearchConditionPanelAdvanced advancedPanel = new SearchConditionPanelAdvanced(
714
                        this.store,
715
                        txtAdvancedExpression,
716
                        btnAdvancedExpression,
717
                        btnAdvancedExpressionHistory,
718
                        btnAdvancedExpressionBookmarks
719
                );
720
                this.conditionPanels.add(advancedPanel);
721 44259 jjdelcerro
722 46063 omartinez
                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 44829 omartinez
736 46063 omartinez
                this.btnSearch.addActionListener((ActionEvent e) -> {
737
                        this.tabResults.setEnabledAt(1, false);
738
                        search();
739
                });
740 44822 jjdelcerro
741 46063 omartinez
                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 45794 jjdelcerro
//        this.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
761 46063 omartinez
                ToolsSwingUtils.ensureRowsCols(this, 20, 100, 30, 120);
762 44259 jjdelcerro
763 46063 omartinez
                this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(this.bookmarks, btnBookmarks);
764
                this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(this.history, btnHistory);
765 44829 omartinez
766 46063 omartinez
                this.historyController.setFilter(null);
767 44829 omartinez
768 46463 fdiaz
                this.historyController.addActionListener((ActionEvent e) -> {
769 46063 omartinez
                        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 45537 jolivas
776 46063 omartinez
                                case ID_SETVALUE:
777
                                        if (b.getCurrentValue() == null) {
778
                                                return;
779
                                        }
780 46485 fdiaz
                                        putParametersAndSearch(b.getCurrentValue());
781 46463 fdiaz
                                        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 46063 omartinez
                                                return;
795
                                        }
796 46463 fdiaz
                                        b.getBookmark().used();
797 46536 fdiaz
                                        b.getCurrentValue().setName(b.getBookmark().getName());
798 46485 fdiaz
                                        putParametersAndSearch(b.getCurrentValue());
799 46063 omartinez
                                        break;
800 46536 fdiaz
                                case ID_SETNAME:
801
                                        if (b.getCurrentValue() == null) {
802
                                                return;
803
                                        }
804
                                        b.getCurrentValue().setName(b.getBookmark().getName());
805
                                        break;
806 46063 omartinez
                        }
807 46463 fdiaz
                });
808 46063 omartinez
                this.addComponentListener(new ComponentAdapter() {
809
                        @Override
810
                        public void componentHidden(ComponentEvent e) {
811
                                dispose();
812
                        }
813
                });
814 45537 jolivas
815 46063 omartinez
                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 45537 jolivas
823 46063 omartinez
                this.tabResults.setEnabledAt(1, false);
824 44259 jjdelcerro
825 46063 omartinez
                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 44829 omartinez
835 46063 omartinez
                this.tblResults.setComponentPopupMenu(new TablePopupMenu(this.tblResults));
836
                this.tblSearchPostProcessResults.setComponentPopupMenu(new TablePopupMenu(this.tblSearchPostProcessResults));
837 44829 omartinez
838 46063 omartinez
                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 46463 fdiaz
851 46505 fdiaz
                this.initialized = true;
852
853 46463 fdiaz
                //this.tblResults.add
854 46485 fdiaz
                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 46463 fdiaz
                    clear();
865 46485 fdiaz
866 46463 fdiaz
                }
867 46063 omartinez
        }
868 46463 fdiaz
869 46485 fdiaz
    private void putParametersAndSearch(DefaultSearchParameters searchParams) {
870 46463 fdiaz
        DefaultSearchParameters params;
871
        try {
872
            params = searchParams.getCopy();
873 46505 fdiaz
            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 46463 fdiaz
        } 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 45247 omartinez
904 46463 fdiaz
    }
905
906 46063 omartinez
        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 44262 jjdelcerro
927 46063 omartinez
        @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 44259 jjdelcerro
936 46063 omartinez
        @Override
937
        public void setEnabled(boolean enabled) {
938
                if (!SwingUtilities.isEventDispatchThread()) {
939
                        SwingUtilities.invokeLater(() -> {
940
                                setEnabled(enabled);
941
                        });
942
                        return;
943
                }
944
945 46505 fdiaz
                if (!this.initialized) { //this.conditionPanels == null) {
946
                        this.initComponents1();
947 46063 omartinez
                }
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 46505 fdiaz
                if (!this.initialized) { //this.conditionPanels == null) {
965 46063 omartinez
                        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 46482 jjdelcerro
        public int search() {
1006 46063 omartinez
                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 46482 jjdelcerro
                        return STATUS_NOT_VALID;
1015 46063 omartinez
                }
1016
                lblMsg.setText(ToolsLocator.getI18nManager().getTranslation("_Searching") + "...");
1017
                setEnabled(false);
1018
                Thread th = new Thread(() -> {
1019
                        try {
1020 46062 omartinez
                                SearchParameters searchParams;
1021
                                try {
1022
                                        searchParams = this.fetch(this.parameters.getCopy()); // esto lo actualiza a la ultima // decidir si se devuelve clonado
1023 45537 jolivas
1024 46062 omartinez
                                        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 46063 omartinez
                });
1044
                th.start();
1045 46482 jjdelcerro
                return STATUS_OK;
1046 46063 omartinez
        }
1047
1048 46485 fdiaz
        @Override
1049 46482 jjdelcerro
        public int search(SearchParameters searchParams) {
1050 46485 fdiaz
            ((DefaultSearchParameters)searchParams).fix(this.getFeatureType());
1051
            return doSearch(searchParams);
1052 46482 jjdelcerro
        }
1053
1054
        private int doSearch(SearchParameters searchParams) {
1055 46063 omartinez
                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 46517 fdiaz
                List<Feature> features = null;
1063 46063 omartinez
                try {
1064
                        status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Processing_search"));
1065
                        SwingUtilities.invokeLater(() -> {
1066 46505 fdiaz
                            if(this.initialized){
1067 46063 omartinez
                                this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1068 46505 fdiaz
                            }
1069 46063 omartinez
                        });
1070
                        FeatureQuery myQuery;
1071 45280 omartinez
//                myQuery = this.getQuery().getCopy();
1072 46063 omartinez
                        List<String> resultColumnNames = searchParams.getResultColumnNames();
1073
                        myQuery = searchParams.getQuery().getCopy();
1074 46536 fdiaz
                        if(searchParams.getIgnoreAggregateFunctions()){
1075
                            myQuery.getAggregateFunctions().clear();
1076
                        }
1077 46063 omartinez
                        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 46517 fdiaz
                        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 46485 fdiaz
                        resultModel = (SimpleFeaturesTableModel) model.getValue();
1093 46063 omartinez
                        SwingUtilities.invokeLater(() -> {
1094 46505 fdiaz
                            if(this.initialized){
1095 46063 omartinez
                                I18nManager i18n = ToolsLocator.getI18nManager();
1096
                                try {
1097 46505 fdiaz
                                        this.tabResults.setSelectedIndex(0);
1098 46063 omartinez
                                        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 46505 fdiaz
                            }
1121 46063 omartinez
                        });
1122 46517 fdiaz
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 46063 omartinez
                }
1135 46482 jjdelcerro
                return STATUS_OK;
1136 46063 omartinez
        }
1137
1138 46482 jjdelcerro
        @Override
1139
        public SimpleFeaturesTableModel getResultsTableModel() {
1140
            return this.resultModel;
1141
        }
1142
1143 46063 omartinez
        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 46051 omartinez
//                renderers.put(attr.getName(), new ColorRangeRenderer(attr, 20, 50));
1149 46063 omartinez
                        }
1150
                }
1151
                return renderers;
1152
        }
1153 45280 omartinez
1154 46063 omartinez
        private void resetTable() {
1155
                if (!SwingUtilities.isEventDispatchThread()) {
1156 46505 fdiaz
                        SwingUtilities.invokeLater(() -> {
1157
                            if(this.initialized){
1158
                                resetTable();
1159
                            }
1160
                        });
1161 46063 omartinez
                        return;
1162
                }
1163
                List<String> resultColumnNames = null;
1164
                try {
1165
                        resultColumnNames = this.parameters.getResultColumnNames();
1166
                } catch (Exception ex) {
1167 44259 jjdelcerro
1168 46063 omartinez
                }
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 45996 omartinez
//        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 46063 omartinez
        }
1197 44829 omartinez
1198 46063 omartinez
        @Override
1199
        public boolean setFilter(Expression filter) {
1200
                try {
1201 46505 fdiaz
                        if (!this.initialized) { //this.conditionPanels == null) {
1202
                                this.initComponents1();
1203 46063 omartinez
                        }
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 44829 omartinez
1218 44794 omartinez
//            SimpleFeaturesTableModel model = new SimpleFeaturesTableModel(this.getStore());
1219
//            tblResults.setModel(model);
1220
//            lblMsg.setText("");
1221 46063 omartinez
                        return true;
1222
                } catch (Exception ex) {
1223
                        LOGGER.warn("Can't set current search", ex);
1224
                        return false;
1225
                }
1226
        }
1227 44707 jjdelcerro
1228 46063 omartinez
        @Override
1229
        public List<SearchConditionPanel> getConditionPanels() {
1230
                return Collections.unmodifiableList(this.conditionPanels);
1231
        }
1232 44712 jjdelcerro
1233 46063 omartinez
        @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 44829 omartinez
1246 46063 omartinez
        @Override
1247
        public Expression getFilterForSelectedFeature() {
1248 46505 fdiaz
                if (!this.initialized) { //this.conditionPanels == null) {
1249 46063 omartinez
                        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 45537 jolivas
1260 46063 omartinez
                                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 44829 omartinez
1288 46063 omartinez
                                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 45537 jolivas
1306 46063 omartinez
        }
1307 45537 jolivas
1308 46063 omartinez
        @Override
1309
        public FeatureStore getStore() {
1310
                return store;
1311
        }
1312 44644 jjdelcerro
1313 46063 omartinez
        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 46571 fdiaz
        }
1333 46063 omartinez
1334 46571 fdiaz
    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 46063 omartinez
        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 46066 omartinez
                                this.updateComponentState();
1453 46062 omartinez
                                status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Copying_rows_to_clipboard"));
1454 46063 omartinez
                                SwingUtilities.invokeLater(() -> {
1455
                                        this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1456
                                });
1457 44829 omartinez
1458 46063 omartinez
                                SimpleFeaturesTableModel model = null;
1459
                                if (table.getModel() instanceof SimpleFeaturesTableModel) {
1460
                                        model = (SimpleFeaturesTableModel) table.getModel();
1461
                                }
1462 45695 omartinez
1463 46063 omartinez
                                String LINE_BREAK = System.lineSeparator();
1464
                                String CELL_BREAK = "\t";
1465
                                char DELIMITER = '"';
1466 45695 omartinez
1467 46063 omartinez
                                int[] selection = table.getSelectedRows();
1468
                                for (int i = 0; i < selection.length; i++) {
1469
                                        selection[i] = table.convertRowIndexToModel(selection[i]);
1470
                                }
1471 45695 omartinez
1472 46063 omartinez
                                int numCols = table.getColumnCount();
1473
                                StringBuilder excelStr = new StringBuilder();
1474
                                boolean valueIsNumeric;
1475 46051 omartinez
1476 46063 omartinez
                                for (int j = 0; j < numCols; j++) {
1477 46051 omartinez
1478 46063 omartinez
                                        excelStr.append(DELIMITER);
1479
                                        excelStr.append(escape(table.getColumnName(j), LINE_BREAK, CELL_BREAK));
1480
                                        excelStr.append(DELIMITER);
1481 46051 omartinez
1482 46063 omartinez
                                        if (j < numCols - 1) {
1483
                                                excelStr.append(CELL_BREAK);
1484
                                        }
1485
                                }
1486 46051 omartinez
1487 46063 omartinez
                                //from( 0, selection.length)
1488
                                status.setRangeOfValues(0, selection.length);
1489
                                excelStr.append(LINE_BREAK);
1490
                                for (int i : selection) {
1491 46066 omartinez
                                        status.incrementCurrentValue();
1492 46063 omartinez
                                        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 46051 omartinez
1518 46063 omartinez
                                                }
1519
                                                excelStr.append(valueStr);
1520 46062 omartinez
1521 46063 omartinez
                                                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 46051 omartinez
1532 46063 omartinez
                                doPostCopyRows(status, toStr);
1533 46066 omartinez
                                SwingUtilities.invokeLater(() -> {
1534
                                        status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Copy_ended"));
1535
                                        status.terminate();
1536
                                });
1537 46051 omartinez
1538 46063 omartinez
                        } 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 45695 omartinez
1553 46063 omartinez
        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 46051 omartinez
//        StringSelection sel = new StringSelection(toStr);
1562
//        Clipboard CLIPBOARD = Toolkit.getDefaultToolkit().getSystemClipboard();
1563
//        CLIPBOARD.setContents(sel, null);
1564 46063 omartinez
        }
1565 45695 omartinez
1566 46063 omartinez
        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 44259 jjdelcerro
1573 46063 omartinez
        @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 44829 omartinez
1587 46063 omartinez
        @Override
1588
        public int getSelectedFeatureCount() {
1589 46505 fdiaz
                if (!this.initialized) { //this.conditionPanels == null) {
1590 46063 omartinez
                        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 44275 jjdelcerro
1598 46063 omartinez
        @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 44829 omartinez
1607 46063 omartinez
        @Override
1608
        public void setShowActions(boolean showActions) {
1609
                this.showActions = showActions;
1610
        }
1611 44351 jjdelcerro
1612 46063 omartinez
        @Override
1613
        public boolean isShowActions() {
1614
                return this.showActions;
1615
        }
1616 44712 jjdelcerro
1617 46063 omartinez
        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 44707 jjdelcerro
1638 46063 omartinez
        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 44712 jjdelcerro
1653 46063 omartinez
                WindowManager_v2 winmanager = (WindowManager_v2) ToolsSwingLocator.getWindowManager();
1654
                I18nManager i18n = ToolsLocator.getI18nManager();
1655 46536 fdiaz
                final DefaultSearchGroupByPanel panelGroupBy = new DefaultSearchGroupByPanel();
1656 46063 omartinez
                panelGroupBy.setStore(this.store);
1657 46536 fdiaz
                panelGroupBy.put(this.parameters);
1658 46063 omartinez
                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 46536 fdiaz
                                panelGroupBy.fetch(this.parameters);
1667 46063 omartinez
                                search();
1668
                        }
1669
                });
1670
                dialog.show(WindowManager.MODE.DIALOG);
1671
        }
1672 44829 omartinez
1673 46063 omartinez
        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 46536 fdiaz
                if(this.parameters.getQuery() != null){
1681
                    panelSelectColumns.setExtraColumns(this.parameters.getQuery().getExtraColumns().getColumns());
1682
                }
1683 46063 omartinez
                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 45280 omartinez
//        this.resetTable();
1711 44829 omartinez
1712 46063 omartinez
        }
1713 44707 jjdelcerro
1714 46063 omartinez
        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 44712 jjdelcerro
1737 46063 omartinez
        @Override
1738
        public SearchParameters fetch(SearchParameters outParams) {
1739 46536 fdiaz
            if(!initialized){
1740
                this.initComponents1();
1741
            }
1742 46063 omartinez
                // 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 44829 omartinez
1751 46063 omartinez
                // 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 44829 omartinez
1768 46063 omartinez
                if (outParams == null) {
1769
                        return this.parameters.getCopy();
1770
                }
1771
                outParams.copyFrom(this.parameters.getCopy());
1772
                return outParams;
1773
        }
1774 44829 omartinez
1775 46063 omartinez
        public static void selfRegister() {
1776 46238 jjdelcerro
                IconTheme theme;
1777
                try {
1778
                   theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
1779
                } catch(ReferenceNotRegisteredException ex) {
1780
                    return;
1781
                }
1782 46063 omartinez
                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 44712 jjdelcerro
1793 46063 omartinez
                };
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 45379 jjdelcerro
1799 46063 omartinez
                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 46536 fdiaz
                cfgActionsManager.addConfigurableAction(CONFIGURABLE_PANEL_ID, new PropertiesAction());
1808 46063 omartinez
        }
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 45537 jolivas
//            item.addActionListener(new SearchPostProcessListener(this.store, myQuery, manager.getSearchPostProcess(factory)));
1821 46063 omartinez
                        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 45537 jolivas
1829 46063 omartinez
        private void doExecuteSearchPostProcess(
1830
                FeatureStore input,
1831
                FeatureQuery query,
1832
                SearchPostProcessFactory factory,
1833
                DynObject parameters
1834
        ) {
1835 46062 omartinez
                Cursor savedCursor = this.getCursor();
1836
                SimpleTaskStatus status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("");
1837 46063 omartinez
                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 45537 jolivas
1849 46063 omartinez
                                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 46062 omartinez
                                if (output != null) {
1855
                                        this.postProcessStore = output.getStore();
1856
                                        this.postProcessQuery = output.getQuery();
1857
1858
                                        doLoadSearchPostProccessResults(this.postProcessStore);
1859
1860
                                }
1861 46063 omartinez
                                this.currentPostProcess = factory.getName();
1862 46062 omartinez
                                status.terminate();
1863 46063 omartinez
1864
                        } catch (Exception ex) {
1865
                                LOGGER.warn("SearchPostProcess not able to be executed.", ex);
1866
                                resetPostProcessTable();
1867 46062 omartinez
                                status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Error_in_post_process_operation"));
1868
                                status.message("");
1869
                                status.abort();
1870 46063 omartinez
                        } finally {
1871
                                SwingUtilities.invokeLater(() -> {
1872
                                        this.setCursor(savedCursor);
1873
                                });
1874
                                this.processing = false;
1875
                                this.updateComponentState();
1876
                        }
1877
                }, "ExecuteSearchPostProcess");
1878 45537 jolivas
1879 46063 omartinez
                task.start();
1880 45537 jolivas
1881 46063 omartinez
        }
1882 45537 jolivas
1883 46063 omartinez
        private void doLoadSearchPostProccessResults(FeatureStore input) {
1884 46062 omartinez
                if (!SwingUtilities.isEventDispatchThread()) {
1885 46063 omartinez
                        SwingUtilities.invokeLater(() -> {
1886 46062 omartinez
                                doLoadSearchPostProccessResults(input);
1887
                        });
1888 46063 omartinez
                        return;
1889
                }
1890 45537 jolivas
1891 46063 omartinez
                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 45537 jolivas
1907 46063 omartinez
                        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 45537 jolivas
//            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 46063 omartinez
                } 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 45537 jolivas
1926 46063 omartinez
        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 45537 jolivas
1935 46063 omartinez
        private void resetPostProcessTable() {
1936
                if (!SwingUtilities.isEventDispatchThread()) {
1937
                        SwingUtilities.invokeLater(this::resetPostProcessTable);
1938
                        return;
1939
                }
1940 45537 jolivas
1941 46063 omartinez
                this.tblSearchPostProcessResults.setModel(new DefaultTableModel());
1942
        }
1943 45537 jolivas
1944 46063 omartinez
        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 45537 jolivas
1950 46063 omartinez
                        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 45794 jjdelcerro
//            if( component instanceof OrderByAction ) {
1998
//                return false;
1999
//            }
2000 46010 jjdelcerro
//            if( component instanceof CalculatedColumnsAction ) {
2001
//                return false;
2002
//            }
2003 46063 omartinez
                }
2004
                return true;
2005
        }
2006 45537 jolivas
2007 46063 omartinez
        @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 45379 jjdelcerro
2019 46063 omartinez
        @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 45379 jjdelcerro
2028 46063 omartinez
        @Override
2029
        public boolean isFilterOnlyMode() {
2030
                return this.filterOnlyMode;
2031
        }
2032 45379 jjdelcerro
2033 46063 omartinez
        @Override
2034
        public Feature getLastSelectedFeature() {
2035
                return this.lastSelectedFeature;
2036
        }
2037 45794 jjdelcerro
2038 46063 omartinez
        @Override
2039
        public Object getProperty(String name) {
2040
                return this.propertiesHelper.getProperty(name);
2041
        }
2042 46010 jjdelcerro
2043 46063 omartinez
        @Override
2044
        public void setProperty(String name, Object value) {
2045
                this.propertiesHelper.setProperty(name, value);
2046
        }
2047 46010 jjdelcerro
2048 46063 omartinez
        @Override
2049
        public Map<String, Object> getProperties() {
2050
                return this.propertiesHelper.getProperties();
2051
        }
2052 46010 jjdelcerro
2053 46485 fdiaz
    public void setAutomaticallySearch(boolean automaticallySearch){
2054
        this.automaticallySearch = automaticallySearch;
2055
    }
2056
2057
    public boolean isAutomaticallySearch(){
2058
        return automaticallySearch;
2059
    }
2060 46517 fdiaz
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 46536 fdiaz
    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 44263 jjdelcerro
}