Revision 46063

View differences:

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
123 123
 */
124 124
@SuppressWarnings({"UseSpecificCatch"})
125 125
public class DefaultSearchPanel
126
        extends DefaultSearchPanelView2
127
        implements FeatureStoreSearchPanel, SupportIsEnable, SupportIsVisible {
126
	extends DefaultSearchPanelView2
127
	implements FeatureStoreSearchPanel, SupportIsEnable, SupportIsVisible {
128 128

  
129
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class);
129
	private static final Logger LOGGER = LoggerFactory.getLogger(DefaultSearchPanel.class);
130 130

  
131
    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;
131
	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 138

  
139
    public static class UseLabelsYesAction extends AbstractAction {
139
	public static class UseLabelsYesAction extends AbstractAction {
140 140

  
141
        @SuppressWarnings("OverridableMethodCallInConstructor")
142
        public UseLabelsYesAction() {
143
            I18nManager i18n = ToolsLocator.getI18nManager();
141
		@SuppressWarnings("OverridableMethodCallInConstructor")
142
		public UseLabelsYesAction() {
143
			I18nManager i18n = ToolsLocator.getI18nManager();
144 144

  
145
            this.putValue(NAME, i18n.getTranslation("_Use_labels"));
146
            this.putValue(ACTION_COMMAND_KEY, "UseLabelsYes");
147
        }
145
			this.putValue(NAME, i18n.getTranslation("_Use_labels"));
146
			this.putValue(ACTION_COMMAND_KEY, "UseLabelsYes");
147
		}
148 148

  
149
        @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
        }
149
		@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 158

  
159
        @Override
160
        public void actionPerformed(ActionEvent ae) {
161
            DefaultSearchPanel.useLabels = USE_LABELS_YES;
162
        }
163
    }
159
		@Override
160
		public void actionPerformed(ActionEvent ae) {
161
			DefaultSearchPanel.useLabels = USE_LABELS_YES;
162
		}
163
	}
164 164

  
165
    public static class UseLabelsNoAction extends AbstractAction {
165
	public static class UseLabelsNoAction extends AbstractAction {
166 166

  
167
        @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
        }
167
		@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 173

  
174
        @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
        }
174
		@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 183

  
184
        @Override
185
        public void actionPerformed(ActionEvent ae) {
186
            DefaultSearchPanel.useLabels = USE_LABELS_NO;
187
        }
188
    }
184
		@Override
185
		public void actionPerformed(ActionEvent ae) {
186
			DefaultSearchPanel.useLabels = USE_LABELS_NO;
187
		}
188
	}
189 189

  
190
    public static class UseLabelsBothAction extends AbstractAction {
190
	public static class UseLabelsBothAction extends AbstractAction {
191 191

  
192
        @SuppressWarnings("OverridableMethodCallInConstructor")
193
        public UseLabelsBothAction() {
194
            I18nManager i18n = ToolsLocator.getI18nManager();
192
		@SuppressWarnings("OverridableMethodCallInConstructor")
193
		public UseLabelsBothAction() {
194
			I18nManager i18n = ToolsLocator.getI18nManager();
195 195

  
196
            this.putValue(NAME, i18n.getTranslation("_Use_labels_and_names"));
197
            this.putValue(ACTION_COMMAND_KEY, "UseLabelsBoth");
198
        }
196
			this.putValue(NAME, i18n.getTranslation("_Use_labels_and_names"));
197
			this.putValue(ACTION_COMMAND_KEY, "UseLabelsBoth");
198
		}
199 199

  
200
        @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
        }
200
		@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 209

  
210
        @Override
211
        public void actionPerformed(ActionEvent ae) {
212
            DefaultSearchPanel.useLabels = USE_LABELS_BOTH;
213
        }
214
    }
210
		@Override
211
		public void actionPerformed(ActionEvent ae) {
212
			DefaultSearchPanel.useLabels = USE_LABELS_BOTH;
213
		}
214
	}
