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