Revision 47417

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.api/src/main/java/org/gvsig/fmap/dal/swing/DataSwingManager.java
24 24

  
25 25
import java.awt.Component;
26 26
import java.util.Collection;
27
import java.util.HashMap;
27 28
import java.util.List;
28 29
import java.util.Map;
29 30
import java.util.function.Predicate;
......
77 78
import org.gvsig.fmap.dal.swing.report.ReportActionFactory.ReportCustomActionFactory;
78 79
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory;
79 80
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel;
81
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel.SearchResultsPanelFactory;
82
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel;
80 83
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory;
81 84
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters;
82 85
import org.gvsig.fmap.dal.swing.storesrepository.StoresRepositoryController;
83 86
import org.gvsig.tools.dynform.DynFormDefinition;
84 87
import org.gvsig.tools.dynobject.DynStruct;
88
import org.gvsig.tools.util.Factory;
85 89

  
86 90

  
87 91
/**
......
263 267
    
264 268
    public List<ReportAction> getReportActions(DataStore store, Predicate filter);
265 269

  
270
    public void registerSearchResultsPanel(SearchResultsPanelFactory factory);
271

  
272
    public Iterable<SearchResultsPanelFactory> getSearchResultsPanels();
266 273
}
trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.api/src/main/java/org/gvsig/fmap/dal/swing/searchpanel/FeatureStoreSearchPanel.java
7 7
import org.gvsig.fmap.dal.feature.FeatureQuery;
8 8
import org.gvsig.fmap.dal.feature.FeatureStore;
9 9
import org.gvsig.fmap.dal.feature.FeatureType;
10
import org.gvsig.fmap.dal.swing.DALActionFactory;
11
import org.gvsig.fmap.dal.swing.DALActionFactory.DALActionContext;
10 12
import org.gvsig.fmap.dal.swing.featuretable.SimpleFeaturesTableModel;
11 13
import org.gvsig.tools.dispose.Disposable;
12 14
import org.gvsig.tools.swing.api.ActionListenerSupport;
13 15
import org.gvsig.tools.swing.api.Component;
16
import org.gvsig.tools.util.Factory;
14 17
import org.gvsig.tools.util.PropertiesSupport;
15 18

  
16 19
/**
......
18 21
 * @author jjdelcerro
19 22
 */
20 23
public interface FeatureStoreSearchPanel extends  Component, ActionListenerSupport, Disposable, PropertiesSupport {
24
  
25
  public interface SearchResultsPanelFactory extends Factory<Component> {
26

  
27
    @Override
28
    public Component create(Object... os);
21 29
    
30
    public String getTitle();
31
  }
32
  
22 33
    public static final String CONFIGURABLE_PANEL_ID = "FeatureStoreSearchPanel";
23 34
    
24 35
    public static final String ACTION_CONTEXT_NAME = "FeatureStoreSearchPanel";
......
107 118
    
108 119
    public String getLastErrorMessage();
109 120
    
121
    public void addResultPanel(String name, String title, Component component);
122
    
123
    public void removeResultPanel(String name);
124
    
125
    public DALActionContext getSearchActionContext();
110 126
}
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/DefaultDataSwingManager.java
146 146
import org.gvsig.fmap.dal.swing.report.ReportActionFactory.ReportCustomActionFactory;
147 147
import org.gvsig.fmap.dal.swing.searchPostProcess.SearchPostProcessFactory;
148 148
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel;
149
import org.gvsig.fmap.dal.swing.searchpanel.FeatureStoreSearchPanel.SearchResultsPanelFactory;
149 150
import org.gvsig.fmap.dal.swing.searchpanel.SearchConditionPanel.SearchConditionPanelFactory;
150 151
import org.gvsig.fmap.dal.swing.searchpanel.SearchParameters;
151 152
import org.gvsig.fmap.dal.swing.storesrepository.StoresRepositoryController;
......
163 164
import org.gvsig.tools.swing.api.pickercontroller.PickerController;
164 165
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
165 166
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
167
import org.gvsig.tools.util.Factory;
166 168
import org.slf4j.Logger;
167 169
import org.slf4j.LoggerFactory;
168 170

  
......
180 182
    private final Map<String,SearchPostProcessFactory> searchPostProcess;
181 183
    private Map<String,SearchConditionPanelFactory> searchConditionPanelFactories;
182 184
    private Integer useLabels;
185
    private HashMap<String, SearchResultsPanelFactory> searchResultsPanelFactories;
