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 |
}
|