215 215

  
216
    public static class SelectColumnsAction extends AbstractAction {
216
	public static class SelectColumnsAction extends AbstractAction {
217 217

  
218
        @SuppressWarnings("OverridableMethodCallInConstructor")
219
        public SelectColumnsAction() {
220
            I18nManager i18n = ToolsLocator.getI18nManager();
218
		@SuppressWarnings("OverridableMethodCallInConstructor")
219
		public SelectColumnsAction() {
220
			I18nManager i18n = ToolsLocator.getI18nManager();
221 221

  
222
            this.putValue(NAME, i18n.getTranslation("_Select_columns_to_display"));
223
            this.putValue(ACTION_COMMAND_KEY, "SelectColumns");
224
        }
222
			this.putValue(NAME, i18n.getTranslation("_Select_columns_to_display"));
223
			this.putValue(ACTION_COMMAND_KEY, "SelectColumns");
224
		}
225 225

  
226
        @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
        }
226
		@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 235

  
236
        @Override
237
        public void actionPerformed(ActionEvent ae) {
238
            DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
239
            panel.doSelectResultColumnNames();
240
        }
241
    }
236
		@Override
237
		public void actionPerformed(ActionEvent ae) {
238
			DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
239
			panel.doSelectResultColumnNames();
240
		}
241
	}
242 242

  
243
    public static class CalculatedColumnsAction extends AbstractAction {
243
	public static class CalculatedColumnsAction extends AbstractAction {
244 244

  
245
        @SuppressWarnings("OverridableMethodCallInConstructor")
246
        public CalculatedColumnsAction() {
247
            I18nManager i18n = ToolsLocator.getI18nManager();
245
		@SuppressWarnings("OverridableMethodCallInConstructor")
246
		public CalculatedColumnsAction() {
247
			I18nManager i18n = ToolsLocator.getI18nManager();
248 248

  
249
            this.putValue(NAME, i18n.getTranslation("_Calculated_columns"));
250
            this.putValue(ACTION_COMMAND_KEY, "CalculatedColumns");
251
        }
249
			this.putValue(NAME, i18n.getTranslation("_Calculated_columns"));
250
			this.putValue(ACTION_COMMAND_KEY, "CalculatedColumns");
251
		}
252 252

  
253
        @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
        }
253
		@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 262

  
263
        @Override
264
        public void actionPerformed(ActionEvent ae) {
265
            DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
266
            panel.doCalculatedColumns();
267
        }
268
    }
263
		@Override
264
		public void actionPerformed(ActionEvent ae) {
265
			DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
266
			panel.doCalculatedColumns();
267
		}
268
	}
269 269

  
270
    public static class GroupByAction extends AbstractAction {
270
	public static class GroupByAction extends AbstractAction {
271 271

  
272
        @SuppressWarnings("OverridableMethodCallInConstructor")
273
        public GroupByAction() {
274
            I18nManager i18n = ToolsLocator.getI18nManager();
272
		@SuppressWarnings("OverridableMethodCallInConstructor")
273
		public GroupByAction() {
274
			I18nManager i18n = ToolsLocator.getI18nManager();
275 275

  
276
            this.putValue(NAME, i18n.getTranslation("_Group_by"));
277
            this.putValue(ACTION_COMMAND_KEY, "GroupBy");
278
        }
276
			this.putValue(NAME, i18n.getTranslation("_Group_by"));
277
			this.putValue(ACTION_COMMAND_KEY, "GroupBy");
278
		}
279 279

  
280
        @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
        }
280
		@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 289

  
290
        @Override
291
        public void actionPerformed(ActionEvent ae) {
292
            DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
293
            panel.doGroupBy();
294
        }
295
    }
290
		@Override
291
		public void actionPerformed(ActionEvent ae) {
292
			DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
293
			panel.doGroupBy();
294
		}
295
	}
296 296

  
297
    public static class OrderByAction extends AbstractAction {
297
	public static class OrderByAction extends AbstractAction {
298 298

  
299
        @SuppressWarnings("OverridableMethodCallInConstructor")
300
        public OrderByAction() {
301
            I18nManager i18n = ToolsLocator.getI18nManager();
299
		@SuppressWarnings("OverridableMethodCallInConstructor")
300
		public OrderByAction() {
301
			I18nManager i18n = ToolsLocator.getI18nManager();
302 302

  
303
            this.putValue(NAME, i18n.getTranslation("_Order_by"));
304
            this.putValue(ACTION_COMMAND_KEY, "SelectOrderBy");
305
        }
303
			this.putValue(NAME, i18n.getTranslation("_Order_by"));
304
			this.putValue(ACTION_COMMAND_KEY, "SelectOrderBy");
305
		}
306 306

  
307
        @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
        }
307
		@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 316

  
317
        @Override
318
        public void actionPerformed(ActionEvent ae) {
319
            DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
320
            panel.doOrderBy();
321
        }
322
    }
323
    
