| | 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 keep type")); |
| | 1429 | putValue(SHORT_DESCRIPTION, tr("Search with the key and value of the selected tag, keep type")); |
| | 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 + "\"" + key + "\"=\"" + val + "\")"; |
| | 1463 | sep = " OR "; |
| | 1464 | } |
| | 1465 | |
| | 1466 | SearchSetting ss = new SearchSetting(s, SearchMode.replace, true, false, false); |
| | 1467 | org.openstreetmap.josm.actions.search.SearchAction.searchWithoutHistory(ss); |
| | 1468 | } |
| | 1469 | } |