183 186
    
184 187
    public DefaultDataSwingManager() {
185 188
        this.featureStoreActions = new LinkedHashMap<>();
......
624 627
    }
625 628

  
626 629
    @Override
630
    public void registerSearchResultsPanel(SearchResultsPanelFactory factory) {
631
      if( this.searchResultsPanelFactories==null ) {
632
        this.searchResultsPanelFactories = new HashMap<>();
633
      }
634
      this.searchResultsPanelFactories.put(factory.getName(), factory);
635
    }
636

  
637
    @Override
638
    public Iterable<SearchResultsPanelFactory> getSearchResultsPanels() {
639
      if( this.searchResultsPanelFactories==null ) {
640
        return Collections.EMPTY_LIST;
641
      }
642
      return this.searchResultsPanelFactories.values();
643
    }
644

  
645
    @Override
627 646
    public FeatureAttributesSelectionPanel createFeatureAttributeSelectionPanel() {
628 647
      FeatureAttributesSelectionPanel p = new DefaultFeatureAttributesSelectionPanel();
629 648
      return p;
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
108 108
import org.gvsig.tools.folders.FoldersManager;
109 109
import org.gvsig.tools.i18n.I18nManager;
110 110
import org.gvsig.tools.swing.api.ActionListenerSupport;
111
import org.gvsig.tools.swing.api.Component;
111 112
import org.gvsig.tools.swing.api.SupportIsEnable;
112 113
import org.gvsig.tools.swing.api.SupportIsVisible;
113 114
import org.gvsig.tools.swing.api.ToolsSwingLocator;
......
158 159
        private boolean initialized;
159 160
        private boolean postProcessEnabled;
160 161
        private boolean groupByEnabled;
162
        
163
        private Map<String,AdditionalResultsPanel> additionalResultsPanels;
164
        
165
        private static class AdditionalResultsPanel implements Component {
166
            
167
            private final String name;
168
            private final String title;
169
            private int index;
170
            private final Component component;
171
            
172
            public AdditionalResultsPanel(String name, String title, Component component, int index) {
173
                this.name = name;
174
                this.title = title;
175
                this.component = component;
176
                this.index = index;
177
            }
178
            
179
            public AdditionalResultsPanel(String name, String title, Component component) {
180
                this(name, title, component,-1);
181
            }
182
            
183
            public String getName() {
184
                return this.name;
185
            }
161 186

  
187
            public String getTitle() {
188
                return title;
189
            }
190
        
191
            public int getIndex() {
192
                return this.index;
193
            }
194

  
195
            @Override
196
            public JComponent asJComponent() {
197
                return this.component.asJComponent();
198
            }
199
            
200
            public void setIndex(int index) {
201
                this.index = index;
202
            }
203
            
204
            public void fireActionEvent(ActionEvent e) {                
205
                if( this.component instanceof ActionListenerSupport ) {
206
                    ((ActionListenerSupport)this.component).fireActionEvent(e);
207
                }
208
            }
209
            
210
            public void doDispose() {
211
                DisposeUtils.dispose(this.component);
212
            }
213
        }
214

  
162 215
	public static class UseLabelsYesAction extends AbstractAction {
163 216

  
164 217
		@SuppressWarnings("OverridableMethodCallInConstructor")
......
416 469

  
417 470
		@Override
418 471
		public DataStore getStore() {
419
			if (this.panel.currentPostProcess == null || this.panel.tabResults.getSelectedIndex() == 0) {
472
			if (this.panel.currentPostProcess != null && this.panel.tabResults.getSelectedIndex() == 1) {
473
				return this.panel.postProcessStore;
474
			} else {
420 475
				return this.panel.getStore();
421
			} else {
422
				return this.panel.postProcessStore;
423 476
			}
424 477
		}
425 478

  
......
445 498

  
446 499
		@Override
447 500
		public FeatureQuery getQuery() {
448
			if (this.panel.currentPostProcess == null || this.panel.tabResults.getSelectedIndex() == 0) {
501
			if (this.panel.currentPostProcess != null && this.panel.tabResults.getSelectedIndex() == 1) {
502
                            return this.panel.postProcessQuery;
503
			} else {
449 504
                            SearchParameters searchParams = this.panel.parameters;                            
450 505
                            FeatureQuery query = searchParams.getQueryToApply();
451 506
                            if( panel.useSelection() ) {
452 507
                                query = panel.addSelection(panel.store, query);
453 508
                            }
454 509
                            return query;
455
			} else {
456
                            return this.panel.postProcessQuery;
457 510
			}
458 511
		}
459 512
	}
......
492 545
		this.acctionListeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
493 546
		this.actions = new HashMap<>();
494 547
		this.parameters = new DefaultSearchParameters();
548
                this.additionalResultsPanels = new HashMap<>();
495 549
		FeatureQuery featureQuery = this.store.createFeatureQuery();
496 550
		featureQuery.retrievesAllAttributes();
497 551
		this.parameters.setQuery(featureQuery);
......
535 589
		}
536 590
		this.store = null;
537 591
		this.tblResults.setModel(new DefaultTableModel());
592
                for (AdditionalResultsPanel additionalResultsPanel : this.additionalResultsPanels.values()) {
593
                    additionalResultsPanel.doDispose();
594
                }                
538 595
	}
539 596

  
540 597
	@Override
......
658 715
					this.tabSearchMode.add(factory.getName(), panel.asJComponent());
659 716
				}