324
    private class TablePopupMenu extends JPopupMenu {
325
            public final JTable table;
326
            @SuppressWarnings("OverridableMethodCallInConstructor")
327
            public TablePopupMenu(JTable inputTable) {
328
                this.table = inputTable;
329
                I18nManager i18n = ToolsLocator.getI18nManager();
330
                JMenuItem copyRowsActionMenu = new JMenuItem(i18n.getTranslation("_Copy_rows"));
331
                copyRowsActionMenu.addActionListener((ActionEvent e) -> {
332
                    doCopyRows(table);
333
                });
334
                this.add(copyRowsActionMenu);
335
            }
336
        }
337
            
338
    private class ActionButtons {
317
		@Override
318
		public void actionPerformed(ActionEvent ae) {
319
			DefaultSearchPanel panel = (DefaultSearchPanel) ae.getSource();
320
			panel.doOrderBy();
321
		}
322
	}
339 323

  
340
        private final DALActionFactory factory;
341
        private final Action action;
342
        private final JButton button;
324
	private class TablePopupMenu extends JPopupMenu {
343 325

  
344
        public ActionButtons(DALActionFactory factory, Action action, JButton button) {
345
            this.factory = factory;
346
            this.action = action;
347
            this.button = button;
348
        }
349
    }
326
		public final JTable table;
350 327

  
351
    public static class SearchActionContext extends AbstractDALActionContext {
328
		@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
	}
352 339

  
353
        private final DefaultSearchPanel panel;
340
	private class ActionButtons {
354 341

  
355
        public SearchActionContext(DefaultSearchPanel panel) {
356
            super(FeatureStoreSearchPanel.ACTION_CONTEXT_NAME);
357
            this.panel = panel;
358
        }
342
		private final DALActionFactory factory;
343
		private final Action action;
344
		private final JButton button;
359 345

  
360
        @Override
361
        public DataStore getStore() {
362
            if (this.panel.currentPostProcess == null || this.panel.tabResults.getSelectedIndex() == 0) {
363
                return this.panel.getStore();
364
            } else {
365
                return this.panel.postProcessStore;
346
		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;
366 368
//                DataSwingManager manager = DALSwingLocator.getDataSwingManager();
367 369
//                SearchPostProcessFactory factory= manager.getSearchPostProcess(this.panel.currentPostProcess);
368 370
//                SearchParameters searchParams = this.panel.parameters.getCopy();
......
372 374
//                }
373 375
//                SearchPostProcess.SearchPostProcessResult searchPostProcessResult = this.panel.doExecuteSearchPostProcess(this.panel.store, this.panel.parameters.getQuery(), factory, null, searchParams);
374 376
//                return searchPostProcessResult.getStore();
375
            }
376
        }
377
			}
378
		}
377 379

  
378
        @Override
379
        public JComponent getActionButton(String actionName) {
380
            return this.panel.getActionButton(actionName);
381
        }
380
		@Override
381
		public JComponent getActionButton(String actionName) {
382
			return this.panel.getActionButton(actionName);
383
		}
382 384

  
383
        @Override
384
        public int getSelectedsCount() {
385
            return this.panel.getSelectedFeatureCount();
386
        }
385
		@Override
386
		public int getSelectedsCount() {
387
			return this.panel.getSelectedFeatureCount();
388
		}
387 389

  
388
        @Override
389
        public Expression getFilterForSelecteds() {
390
            return this.panel.getFilterForSelectedFeature();
391
        }
390
		@Override
391
		public Expression getFilterForSelecteds() {
392
			return this.panel.getFilterForSelectedFeature();
393
		}
392 394

  
393
        @Override
394
        public FeatureQuery getQuery() {
395
            if (this.panel.currentPostProcess == null || this.panel.tabResults.getSelectedIndex() == 0) {
396
                return this.panel.parameters.getQuery();
397
            } else {
398
                return this.panel.postProcessQuery;
395
		@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;
399 401
//                DataSwingManager manager = DALSwingLocator.getDataSwingManager();
400 402
//                SearchPostProcessFactory factory= manager.getSearchPostProcess(this.panel.currentPostProcess);
401 403
//                SearchParameters searchParams =this.panel.parameters.getCopy();
......
405 407
//                }
406 408
//                SearchPostProcess.SearchPostProcessResult searchPostProcessResult = this.panel.doExecuteSearchPostProcess(this.panel.store, this.panel.parameters.getQuery(), factory, null, searchParams);
407 409
//                return searchPostProcessResult.getQuery();
408
            }
409
        }
410
    }
410
			}
411
		}
412
	}
