Ticket #17342: 17342-v2.patch
| File 17342-v2.patch, 4.7 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
18 18 import java.util.concurrent.atomic.AtomicBoolean; 19 19 20 20 import javax.swing.AbstractAction; 21 import javax.swing.Action; 21 22 import javax.swing.JComponent; 22 23 import javax.swing.JOptionPane; 23 24 import javax.swing.JPopupMenu; … … 125 126 selectButton.setEnabled(false); 126 127 buttons.add(selectButton); 127 128 128 lookupButton = new SideButton(new AbstractAction() { 129 { 130 putValue(NAME, tr("Lookup")); 131 putValue(SHORT_DESCRIPTION, tr("Looks up the selected primitives in the error list.")); 132 new ImageProvider("dialogs", "search").getResource().attachImageIcon(this, true); 133 } 134 135 @Override 136 public void actionPerformed(ActionEvent e) { 137 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 138 if (ds == null) { 139 return; 140 } 141 tree.selectRelatedErrors(ds.getSelected()); 142 } 143 }); 144 129 lookupButton = new SideButton(new LookupAction()); 145 130 buttons.add(lookupButton); 146 131 147 132 buttons.add(new SideButton(validateAction)); … … 180 165 createLayout(tree, true, buttons); 181 166 } 182 167 168 /** 169 * The action to lookup the selection in the error tree. 170 */ 171 class LookupAction extends AbstractAction implements DataSelectionListener { 172 173 LookupAction() { 174 putValue(NAME, tr("Lookup")); 175 putValue(SHORT_DESCRIPTION, tr("Looks up the selected primitives in the error list.")); 176 new ImageProvider("dialogs", "search").getResource().attachImageIcon(this, true); 177 SelectionEventManager.getInstance().addSelectionListener(this); 178 updateEnabledState(); 179 } 180 181 @Override 182 public void actionPerformed(ActionEvent e) { 183 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 184 if (ds == null) { 185 return; 186 } 187 tree.selectRelatedErrors(ds.getSelected()); 188 } 189 190 protected void updateEnabledState() { 191 boolean found = false; 192 for (TestError e : tree.getErrors()) { 193 for (OsmPrimitive p : e.getPrimitives()) { 194 if (p.isSelected()) { 195 found = true; 196 break; 197 } 198 } 199 } 200 setEnabled(found); 201 } 202 203 @Override 204 public void selectionChanged(SelectionChangeEvent event) { 205 updateEnabledState(); 206 } 207 } 208 183 209 @Override 184 210 public void showNotify() { 185 211 SelectionEventManager.getInstance().addSelectionListener(this); … … 606 632 private static void invalidateValidatorLayers() { 607 633 MainApplication.getLayerManager().getLayersOfType(ValidatorLayer.class).forEach(ValidatorLayer::invalidate); 608 634 } 635 636 @Override 637 public void destroy() { 638 if (lookupButton != null && lookupButton.getAction() instanceof DataSelectionListener) { 639 Action a = lookupButton.getAction(); 640 SelectionEventManager.getInstance().removeSelectionListener((DataSelectionListener) a); 641 } 642 super.destroy(); 643 } 609 644 } -
src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
348 348 * @param primitives collection of primitives 349 349 */ 350 350 public void selectRelatedErrors(final Collection<OsmPrimitive> primitives) { 351 final Collection<TreePath> paths = new ArrayList<>();351 final List<TreePath> paths = new ArrayList<>(); 352 352 walkAndSelectRelatedErrors(new TreePath(getRoot()), new HashSet<>(primitives)::contains, paths); 353 353 getSelectionModel().clearSelection(); 354 354 for (TreePath path : paths) { … … 355 355 expandPath(path); 356 356 getSelectionModel().addSelectionPath(path); 357 357 } 358 // make sure that first path is visible 359 if (!paths.isEmpty()) { 360 scrollPathToVisible(paths.get(0)); 361 } 358 362 } 359 363 360 364 private void walkAndSelectRelatedErrors(final TreePath p, final Predicate<OsmPrimitive> isRelevant, final Collection<TreePath> paths) {
