Changeset 14849 in josm


Ignore:
Timestamp:
2019-03-06T16:38:08+01:00 (4 months ago)
Author:
GerdP
Message:

fix #17412: Update validator tree when primitives are purged or removed and existing errors refer to those 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

    r14847 r14849  
    6363import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference;
    6464import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     65import org.openstreetmap.josm.gui.util.GuiHelper;
    6566import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    6667import org.openstreetmap.josm.io.OsmTransferException;
     
    610611        protected void fixError(TestError error) throws InterruptedException, InvocationTargetException {
    611612            if (error.isFixable()) {
    612                 if (error.getPrimitives().stream().noneMatch(OsmPrimitive::isDeleted)) {
     613                if (error.getPrimitives().stream().noneMatch(p -> p.isDeleted() || p.getDataSet() == null)) {
    613614                    final Command fixCommand = error.getFix();
    614615                    if (fixCommand != null) {
     
    632633                int i = 0;
    633634                SwingUtilities.invokeAndWait(ds::beginUpdate);
     635                tree.setResetScheduled();
    634636                try {
    635637                    for (TestError error: testErrors) {
     
    651653                    }
    652654                    invalidateValidatorLayers();
    653                     tree.resetErrors();
    654655                });
    655656            } catch (InterruptedException e) {
     
    663664                    tryUndo();
    664665                }
     666                GuiHelper.runInEDTAndWait(tree::resetErrors);
    665667                monitor.finishTask();
    666668            }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

    r14839 r14849  
    8181    private transient Set<? extends OsmPrimitive> filter;
    8282
    83     private final ListenerList<Runnable> invalidationListeners = ListenerList.create();
     83    private final transient ListenerList<Runnable> invalidationListeners = ListenerList.create();
     84
     85    /** if true, buildTree() does nothing */
     86    private boolean resetScheduled;
    8487
    8588    /**
     
    148151     */
    149152    public void buildTree() {
     153        if (resetScheduled)
     154            return;
    150155        final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    151156
     
    402407     */
    403408    public void resetErrors() {
     409        resetScheduled = false;
     410        filterRemovedPrimitives();
    404411        setErrors(new ArrayList<>(errors));
    405412    }
     
    481488    @Override public void primitivesRemoved(PrimitivesRemovedEvent event) {
    482489        // Remove purged primitives (fix #8639)
    483         if (errors != null) {
    484             final Set<? extends OsmPrimitive> deletedPrimitives = new HashSet<>(event.getPrimitives());
    485             errors.removeIf(error -> error.getPrimitives().stream().anyMatch(deletedPrimitives::contains));
     490        if (filterRemovedPrimitives()) {
     491            buildTree();
    486492        }
    487493    }
     
    512518
    513519    @Override public void dataChanged(DataChangedEvent event) {
    514         // Do nothing
    515     }
     520        if (filterRemovedPrimitives()) {
     521            buildTree();
     522        }
     523    }
     524
     525    /**
     526     * Can be called to suppress execution of buildTree() while doing multiple updates. Caller must
     527     * call resetErrors() to end this state.
     528     * @since 14848
     529     */
     530    public void setResetScheduled() {
     531        resetScheduled = true;
     532    }
     533
     534    /**
     535     * Remove errors which refer to removed or purged primitives.
     536     * @return true if error list was changed
     537     */
     538    private boolean filterRemovedPrimitives() {
     539        return errors != null && errors.removeIf(
     540                error -> error.getPrimitives().stream().anyMatch(p -> p.isDeleted() || p.getDataSet() == null));
     541    }
     542
    516543}
Note: See TracChangeset for help on using the changeset viewer.