411 413

  
412 414
//    private class SearchPostProcessListener implements ActionListener {
413 415
//
......
457 459
//            }
458 460
//        }
459 461
//    }
462
	private FeatureStore store;
463
	private final ActionListenerSupport acctionListeners;
464
	private final Map<String, ActionButtons> actions;
465
	private boolean showActions = true;
466
	private DefaultSearchParameters parameters;
460 467

  
461
    private FeatureStore store;
462
    private final ActionListenerSupport acctionListeners;
463
    private final Map<String, ActionButtons> actions;
464
    private boolean showActions = true;
465
    private DefaultSearchParameters parameters;
468
	private List<SearchConditionPanel> conditionPanels;
466 469

  
467
    private List<SearchConditionPanel> conditionPanels;
470
	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;
468 476

  
469
    public static final int PANEL_SIMPLIFIED = 0;
470
    public static final int PANEL_ADVANCED = 1;
471
    private static final String BOOKMARKSANDHISTORY_NAME = "SearchPanel";
472
    private final Bookmarks<Object> bookmarks;
473
    private final History<Object> history;
474
    private boolean filterOnlyMode;
477
	private String currentPostProcess;
475 478

  
476
    private String currentPostProcess;
479
	private DynObject postProcessParams;
480
	private FeatureStore postProcessStore;
481
	private FeatureQuery postProcessQuery;
482
	private SimpleFeaturesTableModel resultModel;
483
	private SimpleFeaturesTableModel resultPostProcessModel;
477 484

  
478
    private DynObject postProcessParams;
479
    private FeatureStore postProcessStore;
480
    private FeatureQuery postProcessQuery;
481
    private SimpleFeaturesTableModel resultModel;
482
    private SimpleFeaturesTableModel resultPostProcessModel;
485
	private boolean processing;
486
	private JComponent configurableActions;
483 487

  
484
    private boolean processing;
485
    private JComponent configurableActions;
488
	@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);
486 509

  
487
    @SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"})
488
    public DefaultSearchPanel(FeatureStore store) {
489
        this.store = store;
490
        this.filterOnlyMode = false;
491
        DisposeUtils.bind(store);
492
        this.acctionListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
493
        this.actions = new HashMap<>();
494
        this.parameters = new DefaultSearchParameters();
495
        FeatureQuery featureQuery = this.store.createFeatureQuery();
496
        featureQuery.retrievesAllAttributes();
497
        this.parameters.setQuery(featureQuery);
498
        this.currentPostProcess = null;
499
        this.postProcessParams = null;
500
        this.postProcessStore = null;
501
        this.postProcessQuery = null;
502
        this.processing = false;
503
        this.configurableActions = null;
504
        this.resultModel = null;
505
        this.resultPostProcessModel = null;
506
        this.propertiesHelper = new PropertiesSupportHelper();
507
        this.propertiesHelper.setProperty("SearchPanel", this);
510
		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
	}
508 524

  
509
        Search search = (Search) ToolsLocator.getComplementsManager().get(
510
                Search.COMPLEMENT_MANE, getFeatureType()
511
        );
512
        List<Search.OrderedAttribute> attributos = search.getOrderedAttributes(
513
                Search.BASIC_TYPES_FILTER,
514
                Search.STR_INT_LONG_LABEL_ORDER,
515
                12
516
        );
517
        for (Search.OrderedAttribute attrdesc : attributos) {
518
            this.parameters.getResultColumnNames().add(attrdesc.getDescriptor().getName());
519
        }
520
        this.bookmarks = ToolsLocator.getBookmarksAndHistoryManager().getBookmarksGroup(BOOKMARKSANDHISTORY_NAME);
521
        this.history = ToolsLocator.getBookmarksAndHistoryManager().getHistoryGroup(BOOKMARKSANDHISTORY_NAME);
522
    }
525
	@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
	}
523 535

  
524
    @Override
525
    public void dispose() {
526
        DisposeUtils.disposeQuietly(store);
527
        TableModel m = this.tblResults.getModel();
528
        if (m instanceof Disposable) {
529
            DisposeUtils.disposeQuietly((Disposable) m);
530
        }
531
        this.store = null;
532
        this.tblResults.setModel(new DefaultTableModel());
533
    }
536
	@Override
537
	public JComponent asJComponent() {
538
		if (this.conditionPanels == null) {
539
			this.initComponents();
540
		}
541
		return this;
542
	}
534 543

  
535
    @Override
536
    public JComponent asJComponent() {
537
        if (this.conditionPanels == null) {
538
            this.initComponents();
539
        }
540
        return this;
541
    }
