Ignore:
Timestamp:
2020-01-27T08:05:05+01:00 (5 years ago)
Author:
gerdp
Message:

fix #10020: Revert selection to new layer broken
Selected elements where searched in the wrong DataSet.

Location:
applications/editors/josm/plugins/reverter/src/reverter
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reverter/src/reverter/ChangesetReverter.java

    r35226 r35310  
    7474    private final DataSet ds; // DataSet associated with reverter
    7575    private final ChangesetDataSet cds; // Current changeset data
     76    /** original DataSet, used if a new layer is requested */
     77    private final DataSet ods;
    7678    private DataSet nds; // Dataset that contains new objects downloaded by reverter
    7779
     
    118120            return true;
    119121        }
    120         OsmPrimitive p = ds.getPrimitiveById(entry.getPrimitive().getPrimitiveId());
     122        if (ods == null)
     123            return false; // should not happen
     124        OsmPrimitive p = ods.getPrimitiveById(entry.getPrimitive().getPrimitiveId());
    121125        if (p == null) return false;
    122126        return p.isSelected();
     
    128132     * @param revertType type of revert
    129133     * @param newLayer set to true if a new layer should be created
     134     * @param ods original dataset to search for selected primitives, can be null
    130135     * @param monitor progress monitor
    131136     * @throws OsmTransferException if data transfer errors occur
    132137     * @throws RevertRedactedChangesetException if a redacted changeset is requested
    133138     */
    134     public ChangesetReverter(int changesetId, RevertType revertType, boolean newLayer, ProgressMonitor monitor)
     139    public ChangesetReverter(int changesetId, RevertType revertType, boolean newLayer, DataSet ods, ProgressMonitor monitor)
    135140            throws OsmTransferException, RevertRedactedChangesetException {
    136141        this.changesetId = changesetId;
     142        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    137143        if (newLayer) {
    138144            this.ds = new DataSet();
    139145            this.layer = new OsmDataLayer(this.ds, tr("Reverted changeset") + tr(" [id: {0}]", String.valueOf(changesetId)), null);
     146            this.ods = ods;
    140147        } else {
    141             this.layer = MainApplication.getLayerManager().getEditLayer();
    142             this.ds = layer.data;
     148            this.layer = editLayer;
     149            this.ds = editLayer.data;
     150            this.ods = ods;
    143151        }
    144152        this.revertType = revertType;
     153        if ((revertType == RevertType.SELECTION || revertType == RevertType.SELECTION_WITH_UNDELETE)
     154                && (ods == null || ods.getAllSelected().isEmpty())) {
     155            throw new IllegalArgumentException("No selected elements with revert type " + revertType);
     156        }
    145157
    146158        OsmServerChangesetReader csr = new OsmServerChangesetReader(true);
  • applications/editors/josm/plugins/reverter/src/reverter/RevertChangesetTask.java

    r34953 r35310  
    1818import org.openstreetmap.josm.command.conflict.ConflictAddCommand;
    1919import org.openstreetmap.josm.data.UndoRedoHandler;
     20import org.openstreetmap.josm.data.osm.DataSet;
    2021import org.openstreetmap.josm.gui.MainApplication;
    2122import org.openstreetmap.josm.gui.Notification;
    2223import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     24import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2325import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2426import org.openstreetmap.josm.gui.util.GuiHelper;
     
    3335    private final RevertType revertType;
    3436    private boolean newLayer;
     37    private final DataSet oldDataSet;
    3538
    3639    private ChangesetReverter rev;
     
    5659        this.downloadConfirmed = autoConfirmDownload;
    5760        this.newLayer = newLayer;
     61        OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
     62        this.oldDataSet = editLayer == null ? null : editLayer.data;
    5863    }
    5964
     
    116121        progressMonitor.indeterminateSubTask(tr("Reverting changeset {0}", Long.toString(changesetId)));
    117122        try {
    118             rev = new ChangesetReverter(changesetId, revertType, newLayer, progressMonitor.createSubTaskMonitor(0, true));
     123            rev = new ChangesetReverter(changesetId, revertType, newLayer, oldDataSet, progressMonitor.createSubTaskMonitor(0, true));
    119124        } catch (final RevertRedactedChangesetException e) {
    120125            GuiHelper.runInEDT(() -> new Notification(
Note: See TracChangeset for help on using the changeset viewer.