Ticket #11790: 11790.patch

File 11790.patch, 4.2 KB (added by simon04, 11 years ago)
  • src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java b/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
    index 1d53b34..84a0f0a 100644
    a b  
    7676    private SideButton ignoreButton;
    7777    /** The select button */
    7878    private SideButton selectButton;
     79    /** The lookup button */
     80    private SideButton lookupButton;
    7981
    8082    private final JPopupMenu popupMenu = new JPopupMenu();
    8183    private final transient PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu);
    public void actionPerformed(ActionEvent e) {  
    114116        selectButton.setEnabled(false);
    115117        buttons.add(selectButton);
    116118
     119        lookupButton = new SideButton(new AbstractAction(tr("Lookup")) {
     120            {
     121                putValue(NAME, tr("Lookup"));
     122                putValue(SHORT_DESCRIPTION, tr("Looks up the the selected primitives in the error list."));
     123                putValue(SMALL_ICON, ImageProvider.get("dialogs", "search"));
     124            }
     125
     126            @Override
     127            public void actionPerformed(ActionEvent e) {
     128                final DataSet ds = Main.main.getCurrentDataSet();
     129                if (ds == null) {
     130                    return;
     131                }
     132                tree.selectRelatedErrors(ds.getSelected());
     133            }
     134        });
     135
     136        buttons.add(lookupButton);
     137
    117138        buttons.add(new SideButton(Main.main.validator.validateAction));
    118139
    119140        fixButton = new SideButton(new AbstractAction() {
  • src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java b/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
    index 676488b..686c5af 100644
    a b  
    66import java.awt.event.KeyListener;
    77import java.awt.event.MouseEvent;
    88import java.util.ArrayList;
     9import java.util.Collection;
    910import java.util.Collections;
    1011import java.util.EnumMap;
    1112import java.util.Enumeration;
     
    3435import org.openstreetmap.josm.gui.util.GuiHelper;
    3536import org.openstreetmap.josm.tools.Destroyable;
    3637import org.openstreetmap.josm.tools.MultiMap;
     38import org.openstreetmap.josm.tools.Predicate;
     39import org.openstreetmap.josm.tools.Predicates;
     40import org.openstreetmap.josm.tools.Utils;
    3741
    3842/**
    3943 * A panel that displays the error tree. The selection manager
    public void setErrors(List<TestError> newerrors) {  
    342346    }
    343347
    344348    /**
     349     * Selects all errors related to the specified {@code primitives}, i.e. where {@link TestError#getPrimitives()}
     350     * returns a primitive present in {@code primitives}.
     351     */
     352    public void selectRelatedErrors(Collection<OsmPrimitive> primitives) {
     353        final Collection<TreePath> paths = new ArrayList<>();
     354        walkAndSelectRelatedErrors(new TreePath(getRoot()), Predicates.inCollection(primitives), paths);
     355        getSelectionModel().clearSelection();
     356        for (TreePath path : paths) {
     357            expandPath(path);
     358            getSelectionModel().addSelectionPath(path);
     359        }
     360    }
     361
     362    private void walkAndSelectRelatedErrors(final TreePath p, final Predicate<OsmPrimitive> isRelevant, final Collection<TreePath> paths) {
     363        final int count = getModel().getChildCount(p.getLastPathComponent());
     364        for (int i = 0; i < count; i++) {
     365            final Object child = getModel().getChild(p.getLastPathComponent(), i);
     366            if (getModel().isLeaf(child)) {
     367                final TestError error = (TestError)((DefaultMutableTreeNode) child).getUserObject();
     368                if (error.getPrimitives() != null) {
     369                    if (Utils.exists(error.getPrimitives(), isRelevant)) {
     370                        paths.add(p.pathByAddingChild(child));
     371                    }
     372                }
     373            } else {
     374                walkAndSelectRelatedErrors(p.pathByAddingChild(child), isRelevant, paths);
     375            }
     376        }
     377    }
     378
     379    /**
    345380     * Returns the filter list
    346381     * @return the list of primitives used for filtering
    347382     */