544
	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
	}
542 569

  
543
    private void addActions() {
544
        if (!this.showActions) {
545
            return;
546
        }
547
        this.pnlActions.removeAll();
548
        this.pnlActions.setLayout(new FlowLayout(FlowLayout.TRAILING, 8, 4));
549
        SearchActionContext actionContext = new SearchActionContext(this);
550
        Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions();
551
        for (DALActionFactory factory : factories) {
552
            if (!factory.isApplicable(actionContext)) {
553
                continue;
554
            }
555
            Action action = factory.createAction(actionContext);
556
            JButton button = new JButton(action);
557
            this.actions.put(factory.getName(), new ActionButtons(factory, action, button));
558
            button.setBorder(BorderFactory.createEmptyBorder());
559
            button.setBorderPainted(false);
560
            button.setFocusPainted(false);
561
            button.setContentAreaFilled(false);
562
            button.setCursor(new Cursor(Cursor.HAND_CURSOR));
563
            this.pnlActions.add(button);
564
        }
565
        this.pnlActions.revalidate();
566
        this.pnlActions.repaint();
567
    }
570
	@Override
571
	public void addActionListener(ActionListener listener) {
572
		this.acctionListeners.addActionListener(listener);
573
	}
568 574

  
569
    @Override
570
    public void addActionListener(ActionListener listener) {
571
        this.acctionListeners.addActionListener(listener);
572
    }
575
	@Override
576
	public ActionListener[] getActionListeners() {
577
		return this.acctionListeners.getActionListeners();
578
	}
573 579

  
574
    @Override
575
    public ActionListener[] getActionListeners() {
576
        return this.acctionListeners.getActionListeners();
577
    }
580
	@Override
581
	public void removeActionListener(ActionListener listener) {
582
		this.acctionListeners.removeActionListener(listener);
583
	}
578 584

  
579
    @Override
580
    public void removeActionListener(ActionListener listener) {
581
        this.acctionListeners.removeActionListener(listener);
582
    }
585
	@Override
586
	public void removeAllActionListener() {
587
		this.acctionListeners.removeAllActionListener();
588
	}
583 589

  
584
    @Override
585
    public void removeAllActionListener() {
586
        this.acctionListeners.removeAllActionListener();
587
    }
590
	@Override
591
	public void fireActionEvent(ActionEvent event) {
592
		this.acctionListeners.fireActionEvent(event);
593
	}
588 594

  
589
    @Override
590
    public void fireActionEvent(ActionEvent event) {
591
        this.acctionListeners.fireActionEvent(event);
592
    }
595
	@Override
596
	public boolean hasActionListeners() {
597
		return this.acctionListeners.hasActionListeners();
598
	}
593 599

  
594
    @Override
595
    public boolean hasActionListeners() {
596
        return this.acctionListeners.hasActionListeners();
597
    }
600
	private void initComponents() {
601
		this.conditionPanels = new ArrayList<>();
598 602

  
599
    private void initComponents() {
600
        this.conditionPanels = new ArrayList<>();
603
		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);
601 613

  
602
        ToolsSwingManager swingManager = ToolsSwingLocator.getToolsSwingManager();
603
        swingManager.translate(this.tabSearchMode);
604
        swingManager.translate(this.tabResults);
605
        swingManager.translate(this.btnSearch);
606
        swingManager.translate(this.btnClear);
607
        swingManager.translate(this.btnSearchPostProcess);
608
        swingManager.translate(this.lblExpressionDeBusqueda);
609
        swingManager.translate(this.btnAddAccumulatedFilter);
610
        swingManager.translate(this.btnRemoveAccumulatedFilter);
611
        swingManager.translate(this.btnViewAccumulatedFilter);
612
        
613
        ConfigurableActionsMamager cfgActionsManager = ToolsUtilLocator.getConfigurableActionsMamager();
614
        this.configurableActions = cfgActionsManager.getConfigurableActionsComponent(CONFIGURABLE_PANEL_ID, this);
615
        this.pnlCfgActions.setLayout(new BorderLayout(0, 0));
616
        this.pnlCfgActions.add(configurableActions, BorderLayout.CENTER);
617
        
618
        this.taskStatusController = ToolsSwingLocator.getTaskStatusSwingManager().createTaskStatusController(
619
                this.lblStatusTitle, 
620
                this.lblMsg, 
621
                this.pgbStatus);
614
		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);
622 623
		this.pgbStatus.setVisible(false);