660 717
			} catch (Throwable th) {
661
				LOGGER.warn("Can't create search panel '" + factoryName + "'.");
718
				LOGGER.warn("Can't create search panel '" + factoryName + "'.", th);
662 719
			}
663 720
		}
664 721

  
......
765 822
		this.tblResults.setComponentPopupMenu(new TablePopupMenu(this.tblResults));
766 823
		this.tabResults.addChangeListener((ChangeEvent evt) -> {
767 824
			SwingUtilities.invokeLater(() -> {
768
				if (tabResults.getSelectedIndex() == 0) {
825
				switch(tabResults.getSelectedIndex()) {
826
                                    case 1:
827
					updateNumberElementsMsg(resultPostProcessModel);
828
                                        break;
829
                                    case 0:
830
                                    default:
769 831
					updateNumberElementsMsg(resultModel);
770
				} else {
771
					updateNumberElementsMsg(resultPostProcessModel);
772 832
				}
773 833
			});
774 834
		});
......
780 840
                if (this.filterOnlyMode || !this.postProcessEnabled) {
781 841
			this.btnSearchPostProcess.setVisible(false);
782 842
		}
843
                
844
		for (SearchResultsPanelFactory factory : DALSwingLocator.getManager().getSearchResultsPanels()) {
845
			String factoryName = "unknown";
846
			try {
847
                            factoryName = factory.getName();
848
                            this.addResultPanel(
849
                                    factory.getName(),
850
                                    factory.getTitle(),
851
                                    factory.create(this)
852
                                );
853
			} catch (Throwable th) {
854
				LOGGER.warn("Can't create results panel '" + factoryName + "'.",th);
855
			}
856
		}
857
                for (AdditionalResultsPanel panel : this.additionalResultsPanels.values()) {
858
                    panel.setIndex(this.tabResults.getTabCount());
859
                    this.tabResults.addTab(panel.getTitle(), panel.asJComponent());
860
                }
783 861

  
784 862
                this.initialized = true;
785 863
                
786
		//this.tblResults.add
787 864
                if (this.automaticallySearch){
788 865
                    if (this.bookmarks.hasBookmark(this.store.getName())) {
789 866
                            Bookmark<DefaultSearchParameters> initBookmark = this.bookmarks.get(this.store.getName());
......
1053 1130
                            if(this.initialized){
1054 1131
				I18nManager i18n = ToolsLocator.getI18nManager();
1055 1132
				try {
1056
                			this.tabResults.setSelectedIndex(0);
1133
                                        if( this.tabResults.getSelectedIndex()==1 ) {
1134
                                            this.tabResults.setSelectedIndex(0);
1135
                                        }
1057 1136
					TableModel oldmodel = tblResults.getModel();
1058 1137
					tblResults.setModel(resultModel);
1059 1138
					resultModel.setCellRenderers(tblResults, getCustomRenderers(searchParams));
......
1068 1147
					if (this.parameters != null && this.parameters.getQuery() != null) {
1069 1148
						this.history.add(searchParams);
1070 1149
					}
1150
                                        this.fireSearchEvent();
1071 1151
				} catch (Exception ex) {
1072 1152
					LOGGER.warn(" Errors occurred during search getting old model", ex);
1073 1153
					status.setTitle(i18n.getTranslation("_Errors_occurred_during_search"));
......
1210 1290
                if( ArrayUtils.isEmpty(selectedRows) ) {
1211 1291
                    return null;
1212 1292
                }
1213
		if (this.tabResults.getSelectedIndex() == 0) {
1293
		if (this.tabResults.getSelectedIndex() == 1) {
1294
                    if (this.currentPostProcess == null) {
1295
                            return null;
1296
                    }
1214 1297
                    try {
1215 1298
                            FeatureSelection selection = this.store.createFeatureSelection();
1216
                            List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblResults.getModel()).getFeatures();
1299
                            List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblSearchPostProcessResults.getModel()).getFeatures();
1217 1300
                            for (int i = 0; i < selectedRows.length ; i++) {
1218 1301
                                Feature feature = features.get(selectedRows[i]);
1219 1302
                                selection.select(feature);
......
1224 1307
                            return null;
1225 1308
                    }
1226 1309
		} else {
1227
                    if (this.currentPostProcess == null) {
1228
                            return null;
1229
                    }
1230 1310
                    try {
1231 1311
                            FeatureSelection selection = this.store.createFeatureSelection();
1232
                            List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblSearchPostProcessResults.getModel()).getFeatures();
1312
                            List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblResults.getModel()).getFeatures();
1233 1313
                            for (int i = 0; i < selectedRows.length ; i++) {
1234 1314
                                Feature feature = features.get(selectedRows[i]);
1235 1315
                                selection.select(feature);
......
1256 1336
                if( selectedRows.length > maxfeatures ) {
1257 1337
                    this.taskStatusController.message("Too many items selecteds");
1258 1338
                }
1259
		if (this.tabResults.getSelectedIndex() == 0) {
1260
                    try {
1261
                            FeatureType ftype = this.store.getDefaultFeatureType();
1262
                            ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
1263
                            List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblResults.getModel()).getFeatures();
1264
                            for (int i = 0; i < selectedRows.length && i<maxfeatures ; i++) {
1265
                                Feature feature = features.get(selectedRows[i]);
1266
                                for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
1267
                                        builder.and(
1268
                                                builder.eq(
1269
                                                        builder.column(attrdesc.getName()),
1270
                                                        builder.constant(feature.get(attrdesc.getName()))
1271
                                                )
1272
                                        );
1273
                                }
1274
                            }
1275
                            Expression filter = ExpressionUtils.createExpression(builder.toString());                            
1276
                            return filter;
1277
                    } catch (Exception ex) {
1278
                            LOGGER.warn("Can't build search for the selected feature.", ex);
1279
                            return null;
1280
                    }
1281
		} else {
1339
		if (this.tabResults.getSelectedIndex() == 1) {
1282 1340
			if (this.currentPostProcess == null) {
1283 1341
				return null;
1284 1342
			}
......
1303 1361
				LOGGER.warn("Can't build search for the selected feature.", ex);
1304 1362
				return null;
1305 1363
			}
1364
		} else {
1365
                    try {
1366
                            FeatureType ftype = this.store.getDefaultFeatureType();
1367
                            ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
1368
                            List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblResults.getModel()).getFeatures();
1369
                            for (int i = 0; i < selectedRows.length && i<maxfeatures ; i++) {
1370
                                Feature feature = features.get(selectedRows[i]);
1371
                                for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
1372
                                        builder.and(
1373
                                                builder.eq(
1374
                                                        builder.column(attrdesc.getName()),
1375
                                                        builder.constant(feature.get(attrdesc.getName()))
1376
                                                )
1377
                                        );
1378
                                }
1379
                            }
1380
                            Expression filter = ExpressionUtils.createExpression(builder.toString());                            
1381
                            return filter;
1382
                    } catch (Exception ex) {
1383
                            LOGGER.warn("Can't build search for the selected feature.", ex);
1384
                            return null;
1385
                    }
1306 1386
		}
1307 1387
        }
1308 1388
        
......
1311 1391
		if (!this.initialized) { //this.conditionPanels == null) {
1312 1392
			return null;
1313 1393
		}
1314
		if (this.tabResults.getSelectedIndex() == 0) {
1315
			int selectedRow = this.tblResults.getSelectedRow();
1394
		if (this.tabResults.getSelectedIndex() == 1) {
1395
			if (this.currentPostProcess == null) {
1396
				return null;
1397
			}
1398
			int selectedRow = this.tblSearchPostProcessResults.getSelectedRow();
1316 1399
			if (selectedRow < 0) {
1317 1400
				return null;
1318 1401
			}
1319 1402
			try {
1320
				List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblResults.getModel()).getFeatures();
1403
				List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblSearchPostProcessResults.getModel()).getFeatures();
1321 1404
				Feature feature = features.get(selectedRow);
1322 1405

  
1323 1406
				ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
1324
				FeatureType ftype = this.store.getDefaultFeatureType();
1407
				FeatureType ftype = this.postProcessStore.getDefaultFeatureType();
1325 1408
				for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
1326 1409
					builder.and(
1327 1410
						builder.eq(
......
1337 1420
				return null;
1338 1421
			}
1339 1422
		} else {
1340
			if (this.currentPostProcess == null) {
1341
				return null;
1342
			}
1343
			int selectedRow = this.tblSearchPostProcessResults.getSelectedRow();
1423
			int selectedRow = this.tblResults.getSelectedRow();
1344 1424
			if (selectedRow < 0) {
1345 1425
				return null;
1346 1426
			}
1347 1427
			try {
1348
				List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblSearchPostProcessResults.getModel()).getFeatures();
1428
				List<Feature> features = ((SimpleFeaturesTableModelImpl) this.tblResults.getModel()).getFeatures();
1349 1429
				Feature feature = features.get(selectedRow);
1350 1430

  
1351 1431
				ExpressionBuilder builder = ExpressionUtils.createExpressionBuilder();
1352
				FeatureType ftype = this.postProcessStore.getDefaultFeatureType();
1432
				FeatureType ftype = this.store.getDefaultFeatureType();
1353 1433
				for (FeatureAttributeDescriptor attrdesc : ftype.getPrimaryKey()) {
1354 1434
					builder.and(
1355 1435
						builder.eq(
......
1642 1722
		if (!this.initialized) { //this.conditionPanels == null) {
1643 1723
			return 0;
1644 1724
		}
1645
		if (this.currentPostProcess == null || this.tabResults.getSelectedIndex() == 0) {
1646
			return this.tblResults.getSelectedRowCount();
1725
		if (this.currentPostProcess != null && this.tabResults.getSelectedIndex() == 1) {
1726
        		return this.tblSearchPostProcessResults.getSelectedRowCount();
1647 1727
		}
1648
		return this.tblSearchPostProcessResults.getSelectedRowCount();
1728
                return this.tblResults.getSelectedRowCount();
1649 1729
	}
1650 1730

  
1651 1731
	@Override
......
2246 2326
        query.retrievesAllAttributes();
2247 2327
        return query;
2248 2328
    }
2329
    
2330
    @Override
2331
    public void addResultPanel(String name, String title, Component component) {
2332
        int index = -1;
2333
        if( this.additionalResultsPanels.containsKey(name) ) {
2334
            index = this.additionalResultsPanels.get(name).getIndex();
2335
        }
2336
        AdditionalResultsPanel panel = new AdditionalResultsPanel(name, title, component, index);
2337
        this.additionalResultsPanels.put(name, panel);
2338
        if( this.initialized ) {
2339
            if( index < 0 ) {
2340
                panel.setIndex(this.tabResults.getTabCount());
2341
                this.tabResults.addTab(panel.getTitle(), panel.asJComponent());
2342
            } else {
2343
                this.tabResults.setComponentAt(index, panel.asJComponent());
2344
                this.tabResults.setTitleAt(index, panel.getTitle());
2345
            }
2346
        }
2347
    }
2348

  
2349
    @Override
2350
    public void removeResultPanel(String name) {
2351
        int index = -1;
2352
        if( this.additionalResultsPanels.containsKey(name) ) {
2353
            index = this.additionalResultsPanels.get(name).getIndex();
2354
        }
2355
        this.additionalResultsPanels.remove(name);
2356
        if( this.initialized ) {
2357
            this.tabResults.removeTabAt(index);
2358
        }
2359
    }
2360

  
2361
    @Override
2362
    public DALActionFactory.DALActionContext getSearchActionContext() {
2363
        return new SearchActionContext(this);
2364
    }
2365

  
2366
    private void fireSearchEvent() {
2367
        ActionEvent e = new ActionEvent(this, 1, "search");
2368
        for (AdditionalResultsPanel additionalResultsPanel : this.additionalResultsPanels.values()) {
2369
            additionalResultsPanel.fireActionEvent(e);
2370
        }
2371
    }
2372
    
2373
    // https://docs.oracle.com/javase/tutorial/uiswing/components/layeredpane.html
2249 2374
}

Also available in: Unified diff