Changeset 8682 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2015-08-22T21:43:53+02:00 (9 years ago)
Author:
simon04
Message:

fix #11790 - Validator dialog: lookup test errors for selected primitives

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs
Files:
2 edited

Legend:

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

    r8633 r8682  
    7777    /** The select button */
    7878    private SideButton selectButton;
     79    /** The lookup button */
     80    private SideButton lookupButton;
    7981
    8082    private final JPopupMenu popupMenu = new JPopupMenu();
     
    114116        selectButton.setEnabled(false);
    115117        buttons.add(selectButton);
     118
     119        lookupButton = new SideButton(new AbstractAction() {
     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);
    116137
    117138        buttons.add(new SideButton(Main.main.validator.validateAction));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

    r8633 r8682  
    77import java.awt.event.MouseEvent;
    88import java.util.ArrayList;
     9import java.util.Collection;
    910import java.util.Collections;
    1011import java.util.EnumMap;
     
    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/**
     
    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(final Collection<OsmPrimitive> primitives) {
     353        final Collection<TreePath> paths = new ArrayList<>();
     354        walkAndSelectRelatedErrors(new TreePath(getRoot()), Predicates.inCollection(new HashSet<>(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) && child instanceof DefaultMutableTreeNode
     367                    && ((DefaultMutableTreeNode) child).getUserObject() instanceof TestError) {
     368                final TestError error = (TestError) ((DefaultMutableTreeNode) child).getUserObject();
     369                if (error.getPrimitives() != null) {
     370                    if (Utils.exists(error.getPrimitives(), isRelevant)) {
     371                        paths.add(p.pathByAddingChild(child));
     372                    }
     373                }
     374            } else {
     375                walkAndSelectRelatedErrors(p.pathByAddingChild(child), isRelevant, paths);
     376            }
     377        }
     378    }
     379
     380    /**
    345381     * Returns the filter list
    346382     * @return the list of primitives used for filtering
Note: See TracChangeset for help on using the changeset viewer.