623 624

  
624
        this.conditionPanels.add(
625
                new SearchConditionPanelSimplified(
626
                        parameters,
627
                        store,
628
                        btnAddAccumulatedFilter,
629
                        btnRemoveAccumulatedFilter,
630
                        btnViewAccumulatedFilter,
631
                        lblField1,
632
                        lblExtraFields1,
633
                        lblRelationalOperator1,
634
                        cboValue1,
635
                        lblNull1,
636
                        lblLogicalOperators1,
637
                        lblField2,
638
                        lblExtraFields2,
639
                        lblRelationalOperator2,
640
                        cboValue2,
641
                        lblNull2,
642
                        lblLogicalOperators2,
643
                        lblField3,
644
                        lblExtraFields3,
645
                        lblRelationalOperator3,
646
                        cboValue3,
647
                        lblNull3,
648
                        lblLogicalOperators3,
649
                        lblField4,
650
                        lblExtraFields4,
651
                        lblRelationalOperator4,
652
                        cboValue4,
653
                        lblNull4,
654
                        null
655
                )
656
        );
657
        
658
        SearchConditionPanelAdvanced advancedPanel = new SearchConditionPanelAdvanced(
659
                this.store,
660
                txtAdvancedExpression,
661
                btnAdvancedExpression,
662
                btnAdvancedExpressionHistory,
663
                btnAdvancedExpressionBookmarks
664
        );
665
        this.conditionPanels.add(advancedPanel);
666
        
667
        for (SearchConditionPanelFactory factory : DALSwingLocator.getManager().getSearchConditionPanels()) {
668
            String factoryName = "unknown";
669
            try {
670
                factoryName = factory.getName();
671
                if (factory.isApplicable(store)) {
672
                    SearchConditionPanel panel = factory.create(this);
673
                    this.conditionPanels.add(panel);
674
                    this.tabSearchMode.add(factory.getName(), panel.asJComponent());
675
                }
676
            } catch (Throwable th) {
677
                LOGGER.warn("Can't create search panel '" + factoryName + "'.");
678
            }
679
        }
625
		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
		);
680 658

  
681
        this.btnSearch.addActionListener((ActionEvent e) -> {
682
            this.tabResults.setEnabledAt(1, false);
683
            search();
684
        });
659
		SearchConditionPanelAdvanced advancedPanel = new SearchConditionPanelAdvanced(
660
			this.store,
661
			txtAdvancedExpression,
662
			btnAdvancedExpression,
663
			btnAdvancedExpressionHistory,
664
			btnAdvancedExpressionBookmarks
665
		);
666
		this.conditionPanels.add(advancedPanel);
685 667

  
686
        this.tblResults.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> {
687
            try {
688
                lastSelectedFeature = resultModel.getFeatureAt(tblResults.getSelectedRow());
689
            } catch(Throwable th ) {
690
                LOGGER.debug("Can't retrieve last selected feature.",th);
691
            }
692
            for (ActionButtons actionButton : actions.values()) {
693
                if (actionButton.action instanceof ListSelectionListener) {
694
                    ((ListSelectionListener) actionButton.action).valueChanged(e);
695
                }
696
            }
697
        });
698
        this.btnClear.addActionListener((ActionEvent e) -> {
699
            clear();
700
        });
701
        addActions();
668
		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
		}
702 681

  
703
        //swingManager.createTableColumnAdjuster(tblResults);
704
        //swingManager.createTableColumnAdjuster(tblSearchPostProcessResults);
682
		this.btnSearch.addActionListener((ActionEvent e) -> {
683
			this.tabResults.setEnabledAt(1, false);
684
			search();
685
		});
705 686

  
687
		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 706
//        this.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
707
        ToolsSwingUtils.ensureRowsCols(this, 20, 100, 30, 120);
707
		ToolsSwingUtils.ensureRowsCols(this, 20, 100, 30, 120);
708 708

  
709
        this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(this.bookmarks, btnBookmarks);
710
        this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(this.history, btnHistory);
709
		this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(this.bookmarks, btnBookmarks);
710
		this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(this.history, btnHistory);
711 711

  
712
        this.historyController.setFilter(null);
712
		this.historyController.setFilter(null);
713 713

  
714
        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
                    
722
                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
        });
714
		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;
750 721

  
751
        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
        });
722
				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
		});
758 750

  
759
        this.tabResults.setEnabledAt(1, false);
751
		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
		});
760 758

  
761
        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
        
771
        this.tblResults.setComponentPopupMenu(new TablePopupMenu(this.tblResults));
