Ticket #17401: 17401-v3.patch

File 17401-v3.patch, 4.4 KB (added by GerdP, 7 years ago)
  • src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

     
    3434import org.openstreetmap.josm.actions.ValidateAction;
    3535import org.openstreetmap.josm.actions.relation.EditRelationAction;
    3636import org.openstreetmap.josm.command.Command;
     37import org.openstreetmap.josm.command.SequenceCommand;
    3738import org.openstreetmap.josm.data.UndoRedoHandler;
    3839import org.openstreetmap.josm.data.osm.DataSelectionListener;
    3940import org.openstreetmap.josm.data.osm.DataSet;
     
    601602            // do nothing
    602603        }
    603604
    604         protected void fixError(TestError error) throws InterruptedException, InvocationTargetException {
     605        protected void fixError(TestError error) {
    605606            if (error.isFixable()) {
    606607                final Command fixCommand = error.getFix();
    607608                if (fixCommand != null) {
    608                     SwingUtilities.invokeAndWait(() -> UndoRedoHandler.getInstance().addNoRedraw(fixCommand));
    609609                    fixCommands.add(fixCommand);
    610610                }
    611611                // It is wanted to ignore an error if it said fixable, even if fixCommand was null
     
    622622                monitor.setTicksCount(testErrors.size());
    623623                final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    624624                int i = 0;
    625                 SwingUtilities.invokeAndWait(ds::beginUpdate);
    626                 try {
    627                     for (TestError error: testErrors) {
    628                         i++;
    629                         monitor.subTask(tr("Fixing ({0}/{1}): ''{2}''", i, testErrors.size(), error.getMessage()));
    630                         if (this.canceled)
    631                             return;
    632                         fixError(error);
    633                         monitor.worked(1);
    634                     }
    635                 } finally {
    636                     SwingUtilities.invokeAndWait(ds::endUpdate);
     625                for (TestError error: testErrors) {
     626                    i++;
     627                    monitor.subTask(tr("Fixing ({0}/{1}): ''{2}''", i, testErrors.size(), error.getMessage()));
     628                    if (this.canceled)
     629                        return;
     630                    fixError(error);
     631                    monitor.worked(1);
    637632                }
    638633                monitor.subTask(tr("Updating map ..."));
     634                List<TestError> oldErrors = new ArrayList<>(tree.getErrors());
     635                tree.getErrors().clear();
    639636                SwingUtilities.invokeAndWait(() -> {
    640                     UndoRedoHandler.getInstance().afterAdd(fixCommands);
    641                     invalidateValidatorLayers();
    642                     tree.resetErrors();
     637                    ds.beginUpdate();
     638                    UndoRedoHandler.getInstance().add(new SequenceCommand(tr("fixed by Validator"), fixCommands, true));
     639                    ds.endUpdate();
    643640                });
     641                invalidateValidatorLayers();
     642
     643                oldErrors.removeIf(error -> error.getPrimitives().stream().anyMatch(OsmPrimitive::isDeleted));
     644                tree.getErrors().addAll(oldErrors);
     645                tree.resetErrors();
    644646            } catch (InterruptedException | InvocationTargetException e) {
    645647                // FIXME: signature of realRun should have a generic checked exception we could throw here
    646648                throw new JosmRuntimeException(e);
  • src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

     
    483483
    484484    @Override public void primitivesRemoved(PrimitivesRemovedEvent event) {
    485485        // Remove purged primitives (fix #8639)
    486         if (errors != null) {
    487             final Set<? extends OsmPrimitive> deletedPrimitives = new HashSet<>(event.getPrimitives());
    488             errors.removeIf(error -> error.getPrimitives().stream().anyMatch(deletedPrimitives::contains));
     486        if (errors != null && !errors.isEmpty()) {
     487            errors.removeIf(error -> error.getPrimitives().stream().anyMatch(OsmPrimitive::isDeleted));
    489488        }
    490489    }
    491490