Ignore:
Timestamp:
2011-10-08T00:24:18+02:00 (13 years ago)
Author:
simon04
Message:

fix #6935 - Ability to auto-find based on key/value pairs (patch by ij)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r4500 r4503  
    102102import org.openstreetmap.josm.tools.Shortcut;
    103103import org.openstreetmap.josm.tools.Utils;
     104import org.openstreetmap.josm.actions.search.SearchAction.SearchMode;
     105import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
    104106
    105107/**
     
    182184    private CopyKeyValueAction copyKeyValueAction = new CopyKeyValueAction();
    183185    private CopyAllKeyValueAction copyAllKeyValueAction = new CopyAllKeyValueAction();
     186    private SearchAction searchActionSame = new SearchAction(true);
     187    private SearchAction searchActionAny = new SearchAction(false);
    184188    private AddAction addAction = new AddAction();
    185189
     
    616620        propertyMenu.add(copyAllKeyValueAction);
    617621        propertyMenu.addSeparator();
     622        propertyMenu.add(searchActionAny);
     623        propertyMenu.add(searchActionSame);
     624        propertyMenu.addSeparator();
    618625        propertyMenu.add(helpAction);
    619626       
     
    14121419        }
    14131420    }
     1421
     1422    class SearchAction extends AbstractAction {
     1423        final boolean sameType;
     1424
     1425        public SearchAction(boolean sameType) {
     1426            this.sameType = sameType;
     1427            if (sameType) {
     1428                putValue(NAME, tr("Search Key/Value/Type"));
     1429                putValue(SHORT_DESCRIPTION, tr("Search with the key and value of the selected tag, restrict to type (i.e., node/way/relation)"));
     1430            } else {
     1431                putValue(NAME, tr("Search Key/Value"));
     1432                putValue(SHORT_DESCRIPTION, tr("Search with the key and value of the selected tag"));
     1433            }
     1434        }
     1435
     1436        public void actionPerformed(ActionEvent e) {
     1437            if (propertyTable.getSelectedRowCount() != 1) {
     1438                return;
     1439            }
     1440            String key = propertyData.getValueAt(propertyTable.getSelectedRow(), 0).toString();
     1441            Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
     1442            if (sel.isEmpty()) {
     1443                return;
     1444            }
     1445            String sep = "";
     1446            String s = "";
     1447            for (OsmPrimitive p : sel) {
     1448                String val = p.get(key);
     1449                if (val == null) {
     1450                    continue;
     1451                }
     1452                String t = "";
     1453                if (!sameType) {
     1454                    t = "";
     1455                } else if (p instanceof Node) {
     1456                    t = "type:node ";
     1457                } else if (p instanceof Way) {
     1458                    t = "type:way ";
     1459                } else if (p instanceof Relation) {
     1460                    t = "type:relation ";
     1461                }
     1462                s += sep + "(" + t + "\"" +
     1463                        org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(key) + "\"=\"" +
     1464                        org.openstreetmap.josm.actions.search.SearchAction.escapeStringForSearch(val) + "\")";
     1465                sep = " OR ";
     1466            }
     1467
     1468            SearchSetting ss = new SearchSetting(s, SearchMode.replace, true, false, false);
     1469            org.openstreetmap.josm.actions.search.SearchAction.searchWithoutHistory(ss);
     1470        }
     1471    }
    14141472}
Note: See TracChangeset for help on using the changeset viewer.