772
        this.tblSearchPostProcessResults.setComponentPopupMenu(new TablePopupMenu(this.tblSearchPostProcessResults));
773
                
774
        //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
        
786
        this.tabResults.addChangeListener((ChangeEvent evt) -> {
787
            SwingUtilities.invokeLater(() -> {
788
                if(tabResults.getSelectedIndex()==0){
789
                    updateNumberElementsMsg(resultModel);
790
                }else{
791
                    updateNumberElementsMsg(resultPostProcessModel);
792
                }
793
            });
794
        });
795
        if( this.filterOnlyMode ) {
796
            this.btnSearchPostProcess.setVisible(false);
797
        }
798
        clear();
799
        search();
800
    }
801
    
802
    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
    }
759
		this.tabResults.setEnabledAt(1, false);
822 760

  
823
    @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
    }
761
		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
		});
831 770

  
832
    @Override
833
    public void setEnabled(boolean enabled) {
834
        if(!SwingUtilities.isEventDispatchThread()) {
835
            SwingUtilities.invokeLater(() -> {setEnabled(enabled);});
836
            return;
837
        }
838
        
839
        if (this.conditionPanels == null) {
840
            this.initComponents();
841
        }
842
        for (SearchConditionPanel conditionPanel : conditionPanels) {
843
            conditionPanel.setEnabled(enabled);
844
        }
771
		this.tblResults.setComponentPopupMenu(new TablePopupMenu(this.tblResults));
772
		this.tblSearchPostProcessResults.setComponentPopupMenu(new TablePopupMenu(this.tblSearchPostProcessResults));
845 773

  
846
        this.btnClear.setEnabled(enabled);
847
        this.btnSearch.setEnabled(enabled);
848
        for (ActionButtons actionButton : actions.values()) {
849
            actionButton.action.setEnabled(enabled);
850
        }
851
        this.btnSearchPostProcess.setEnabled(enabled);
852
        //bookmarkController,historyController,configurableActions
853
    }
774
		//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
		}
854 785

  
855
    @Override
856
    public void clear() {
857
        this.taskStatusController.setTitle("");
858
        if (this.conditionPanels == null) {
859
            return;
860
        }
861
        for (SearchConditionPanel conditionPanel : conditionPanels) {
862
            conditionPanel.clear();
863
        }
864
        FeatureQuery emptyQuery = this.store.createFeatureQuery();
865
        emptyQuery.retrievesAllAttributes();
866
        this.parameters.setQuery(emptyQuery);
867
        // Mantener las columnas visualizadas
868
        // Elimina las que no existen en el store como campos calculados que
869
        // pudieran existir en el fquery
870
        List<String> resultColumnNames = this.parameters.getResultColumnNames();
871
        ArrayList<String> toDeleteAlreadyDontExist = new ArrayList<>();
872
        for (String resultColumnName : resultColumnNames) {
873
            try {
874
                FeatureAttributeDescriptor attr = this.store.getDefaultFeatureType().getAttributeDescriptor(resultColumnName);
875
                if (attr == null) {
876
                    toDeleteAlreadyDontExist.add(resultColumnName);
877
                }
878
            } catch (DataException ex) {
786
		this.tabResults.addChangeListener((ChangeEvent evt) -> {
787
			SwingUtilities.invokeLater(() -> {
788
				if (tabResults.getSelectedIndex() == 0) {
789
					updateNumberElementsMsg(resultModel);
790
				} else {
791
					updateNumberElementsMsg(resultPostProcessModel);
792
				}
793
			});
794
		});
795
		if (this.filterOnlyMode) {
796
			this.btnSearchPostProcess.setVisible(false);
797
		}
798
		clear();
799
		search();
800
	}
879 801

  
880
            }
881
        }
882
        resultColumnNames.removeAll(toDeleteAlreadyDontExist);
883
        resetTable();
884
    }
802
	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
	}
885 822

  
886
    @Override
887
    public FeatureQuery getLastQuery() {
888
        return this.lastQuery;
889
    }
823
	@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
	}
890 831

  
891
    public boolean isValid(StringBuilder message) {
892
        int searchMode = this.tabSearchMode.getSelectedIndex();
893
        SearchConditionPanel panel = this.conditionPanels.get(searchMode);
894
        boolean valid = panel.isValid(message);
895
        return valid;
896
    }
897
    
898
    @Override
899
    public void search() {
900
        StringBuilder message = new StringBuilder();
901
        if (!this.isValid(message)) {
902
            ThreadSafeDialogsManager dialogManager = ToolsSwingLocator.getThreadSafeDialogsManager();
903
            dialogManager.messageDialog(
904
                    "_The_specified_search_condition_is_not_valid",
905
                    "_Search",
906
                    JOptionPane.WARNING_MESSAGE
907
            );
908
            return;
909
        }
910
        lblMsg.setText(ToolsLocator.getI18nManager().getTranslation("_Searching")+"...");
911
        setEnabled(false);
912
        Thread th = new Thread(() -> {
913
        try {
832
	@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 {
914 916
				SearchParameters searchParams;
915 917
				try {
916 918
					searchParams = this.fetch(this.parameters.getCopy()); // esto lo actualiza a la ultima // decidir si se devuelve clonado
......
934 936
					setEnabled(true);
935 937
				});
936 938
			}
937
        });
938
        th.start();
939
    }
940
    
941
    private void doSearch(SearchParameters searchParams)  {
942
            final MutableObject model = new MutableObject(null);       
943
            final MutableLong rowCount=new MutableLong();
944
			Cursor savedCursor = this.getCursor();
945
		    SimpleTaskStatus status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("");
946
			status.setAutoremove(true);
947
			status.add();
948
			this.taskStatusController.bind(status);
949
            try {
950
				status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Processing_search"));
951
				SwingUtilities.invokeLater(() -> {this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));});
952
                final List<Feature> features;
953
                 FeatureQuery myQuery;
939
		});
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;
954 958
//                myQuery = this.getQuery().getCopy();
955
                this.tabResults.setSelectedIndex(0);
956
                List<String> resultColumnNames = searchParams.getResultColumnNames();
957
                myQuery = searchParams.getQuery().getCopy();
958
                features = store.getFeatures(myQuery, 50);
959
                FacadeOfAFeaturePagingHelper facade = (FacadeOfAFeaturePagingHelper) features;
960
                FeatureType ftype = facade.getFeaturePagingHelper().getFeatureSet().getDefaultFeatureType();
961
                // al modelo le pasamos el ftype de esas features
962
                SimpleFeaturesTableModel tableModel = new SimpleFeaturesTableModelImpl(
963
                        ftype,
964
                        resultColumnNames,
965
                        features
966
                );
967
                model.setValue(tableModel);
968
                rowCount.setValue(tableModel.getRowCount());
969
            } catch (Exception ex) {
970
                LOGGER.warn("Search not able to be executed. Can't get features or create table model", ex);
971
                status.setTitle(ToolsLocator.getI18nManager().getTranslation("_Errors_getting_new_feature_set") + "...");
972
				status.abort();
973
                resetTable();
974
            } finally {
975
                SwingUtilities.invokeLater(() -> {
976
                    I18nManager i18n = ToolsLocator.getI18nManager();
977
                    try {
978
                        TableModel oldmodel = tblResults.getModel();
979
                        resultModel = (SimpleFeaturesTableModel) model.getValue();
980
                        tblResults.setModel(resultModel);
981
                        resultModel.setCellRenderers(tblResults,getCustomRenderers(searchParams));
982
                        if (oldmodel instanceof SimpleFeaturesTableModelImpl) {
983
                            ((SimpleFeaturesTableModelImpl) oldmodel).dispose();
984
                        }
985
                        if (resultModel.hasErrors()) {
986
                            status.setTitle(i18n.getTranslation("_Errors_occurred_during_search"));
987
                        } else {
988
                            status.setTitle(String.format("%d " + i18n.getTranslation("_elements"), rowCount.getValue()));
989
                        }
990
                        if (this.parameters != null && this.parameters.getQuery() != null) {
991
                            this.history.add(searchParams);                   
992
                        }
993
                    } catch (Exception ex) {
994
                        LOGGER.warn(" Errors occurred during search getting old model", ex);
995
                        status.setTitle(i18n.getTranslation("_Errors_occurred_during_search"));
996
                    } finally {
997
                        setEnabled(true);
998
						status.terminate();
999
						this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
1000
                    }
1001
                });
1002
            }
1003
     }
1004
    
1005
    private Map<String, TableCellRenderer> getCustomRenderers(SearchParameters parameters) {
1006
        FeatureType ft = this.store.getDefaultFeatureTypeQuietly();
1007
        HashMap<String, TableCellRenderer> renderers = new HashMap<String, TableCellRenderer>();
1008
        for (FeatureAttributeDescriptor attr : ft) {
1009
            if(attr.getDataType().isNumeric()) {
959
			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());
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff