Changeset 12718 in josm


Ignore:
Timestamp:
2017-09-04T00:50:22+02:00 (7 years ago)
Author:
Don-vip
Message:

see #13036 - see #15229 - see #15182 - make Commands depends only on a DataSet, not a Layer. This removes a lot of GUI dependencies

Location:
trunk
Files:
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r12696 r12718  
    137137     * The commands undo/redo handler.
    138138     */
    139     public final UndoRedoHandler undoRedo = MainApplication.undoRedo;
     139    public final UndoRedoHandler undoRedo = new UndoRedoHandler();
    140140
    141141    /**
     
    630630
    631631    /**
    632      * Gets the data set of the active edit layer.
    633      * @return That data set, <code>null</code> if there is no edit layer.
     632     * Gets the active edit data set.
     633     * @return That data set, <code>null</code>.
    634634     * @since 12691
    635635     */
    636     public DataSet getEditDataSet() {
    637         return null;
    638     }
     636    public abstract DataSet getEditDataSet();
     637
     638    /**
     639     * Sets the active data set.
     640     * @param ds New edit data set, or <code>null</code>
     641     * @since 12718
     642     */
     643    public abstract void setEditDataSet(DataSet ds);
     644
     645    /**
     646     * Determines if the list of data sets managed by JOSM contains {@code ds}.
     647     * @param ds the data set to look for
     648     * @return {@code true} if the list of data sets managed by JOSM contains {@code ds}
     649     * @since 12718
     650     */
     651    public abstract boolean containsDataSet(DataSet ds);
    639652
    640653    /**
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r12641 r12718  
    693693        // Delete the discarded inner ways
    694694        if (!discardedWays.isEmpty()) {
    695             Command deleteCmd = DeleteCommand.delete(getLayerManager().getEditLayer(), discardedWays, true);
     695            Command deleteCmd = DeleteCommand.delete(discardedWays, true);
    696696            if (deleteCmd != null) {
    697697                cmds.add(deleteCmd);
     
    10181018
    10191019        if (chunks.size() > 1) {
    1020             SplitWayResult split = SplitWayAction.splitWay(getLayerManager().getEditLayer(), way, chunks,
     1020            SplitWayResult split = SplitWayAction.splitWay(way, chunks,
    10211021                    Collections.<OsmPrimitive>emptyList(), SplitWayAction.Strategy.keepFirstChunk());
    10221022
     
    14671467            newRel.addMember(new RelationMember("inner", w));
    14681468        }
    1469         cmds.add(layer != null ? new AddCommand(layer, newRel) :
     1469        cmds.add(layer != null ? new AddCommand(layer.data, newRel) :
    14701470            new AddCommand(inner.iterator().next().getDataSet(), newRel));
    14711471        addedRelations.add(newRel);
     
    15381538        }
    15391539
    1540         OsmDataLayer layer = getLayerManager().getEditLayer();
    15411540        Relation newRel;
    15421541        switch (multiouters.size()) {
     
    15671566            }
    15681567            newRel.addMember(new RelationMember("outer", outer));
    1569             cmds.add(layer != null ? new AddCommand(layer, newRel) : new AddCommand(outer.getDataSet(), newRel));
     1568            cmds.add(new AddCommand(outer.getDataSet(), newRel));
    15701569        }
    15711570    }
  • trunk/src/org/openstreetmap/josm/actions/PurgeAction.java

    r12688 r12718  
    118118        layer = getLayerManager().getEditLayer();
    119119        toPurgeAdditionally = new ArrayList<>();
    120         PurgeCommand cmd = PurgeCommand.build(layer, sel, toPurgeAdditionally);
     120        PurgeCommand cmd = PurgeCommand.build(sel, toPurgeAdditionally);
    121121        modified = cmd.getParticipatingPrimitives().stream().anyMatch(OsmPrimitive::isModified);
    122122        return cmd;
  • trunk/src/org/openstreetmap/josm/actions/RedoAction.java

    r12641 r12718  
    99
    1010import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
    1112import org.openstreetmap.josm.gui.MainApplication;
    1213import org.openstreetmap.josm.gui.MapFrame;
    13 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1414import org.openstreetmap.josm.tools.Shortcut;
    1515
     
    1919 * @author imi
    2020 */
    21 public class RedoAction extends JosmAction implements OsmDataLayer.CommandQueueListener {
     21public class RedoAction extends JosmAction implements CommandQueueListener {
    2222
    2323    /**
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r12663 r12718  
    214214            }
    215215            if (wayToKeep != null) {
    216                 final SplitWayResult result = doSplitWay(getLayerManager().getEditLayer(), selectedWay, wayToKeep, newWays, sel);
     216                final SplitWayResult result = doSplitWay(selectedWay, wayToKeep, newWays, sel);
    217217                MainApplication.undoRedo.add(result.getCommand());
    218218                if (!result.getNewSelection().isEmpty()) {
     
    294294            toggleSaveState(); // necessary since #showDialog() does not handle it due to the non-modal dialog
    295295            if (getValue() == 1) {
    296                 SplitWayResult result = doSplitWay(MainApplication.getLayerManager().getEditLayer(),
    297                         selectedWay, list.getSelectedValue(), newWays, selection);
     296                SplitWayResult result = doSplitWay(selectedWay, list.getSelectedValue(), newWays, selection);
    298297                MainApplication.undoRedo.add(result.getCommand());
    299298                if (!result.getNewSelection().isEmpty()) {
     
    498497     * @param selection The list of currently selected primitives
    499498     * @return the result from the split operation
    500      */
     499     * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection)} instead
     500     */
     501    @Deprecated
    501502    public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks,
    502503            Collection<? extends OsmPrimitive> selection) {
    503         return splitWay(layer, way, wayChunks, selection, Strategy.keepLongestChunk());
     504        return splitWay(way, wayChunks, selection);
     505    }
     506
     507    /**
     508     * Splits the way {@code way} into chunks of {@code wayChunks} and replies
     509     * the result of this process in an instance of {@link SplitWayResult}.
     510     *
     511     * Note that changes are not applied to the data yet. You have to
     512     * submit the command in {@link SplitWayResult#getCommand()} first,
     513     * i.e. {@code Main.main.undoredo.add(result.getCommand())}.
     514     *
     515     * @param way the way to split. Must not be null.
     516     * @param wayChunks the list of way chunks into the way is split. Must not be null.
     517     * @param selection The list of currently selected primitives
     518     * @return the result from the split operation
     519     * @since 12718
     520     */
     521    public static SplitWayResult splitWay(Way way, List<List<Node>> wayChunks,
     522            Collection<? extends OsmPrimitive> selection) {
     523        return splitWay(way, wayChunks, selection, Strategy.keepLongestChunk());
    504524    }
    505525
     
    521541     * @return the result from the split operation
    522542     * @since 8954
    523      */
     543     * @deprecated to be removed end of 2017. Use {@link #splitWay(Way, List, Collection, Strategy)} instead
     544     */
     545    @Deprecated
    524546    public static SplitWayResult splitWay(OsmDataLayer layer, Way way, List<List<Node>> wayChunks,
     547            Collection<? extends OsmPrimitive> selection, Strategy splitStrategy) {
     548        return splitWay(way, wayChunks, selection, splitStrategy);
     549    }
     550
     551    /**
     552     * Splits the way {@code way} into chunks of {@code wayChunks} and replies
     553     * the result of this process in an instance of {@link SplitWayResult}.
     554     * The {@link org.openstreetmap.josm.actions.SplitWayAction.Strategy} is used to determine which
     555     * way chunk should reuse the old id and its history.
     556     *
     557     * Note that changes are not applied to the data yet. You have to
     558     * submit the command in {@link SplitWayResult#getCommand()} first,
     559     * i.e. {@code Main.main.undoredo.add(result.getCommand())}.
     560     *
     561     * @param way the way to split. Must not be null.
     562     * @param wayChunks the list of way chunks into the way is split. Must not be null.
     563     * @param selection The list of currently selected primitives
     564     * @param splitStrategy The strategy used to determine which way chunk should reuse the old id and its history
     565     * @return the result from the split operation
     566     * @since 12718
     567     */
     568    public static SplitWayResult splitWay(Way way, List<List<Node>> wayChunks,
    525569            Collection<? extends OsmPrimitive> selection, Strategy splitStrategy) {
    526570        // build a list of commands, and also a new selection list
     
    534578        final Way wayToKeep = splitStrategy.determineWayToKeep(newWays);
    535579
    536         return wayToKeep != null ? doSplitWay(layer, way, wayToKeep, newWays, newSelection) : null;
    537     }
    538 
    539     static SplitWayResult doSplitWay(OsmDataLayer layer, Way way, Way wayToKeep, List<Way> newWays,
    540                                    List<OsmPrimitive> newSelection) {
     580        return wayToKeep != null ? doSplitWay(way, wayToKeep, newWays, newSelection) : null;
     581    }
     582
     583    static SplitWayResult doSplitWay(Way way, Way wayToKeep, List<Way> newWays, List<OsmPrimitive> newSelection) {
    541584
    542585        Collection<Command> commandList = new ArrayList<>(newWays.size());
     
    550593        final Way changedWay = new Way(way);
    551594        changedWay.setNodes(wayToKeep.getNodes());
    552         commandList.add(layer != null ? new ChangeCommand(layer, way, changedWay) : new ChangeCommand(way.getDataSet(), way, changedWay));
     595        commandList.add(new ChangeCommand(way.getDataSet(), way, changedWay));
    553596        if (!isMapModeDraw && !newSelection.contains(way)) {
    554597            newSelection.add(way);
     
    561604        }
    562605        for (Way wayToAdd : newWays) {
    563             commandList.add(layer != null ? new AddCommand(layer, wayToAdd) : new AddCommand(way.getDataSet(), wayToAdd));
     606            commandList.add(new AddCommand(way.getDataSet(), wayToAdd));
    564607        }
    565608
     
    688731
    689732            if (c != null) {
    690                 commandList.add(layer != null ? new ChangeCommand(layer, r, c) : new ChangeCommand(r.getDataSet(), r, c));
     733                commandList.add(new ChangeCommand(r.getDataSet(), r, c));
    691734            }
    692735        }
     
    741784     * @param selection The list of currently selected primitives
    742785     * @return the result from the split operation
    743      */
     786     * @deprecated to be removed end of 2017. Use {@link #split(Way, List, Collection) instead}
     787     */
     788    @Deprecated
    744789    public static SplitWayResult split(OsmDataLayer layer, Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection) {
     790        return split(way, atNodes, selection);
     791    }
     792
     793    /**
     794     * Splits the way {@code way} at the nodes in {@code atNodes} and replies
     795     * the result of this process in an instance of {@link SplitWayResult}.
     796     *
     797     * Note that changes are not applied to the data yet. You have to
     798     * submit the command in {@link SplitWayResult#getCommand()} first,
     799     * i.e. {@code Main.main.undoredo.add(result.getCommand())}.
     800     *
     801     * Replies null if the way couldn't be split at the given nodes.
     802     *
     803     * @param way the way to split. Must not be null.
     804     * @param atNodes the list of nodes where the way is split. Must not be null.
     805     * @param selection The list of currently selected primitives
     806     * @return the result from the split operation
     807     * @since 12718
     808     */
     809    public static SplitWayResult split(Way way, List<Node> atNodes, Collection<? extends OsmPrimitive> selection) {
    745810        List<List<Node>> chunks = buildSplitChunks(way, atNodes);
    746         return chunks != null ? splitWay(layer, way, chunks, selection) : null;
     811        return chunks != null ? splitWay(way, chunks, selection) : null;
    747812    }
    748813
  • trunk/src/org/openstreetmap/josm/actions/UndoAction.java

    r12641 r12718  
    99
    1010import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
    1112import org.openstreetmap.josm.gui.MainApplication;
    1213import org.openstreetmap.josm.gui.MapFrame;
    13 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1414import org.openstreetmap.josm.tools.Shortcut;
    1515
     
    1919 * @author imi
    2020 */
    21 public class UndoAction extends JosmAction implements OsmDataLayer.CommandQueueListener {
     21public class UndoAction extends JosmAction implements CommandQueueListener {
    2222
    2323    /**
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r12641 r12718  
    151151        Command c;
    152152        if (ctrl) {
    153             c = DeleteCommand.deleteWithReferences(editLayer, lm.getEditDataSet().getSelected());
     153            c = DeleteCommand.deleteWithReferences(lm.getEditDataSet().getSelected());
    154154        } else {
    155             c = DeleteCommand.delete(editLayer, lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */);
     155            c = DeleteCommand.delete(lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */);
    156156        }
    157157        // if c is null, an error occurred or the user aborted. Don't do anything in that case.
     
    352352        CheckParameterUtil.ensureParameterNotNull(toDelete, "toDelete");
    353353
    354         final Command cmd = DeleteCommand.delete(layer, toDelete);
     354        final Command cmd = DeleteCommand.delete(toDelete);
    355355        if (cmd != null) {
    356356            // cmd can be null if the user cancels dialogs DialogCommand displays
     
    404404    private Command buildDeleteCommands(MouseEvent e, int modifiers, boolean silent) {
    405405        DeleteParameters parameters = getDeleteParameters(e, modifiers);
    406         OsmDataLayer editLayer = getLayerManager().getEditLayer();
    407406        switch (parameters.mode) {
    408407        case node:
    409             return DeleteCommand.delete(editLayer, Collections.singleton(parameters.nearestNode), false, silent);
     408            return DeleteCommand.delete(Collections.singleton(parameters.nearestNode), false, silent);
    410409        case node_with_references:
    411             return DeleteCommand.deleteWithReferences(editLayer, Collections.singleton(parameters.nearestNode), silent);
     410            return DeleteCommand.deleteWithReferences(Collections.singleton(parameters.nearestNode), silent);
    412411        case segment:
    413             return DeleteCommand.deleteWaySegment(editLayer, parameters.nearestSegment);
     412            return DeleteCommand.deleteWaySegment(parameters.nearestSegment);
    414413        case way:
    415             return DeleteCommand.delete(editLayer, Collections.singleton(parameters.nearestSegment.way), false, silent);
     414            return DeleteCommand.delete(Collections.singleton(parameters.nearestSegment.way), false, silent);
    416415        case way_with_nodes:
    417             return DeleteCommand.delete(editLayer, Collections.singleton(parameters.nearestSegment.way), true, silent);
     416            return DeleteCommand.delete(Collections.singleton(parameters.nearestSegment.way), true, silent);
    418417        case way_with_references:
    419             return DeleteCommand.deleteWithReferences(editLayer, Collections.singleton(parameters.nearestSegment.way), true);
     418            return DeleteCommand.deleteWithReferences(Collections.singleton(parameters.nearestSegment.way), true);
    420419        default:
    421420            return null;
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java

    r12641 r12718  
    488488                    newWay.setNodes(nodes);
    489489                    if (nodes.size() < 2) {
    490                         final Command deleteCmd = DeleteCommand.delete(getLayerManager().getEditLayer(), Collections.singleton(targetWay), true);
     490                        final Command deleteCmd = DeleteCommand.delete(Collections.singleton(targetWay), true);
    491491                        if (deleteCmd != null) {
    492492                            MainApplication.undoRedo.add(deleteCmd);
     
    500500                            tr("Error"), JOptionPane.ERROR_MESSAGE);
    501501                } else {
    502                     final Command deleteCmd = DeleteCommand.delete(getLayerManager().getEditLayer(), Collections.singleton(candidateNode), true);
     502                    final Command deleteCmd = DeleteCommand.delete(Collections.singleton(candidateNode), true);
    503503                    if (deleteCmd != null) {
    504504                        MainApplication.undoRedo.add(deleteCmd);
  • trunk/src/org/openstreetmap/josm/actions/relation/RecentRelationsAction.java

    r12663 r12718  
    1919
    2020import org.openstreetmap.josm.actions.JosmAction;
     21import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
    2122import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    2223import org.openstreetmap.josm.data.osm.Relation;
     
    2526import org.openstreetmap.josm.gui.layer.Layer;
    2627import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    27 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    2828import org.openstreetmap.josm.tools.ImageProvider;
    2929import org.openstreetmap.josm.tools.Shortcut;
  • trunk/src/org/openstreetmap/josm/command/AddCommand.java

    r12663 r12718  
    4545     * @param layer The data layer. Must not be {@code null}
    4646     * @param osm The primitive to add
     47     * @deprecated to be removed end of 2017. Use {@link #AddCommand(DataSet, OsmPrimitive)} instead
    4748     */
     49    @Deprecated
    4850    public AddCommand(OsmDataLayer layer, OsmPrimitive osm) {
    4951        super(layer);
  • trunk/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    r11609 r12718  
    5959     * @param toSelect The OSM primitives to select at the end. Can be {@code null}
    6060     * @param layer The target data layer. Must not be {@code null}
    61      */
     61     * @deprecated to be removed end of 2017. Use {@link #AddPrimitivesCommand(List, List, DataSet)} instead
     62     */
     63    @Deprecated
    6264    public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect, OsmDataLayer layer) {
    6365        super(layer);
     66        init(data, toSelect);
     67    }
     68
     69    /**
     70     * Constructs a new {@code AddPrimitivesCommand} to add data to the given data set.
     71     * @param data The OSM primitives data to add. Must not be {@code null}
     72     * @param toSelect The OSM primitives to select at the end. Can be {@code null}
     73     * @param ds The target data set. Must not be {@code null}
     74     * @since 12718
     75     */
     76    public AddPrimitivesCommand(List<PrimitiveData> data, List<PrimitiveData> toSelect, DataSet ds) {
     77        super(ds);
    6478        init(data, toSelect);
    6579    }
  • trunk/src/org/openstreetmap/josm/command/ChangeCommand.java

    r12663 r12718  
    4545     * @param osm The existing primitive to modify
    4646     * @param newOsm The new primitive
     47     * @deprecated to be removed end of 2017. Use {@link #ChangeCommand(DataSet, OsmPrimitive, OsmPrimitive)} instead
    4748     */
     49    @Deprecated
    4850    public ChangeCommand(OsmDataLayer layer, OsmPrimitive osm, OsmPrimitive newOsm) {
    4951        super(layer);
  • trunk/src/org/openstreetmap/josm/command/Command.java

    r12636 r12718  
    3535 * one atomic action on a specific dataset, such as move or delete.
    3636 *
    37  * The command remembers the {@link OsmDataLayer} it is operating on.
     37 * The command remembers the {@link DataSet} it is operating on.
    3838 *
    3939 * @author imi
     
    135135    private Map<OsmPrimitive, PrimitiveData> cloneMap = new HashMap<>();
    136136
    137     /** the layer which this command is applied to */
     137    /**
     138     * the layer which this command is applied to
     139     * @deprecated to be removed end of 2017. Use {@link #data} instead
     140     */
     141    @Deprecated
    138142    private final OsmDataLayer layer;
    139143
     
    146150    public Command() {
    147151        this.layer = MainApplication.getLayerManager().getEditLayer();
    148         this.data = layer != null ? layer.data : null;
     152        this.data = layer != null ? layer.data : Main.main.getEditDataSet();
    149153    }
    150154
     
    154158     * @param layer the data layer. Must not be null.
    155159     * @throws IllegalArgumentException if layer is null
    156      */
     160     * @deprecated to be removed end of 2017. Use {@link #Command(DataSet)} instead
     161     */
     162    @Deprecated
    157163    public Command(OsmDataLayer layer) {
    158164        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
     
    216222     * @param oldLayer the old layer that was removed
    217223     * @return true if this command is invalid after that layer is removed.
    218      */
     224     * @deprecated to be removed end of 2017.
     225     */
     226    @Deprecated
    219227    public boolean invalidBecauselayerRemoved(Layer oldLayer) {
    220228        return layer == oldLayer;
     
    234242     * Replies the layer this command is (or was) applied to.
    235243     * @return the layer this command is (or was) applied to
    236      */
     244     * @deprecated to be removed end of 2017. Use {@link #getAffectedDataSet} instead
     245     */
     246    @Deprecated
    237247    protected OsmDataLayer getLayer() {
    238248        return layer;
     
    371381     * Invalidate all layers that were affected by this command.
    372382     * @see Layer#invalidate()
    373      */
     383     * @deprecated to be removed end of 2017.
     384     */
     385    @Deprecated
    374386    public void invalidateAffectedLayers() {
    375387        OsmDataLayer layer = getLayer();
  • trunk/src/org/openstreetmap/josm/command/DeleteCommand.java

    r12663 r12718  
    108108
    109109    /**
    110      * Constructor for a single data item. Use the collection constructor to delete multiple
    111      * objects.
     110     * Constructor for a single data item. Use the collection constructor to delete multiple objects.
    112111     *
    113112     * @param layer the layer context for deleting this primitive. Must not be null.
     
    115114     * @throws IllegalArgumentException if data is null
    116115     * @throws IllegalArgumentException if layer is null
    117      */
     116     * @deprecated to be removed end of 2017. Use {@link #DeleteCommand(DataSet, OsmPrimitive)} instead
     117     */
     118    @Deprecated
    118119    public DeleteCommand(OsmDataLayer layer, OsmPrimitive data) {
    119120        this(layer, Collections.singleton(data));
     
    121122
    122123    /**
    123      * Constructor for a collection of data to be deleted in the context of
    124      * a specific layer
     124     * Constructor for a single data item. Use the collection constructor to delete multiple objects.
     125     *
     126     * @param dataset the data set context for deleting this primitive. Must not be null.
     127     * @param data the primitive to delete. Must not be null.
     128     * @throws IllegalArgumentException if data is null
     129     * @throws IllegalArgumentException if layer is null
     130     * @since 12718
     131     */
     132    public DeleteCommand(DataSet dataset, OsmPrimitive data) {
     133        this(dataset, Collections.singleton(data));
     134    }
     135
     136    /**
     137     * Constructor for a collection of data to be deleted in the context of a specific layer
    125138     *
    126139     * @param layer the layer context for deleting these primitives. Must not be null.
     
    128141     * @throws IllegalArgumentException if layer is null
    129142     * @throws IllegalArgumentException if data is null or empty
    130      */
     143     * @deprecated to be removed end of 2017. Use {@link #DeleteCommand(DataSet, Collection)} instead
     144     */
     145    @Deprecated
    131146    public DeleteCommand(OsmDataLayer layer, Collection<? extends OsmPrimitive> data) {
    132147        super(layer);
     
    137152
    138153    /**
    139      * Constructor for a collection of data to be deleted in the context of
    140      * a specific data set
     154     * Constructor for a collection of data to be deleted in the context of a specific data set
    141155     *
    142156     * @param dataset the dataset context for deleting these primitives. Must not be null.
     
    286300     * @return command A command to perform the deletions, or null of there is nothing to delete.
    287301     * @throws IllegalArgumentException if layer is null
    288      */
     302     * @deprecated to be removed end of 2017. Use {@link #deleteWithReferences(Collection, boolean)} instead
     303     */
     304    @Deprecated
    289305    public static Command deleteWithReferences(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection, boolean silent) {
    290         CheckParameterUtil.ensureParameterNotNull(layer, "layer");
     306        return deleteWithReferences(selection, silent);
     307    }
     308
     309    /**
     310     * Delete the primitives and everything they reference.
     311     *
     312     * If a node is deleted, the node and all ways and relations the node is part of are deleted as well.
     313     * If a way is deleted, all relations the way is member of are also deleted.
     314     * If a way is deleted, only the way and no nodes are deleted.
     315     *
     316     * @param selection The list of all object to be deleted.
     317     * @param silent  Set to true if the user should not be bugged with additional dialogs
     318     * @return command A command to perform the deletions, or null of there is nothing to delete.
     319     * @throws IllegalArgumentException if layer is null
     320     * @since 12718
     321     */
     322    public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection, boolean silent) {
    291323        if (selection == null || selection.isEmpty()) return null;
    292324        Set<OsmPrimitive> parents = OsmPrimitive.getReferrer(selection);
     
    297329        if (!silent && !checkAndConfirmOutlyingDelete(parents, null))
    298330            return null;
    299         return new DeleteCommand(layer, parents);
     331        return new DeleteCommand(parents.iterator().next().getDataSet(), parents);
    300332    }
    301333
     
    307339     * If a way is deleted, only the way and no nodes are deleted.
    308340     *
    309      * @param layer the {@link OsmDataLayer} in whose context primitives are deleted. Must not be null.
     341     * @param layer unused
    310342     * @param selection The list of all object to be deleted.
    311343     * @return command A command to perform the deletions, or null of there is nothing to delete.
    312344     * @throws IllegalArgumentException if layer is null
    313      */
     345     * @deprecated to be removed end of 2017. Use {@link #deleteWithReferences(Collection)} instead
     346     */
     347    @Deprecated
    314348    public static Command deleteWithReferences(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) {
    315         return deleteWithReferences(layer, selection, false);
     349        return deleteWithReferences(selection);
     350    }
     351
     352    /**
     353     * Delete the primitives and everything they reference.
     354     *
     355     * If a node is deleted, the node and all ways and relations the node is part of are deleted as well.
     356     * If a way is deleted, all relations the way is member of are also deleted.
     357     * If a way is deleted, only the way and no nodes are deleted.
     358     *
     359     * @param selection The list of all object to be deleted.
     360     * @return command A command to perform the deletions, or null of there is nothing to delete.
     361     * @throws IllegalArgumentException if layer is null
     362     * @since 12718
     363     */
     364    public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection) {
     365        return deleteWithReferences(selection, false);
    316366    }
    317367
     
    325375     * they are part of a relation, inform the user and do not delete.
    326376     *
    327      * @param layer the {@link OsmDataLayer} in whose context the primitives are deleted
     377     * @param layer unused
    328378     * @param selection the objects to delete.
    329379     * @return command a command to perform the deletions, or null if there is nothing to delete.
    330      */
     380     * @deprecated to be removed end of 2017. Use {@link #delete(Collection)} instead
     381     */
     382    @Deprecated
    331383    public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) {
    332         return delete(layer, selection, true, false);
     384        return delete(selection);
     385    }
     386
     387    /**
     388     * Try to delete all given primitives.
     389     *
     390     * If a node is used by a way, it's removed from that way. If a node or a way is used by a
     391     * relation, inform the user and do not delete.
     392     *
     393     * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If
     394     * they are part of a relation, inform the user and do not delete.
     395     *
     396     * @param selection the objects to delete.
     397     * @return command a command to perform the deletions, or null if there is nothing to delete.
     398     * @since 12718
     399     */
     400    public static Command delete(Collection<? extends OsmPrimitive> selection) {
     401        return delete(selection, true, false);
    333402    }
    334403
     
    376445     * they are part of a relation, inform the user and do not delete.
    377446     *
    378      * @param layer the {@link OsmDataLayer} in whose context the primitives are deleted
     447     * @param layer unused
    379448     * @param selection the objects to delete.
    380449     * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well
    381450     * @return command a command to perform the deletions, or null if there is nothing to delete.
    382      */
     451     * @deprecated to be removed end of 2017. Use {@link #delete(Collection, boolean)} instead
     452     */
     453    @Deprecated
    383454    public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection,
    384455            boolean alsoDeleteNodesInWay) {
    385         return delete(layer, selection, alsoDeleteNodesInWay, false /* not silent */);
     456        return delete(selection, alsoDeleteNodesInWay);
    386457    }
    387458
     
    395466     * they are part of a relation, inform the user and do not delete.
    396467     *
    397      * @param layer the {@link OsmDataLayer} in whose context the primitives are deleted
     468     * @param selection the objects to delete.
     469     * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well
     470     * @return command a command to perform the deletions, or null if there is nothing to delete.
     471     * @since 12718
     472     */
     473    public static Command delete(Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay) {
     474        return delete(selection, alsoDeleteNodesInWay, false /* not silent */);
     475    }
     476
     477    /**
     478     * Try to delete all given primitives.
     479     *
     480     * If a node is used by a way, it's removed from that way. If a node or a way is used by a
     481     * relation, inform the user and do not delete.
     482     *
     483     * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If
     484     * they are part of a relation, inform the user and do not delete.
     485     *
     486     * @param layer unused
    398487     * @param selection the objects to delete.
    399488     * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well
    400489     * @param silent set to true if the user should not be bugged with additional questions
    401490     * @return command a command to perform the deletions, or null if there is nothing to delete.
    402      */
     491     * @deprecated to be removed end of 2017. Use {@link #delete(Collection, boolean, boolean)} instead
     492     */
     493    @Deprecated
    403494    public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection,
    404495            boolean alsoDeleteNodesInWay, boolean silent) {
     496        return delete(selection, alsoDeleteNodesInWay, silent);
     497    }
     498
     499    /**
     500     * Try to delete all given primitives.
     501     *
     502     * If a node is used by a way, it's removed from that way. If a node or a way is used by a
     503     * relation, inform the user and do not delete.
     504     *
     505     * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If
     506     * they are part of a relation, inform the user and do not delete.
     507     *
     508     * @param selection the objects to delete.
     509     * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well
     510     * @param silent set to true if the user should not be bugged with additional questions
     511     * @return command a command to perform the deletions, or null if there is nothing to delete.
     512     * @since 12718
     513     */
     514    public static Command delete(Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay, boolean silent) {
    405515        if (selection == null || selection.isEmpty())
    406516            return null;
     
    460570        //
    461571        if (!primitivesToDelete.isEmpty()) {
    462             cmds.add(layer != null ? new DeleteCommand(layer, primitivesToDelete) :
    463                 new DeleteCommand(primitivesToDelete.iterator().next().getDataSet(), primitivesToDelete));
     572            cmds.add(new DeleteCommand(primitivesToDelete.iterator().next().getDataSet(), primitivesToDelete));
    464573        }
    465574
     
    469578    /**
    470579     * Create a command that deletes a single way segment. The way may be split by this.
    471      * @param layer The layer the segment is in.
     580     * @param layer unused
    472581     * @param ws The way segment that should be deleted
    473582     * @return A matching command to safely delete that segment.
    474      */
     583     * @deprecated to be removed end of 2017. Use {@link #deleteWaySegment(WaySegment)} instead
     584     */
     585    @Deprecated
    475586    public static Command deleteWaySegment(OsmDataLayer layer, WaySegment ws) {
     587        return deleteWaySegment(ws);
     588    }
     589
     590    /**
     591     * Create a command that deletes a single way segment. The way may be split by this.
     592     * @param ws The way segment that should be deleted
     593     * @return A matching command to safely delete that segment.
     594     * @since 12718
     595     */
     596    public static Command deleteWaySegment(WaySegment ws) {
    476597        if (ws.way.getNodesCount() < 3)
    477             return delete(layer, Collections.singleton(ws.way), false);
     598            return delete(Collections.singleton(ws.way), false);
    478599
    479600        if (ws.way.isClosed()) {
     
    506627            return new ChangeCommand(ws.way, wnew);
    507628        } else {
    508             SplitWayResult split = SplitWayAction.splitWay(layer, ws.way, Arrays.asList(n1, n2), Collections.<OsmPrimitive>emptyList());
     629            SplitWayResult split = SplitWayAction.splitWay(ws.way, Arrays.asList(n1, n2), Collections.<OsmPrimitive>emptyList());
    509630            return split != null ? split.getCommand() : null;
    510631        }
  • trunk/src/org/openstreetmap/josm/command/PurgeCommand.java

    r12688 r12718  
    5454     * @param toPurge primitives to purge
    5555     * @param makeIncomplete primitives to make incomplete
     56     * @deprecated to be removed end of 2017. Use {@link #PurgeCommand(DataSet, Collection, Collection)} instead
    5657     */
     58    @Deprecated
    5759    public PurgeCommand(OsmDataLayer layer, Collection<OsmPrimitive> toPurge, Collection<OsmPrimitive> makeIncomplete) {
    5860        super(layer);
     
    319321     * @return command to purge selected OSM primitives
    320322     * @since 12688
     323     * @deprecated to be removed end of 2017. Use {@link #build(Collection, List)} instead
    321324     */
     325    @Deprecated
    322326    public static PurgeCommand build(OsmDataLayer layer, Collection<OsmPrimitive> sel, List<OsmPrimitive> toPurgeAdditionally) {
     327        return build(sel, toPurgeAdditionally);
     328    }
     329
     330    /**
     331     * Creates a new {@code PurgeCommand} to purge selected OSM primitives.
     332     * @param sel selected OSM primitives
     333     * @param toPurgeAdditionally optional list that will be filled with primitives to be purged that have not been in the selection
     334     * @return command to purge selected OSM primitives
     335     * @since 12718
     336     */
     337    public static PurgeCommand build(Collection<OsmPrimitive> sel, List<OsmPrimitive> toPurgeAdditionally) {
    323338        Set<OsmPrimitive> toPurge = new HashSet<>(sel);
    324339        // finally, contains all objects that are purged
     
    423438        }
    424439
    425         return layer != null ? new PurgeCommand(layer, toPurgeChecked, makeIncomplete)
    426                 : new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete);
     440        return new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete);
    427441    }
    428442
  • trunk/src/org/openstreetmap/josm/command/SequenceCommand.java

    r11874 r12718  
    1212
    1313import org.openstreetmap.josm.data.osm.OsmPrimitive;
     14import org.openstreetmap.josm.gui.layer.Layer;
    1415import org.openstreetmap.josm.tools.ImageProvider;
    1516import org.openstreetmap.josm.tools.Utils;
     
    136137    }
    137138
     139    /**
     140     * Invalidate all layers that were affected by this command.
     141     * @see Layer#invalidate()
     142     * @deprecated to be removed end of 2017.
     143     */
    138144    @Override
     145    @Deprecated
    139146    public void invalidateAffectedLayers() {
    140147        super.invalidateAffectedLayers();
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java

    r12672 r12718  
    1616import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    1717import org.openstreetmap.josm.data.osm.OsmPrimitive;
    18 import org.openstreetmap.josm.gui.MainApplication;
    1918import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2019import org.openstreetmap.josm.tools.ImageProvider;
     
    3332     * @param layer the data layer. Must not be null.
    3433     * @param conflict the conflict to add
     34     * @deprecated to be removed end of 2017. Use {@link #ConflictAddCommand(DataSet, Conflict)} instead
    3535     */
     36    @Deprecated
    3637    public ConflictAddCommand(OsmDataLayer layer, Conflict<? extends OsmPrimitive> conflict) {
    3738        super(layer);
     
    5657                        + "''{1}''.<br>"
    5758                        + "This conflict cannot be added.</html>",
    58                         Utils.escapeReservedCharactersHTML(getLayer().getName()),
     59                        Utils.escapeReservedCharactersHTML(getAffectedDataSet().getName()),
    5960                        Utils.escapeReservedCharactersHTML(conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance()))
    6061                ),
     
    7778    @Override
    7879    public void undoCommand() {
    79         if (MainApplication.isDisplayingMapView() && !MainApplication.getLayerManager().containsLayer(getLayer())) {
     80        DataSet ds = getAffectedDataSet();
     81        if (!Main.main.containsDataSet(ds)) {
    8082            Logging.warn(tr("Layer ''{0}'' does not exist any more. Cannot remove conflict for object ''{1}''.",
    81                     getLayer().getName(),
     83                    ds.getName(),
    8284                    conflict.getMy().getDisplayName(DefaultNameFormatter.getInstance())
    8385            ));
    8486            return;
    8587        }
    86         getAffectedDataSet().getConflicts().remove(conflict);
     88        ds.getConflicts().remove(conflict);
    8789    }
    8890
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java

    r12672 r12718  
    66import java.util.Objects;
    77
     8import org.openstreetmap.josm.Main;
    89import org.openstreetmap.josm.command.Command;
    910import org.openstreetmap.josm.data.conflict.Conflict;
    1011import org.openstreetmap.josm.data.conflict.ConflictCollection;
    1112import org.openstreetmap.josm.data.osm.DataSet;
    12 import org.openstreetmap.josm.gui.MainApplication;
    1313import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1414import org.openstreetmap.josm.tools.Logging;
     
    2424public abstract class ConflictResolveCommand extends Command {
    2525    /** the list of resolved conflicts */
    26     private final ConflictCollection resolvedConflicts;
     26    private final ConflictCollection resolvedConflicts = new ConflictCollection();
    2727
    2828    /**
     
    3030     */
    3131    public ConflictResolveCommand() {
    32         super();
    33         resolvedConflicts = new ConflictCollection();
     32        // Do nothing
    3433    }
    3534
     
    3736     * Constructs a new {@code ConflictResolveCommand} in the context of a given data layer.
    3837     * @param layer the data layer. Must not be null.
     38     * @deprecated to be removed end of 2017. Use {@link #ConflictResolveCommand(DataSet)} instead
    3939     */
     40    @Deprecated
    4041    public ConflictResolveCommand(OsmDataLayer layer) {
    4142        super(layer);
    42         resolvedConflicts = new ConflictCollection();
     43    }
     44
     45    /**
     46     * Constructs a new {@code ConflictResolveCommand} in the context of a given data set.
     47     * @param ds the data set. Must not be null.
     48     */
     49    public ConflictResolveCommand(DataSet ds) {
     50        super(ds);
    4351    }
    4452
     
    5664    /**
    5765     * reconstitutes all remembered conflicts. Add the remembered conflicts to the
    58      * set of conflicts of the {@link OsmDataLayer} this command was applied to.
     66     * set of conflicts of the {@link DataSet} this command was applied to.
    5967     *
    6068     */
     
    7280        super.undoCommand();
    7381
    74         if (MainApplication.isDisplayingMapView()) {
    75             if (!MainApplication.getLayerManager().containsLayer(getLayer())) {
    76                 Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
    77                         this.toString(),
    78                         getLayer().toString()
    79                 ));
    80                 return;
    81             }
     82        DataSet ds = getAffectedDataSet();
     83        if (!Main.main.containsDataSet(ds)) {
     84            Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
     85                    this.toString(),
     86                    ds.getName()
     87            ));
     88            return;
     89        }
    8290
    83             MainApplication.getLayerManager().setActiveLayer(getLayer());
    84         }
     91        Main.main.setEditDataSet(ds);
    8592        reconstituteConflicts();
    8693    }
  • trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java

    r12672 r12718  
    1010import javax.swing.Icon;
    1111
     12import org.openstreetmap.josm.Main;
    1213import org.openstreetmap.josm.data.conflict.Conflict;
    1314import org.openstreetmap.josm.data.osm.DataSet;
     
    1516import org.openstreetmap.josm.data.osm.Relation;
    1617import org.openstreetmap.josm.data.osm.RelationMember;
    17 import org.openstreetmap.josm.gui.MainApplication;
    18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1918import org.openstreetmap.josm.tools.ImageProvider;
    2019import org.openstreetmap.josm.tools.Logging;
     
    7271    @Override
    7372    public void undoCommand() {
    74         OsmDataLayer layer = getLayer();
    75         if (!MainApplication.getLayerManager().containsLayer(layer)) {
     73        DataSet editDs = getAffectedDataSet();
     74        if (!Main.main.containsDataSet(editDs)) {
    7675            Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
    7776                    this.toString(),
    78                     layer.toString()
     77                    editDs.getName()
    7978            ));
    8079            return;
    8180        }
    8281
    83         MainApplication.getLayerManager().setActiveLayer(layer);
    84         DataSet editDs = MainApplication.getLayerManager().getEditDataSet();
     82        Main.main.setEditDataSet(editDs);
    8583
    8684        // restore the former state
  • trunk/src/org/openstreetmap/josm/data/UndoRedoHandler.java

    r12691 r12718  
    1111import org.openstreetmap.josm.data.osm.DataSet;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
    13 import org.openstreetmap.josm.gui.MainApplication;
    14 import org.openstreetmap.josm.gui.layer.Layer;
    15 import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
    16 import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
    17 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
    18 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    19 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    20 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    2113import org.openstreetmap.josm.tools.CheckParameterUtil;
    2214
    2315/**
    24  * This is the global undo/redo handler for all {@link OsmDataLayer}s.
     16 * This is the global undo/redo handler for all {@link DataSet}s.
    2517 * <p>
    26  * If you want to change a data layer, you can use {@link #add(Command)} to execute a command on it and make that command undoable.
     18 * If you want to change a data set, you can use {@link #add(Command)} to execute a command on it and make that command undoable.
    2719 */
    28 public class UndoRedoHandler implements LayerChangeListener {
     20public class UndoRedoHandler {
    2921
    3022    /**
     
    4537     */
    4638    public UndoRedoHandler() {
    47         MainApplication.getLayerManager().addLayerChangeListener(this);
     39        // Do nothing
     40    }
     41
     42    /**
     43     * A listener that gets notified of command queue (undo/redo) size changes.
     44     * @since 12718 (moved from {@code OsmDataLayer}
     45     */
     46    @FunctionalInterface
     47    public interface CommandQueueListener {
     48        /**
     49         * Notifies the listener about the new queue size
     50         * @param queueSize Undo stack size
     51         * @param redoSize Redo stack size
     52         */
     53        void commandChanged(int queueSize, int redoSize);
    4854    }
    4955
     
    9298        }
    9399        addNoRedraw(c);
    94         c.invalidateAffectedLayers();
    95100        afterAdd();
    96101
     
    125130                final Command c = commands.removeLast();
    126131                c.undoCommand();
    127                 c.invalidateAffectedLayers();
    128132                redoCommands.addFirst(c);
    129133                if (commands.isEmpty()) {
     
    161165            final Command c = redoCommands.removeFirst();
    162166            c.executeCommand();
    163             c.invalidateAffectedLayers();
    164167            commands.add(c);
    165168            if (redoCommands.isEmpty()) {
     
    197200
    198201    /**
    199      * Resets all commands that affect the given layer.
    200      * @param layer The layer that was affected.
    201      */
    202     public void clean(Layer layer) {
    203         if (layer == null)
     202     * Resets all commands that affect the given dataset.
     203     * @param dataSet The data set that was affected.
     204     * @since 12718
     205     */
     206    public void clean(DataSet dataSet) {
     207        if (dataSet == null)
    204208            return;
    205209        boolean changed = false;
    206210        for (Iterator<Command> it = commands.iterator(); it.hasNext();) {
    207             if (it.next().invalidBecauselayerRemoved(layer)) {
     211            if (it.next().getAffectedDataSet() == dataSet) {
    208212                it.remove();
    209213                changed = true;
     
    211215        }
    212216        for (Iterator<Command> it = redoCommands.iterator(); it.hasNext();) {
    213             if (it.next().invalidBecauselayerRemoved(layer)) {
     217            if (it.next().getAffectedDataSet() == dataSet) {
    214218                it.remove();
    215219                changed = true;
     
    219223            fireCommandsChanged();
    220224        }
    221     }
    222 
    223     @Override
    224     public void layerRemoving(LayerRemoveEvent e) {
    225         clean(e.getRemovedLayer());
    226     }
    227 
    228     @Override
    229     public void layerAdded(LayerAddEvent e) {
    230         // Do nothing
    231     }
    232 
    233     @Override
    234     public void layerOrderChanged(LayerOrderChangeEvent e) {
    235         // Do nothing
    236225    }
    237226
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r12672 r12718  
    169169    private final List<AbstractDatasetChangedEvent> cachedEvents = new ArrayList<>();
    170170
     171    private String name;
    171172    private UploadPolicy uploadPolicy;
    172173
     
    13601361    }
    13611362
     1363    /**
     1364     * Returns the name of this data set (optional).
     1365     * @return the name of this data set. Can be {@code null}
     1366     * @since 12718
     1367     */
     1368    public String getName() {
     1369        return name;
     1370    }
     1371
     1372    /**
     1373     * Sets the name of this data set.
     1374     * @param name the new name of this data set. Can be {@code null} to reset it
     1375     * @since 12718
     1376     */
     1377    public void setName(String name) {
     1378        this.name = name;
     1379    }
     1380
    13621381    /* --------------------------------------------------------------------------------- */
    13631382    /* interface ProjectionChangeListner                                                 */
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r12667 r12718  
    2323import org.openstreetmap.josm.data.osm.search.SearchCompiler.NotOutsideDataSourceArea;
    2424import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor;
    25 import org.openstreetmap.josm.gui.MainApplication;
    2625import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2726import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    331330        }
    332331        if (!primitivesToDelete.isEmpty()) {
    333             return DeleteCommand.delete(MainApplication.getLayerManager().getEditLayer(), primitivesToDelete);
     332            return DeleteCommand.delete(primitivesToDelete);
    334333        } else {
    335334            return null;
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12695 r12718  
    7272import org.openstreetmap.josm.data.Bounds;
    7373import org.openstreetmap.josm.data.UndoRedoHandler;
     74import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
    7475import org.openstreetmap.josm.data.Version;
    7576import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder;
     
    8485import org.openstreetmap.josm.gui.io.SaveLayersDialog;
    8586import org.openstreetmap.josm.gui.layer.AutosaveTask;
     87import org.openstreetmap.josm.gui.layer.Layer;
     88import org.openstreetmap.josm.gui.layer.LayerManager.LayerAddEvent;
     89import org.openstreetmap.josm.gui.layer.LayerManager.LayerChangeListener;
     90import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent;
     91import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent;
    8692import org.openstreetmap.josm.gui.layer.MainLayerManager;
    87 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
     93import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    8894import org.openstreetmap.josm.gui.layer.TMSLayer;
    8995import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
     
    187193    /**
    188194     * The commands undo/redo handler.
    189      * @since 12641 (as a replacement to {@code Main.main.undoRedo})
    190      */
    191     public static final UndoRedoHandler undoRedo = new UndoRedoHandler(); // Must be declared after layerManager
     195     * @since 12641
     196     */
     197    public static UndoRedoHandler undoRedo;
    192198
    193199    /**
     
    213219    public MainApplication(MainFrame mainFrame) {
    214220        this.mainFrame = mainFrame;
     221        undoRedo = super.undoRedo;
     222        getLayerManager().addLayerChangeListener(new LayerChangeListener() {
     223            @Override
     224            public void layerRemoving(LayerRemoveEvent e) {
     225                Layer layer = e.getRemovedLayer();
     226                if (layer instanceof OsmDataLayer) {
     227                    undoRedo.clean(((OsmDataLayer) layer).data);
     228                }
     229            }
     230
     231            @Override
     232            public void layerOrderChanged(LayerOrderChangeEvent e) {
     233                // Do nothing
     234            }
     235
     236            @Override
     237            public void layerAdded(LayerAddEvent e) {
     238                // Do nothing
     239            }
     240        });
    215241    }
    216242
     
    405431    public DataSet getEditDataSet() {
    406432        return getLayerManager().getEditDataSet();
     433    }
     434
     435    @Override
     436    public void setEditDataSet(DataSet ds) {
     437        Optional<OsmDataLayer> layer = getLayerManager().getLayersOfType(OsmDataLayer.class).stream()
     438                .filter(l -> l.data.equals(ds)).findFirst();
     439        if (layer.isPresent()) {
     440            getLayerManager().setActiveLayer(layer.get());
     441        }
     442    }
     443
     444    @Override
     445    public boolean containsDataSet(DataSet ds) {
     446        return getLayerManager().getLayersOfType(OsmDataLayer.class).stream().anyMatch(l -> l.data.equals(ds));
    407447    }
    408448
  • trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/PrimitiveDataPaster.java

    r12641 r12718  
    8383            }
    8484        }
    85         return new AddPrimitivesCommand(bufferCopy, toSelect, layer);
     85        return new AddPrimitivesCommand(bufferCopy, toSelect, layer.data);
    8686    }
    8787
  • trunk/src/org/openstreetmap/josm/gui/dialogs/CommandStackDialog.java

    r12641 r12718  
    3939import org.openstreetmap.josm.command.Command;
    4040import org.openstreetmap.josm.command.PseudoCommand;
     41import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
    4142import org.openstreetmap.josm.data.osm.DataSet;
    4243import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    4445import org.openstreetmap.josm.gui.SideButton;
    4546import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    46 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    4747import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    4848import org.openstreetmap.josm.tools.GBC;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java

    r12641 r12718  
    1111
    1212import org.openstreetmap.josm.Main;
     13import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener;
    1314import org.openstreetmap.josm.data.osm.Relation;
    1415import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     
    1920import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    2021import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    21 import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
    2222import org.openstreetmap.josm.gui.tagging.TagEditorModel;
    2323import org.openstreetmap.josm.tools.ImageProvider;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java

    r12663 r12718  
    7373        if (newRelation.getMembersCount() == 0 && !newRelation.hasKeys())
    7474            return;
    75         MainApplication.undoRedo.add(new AddCommand(layer, newRelation));
     75        MainApplication.undoRedo.add(new AddCommand(layer.data, newRelation));
    7676
    7777        // make sure everybody is notified about the changes
     
    9595        memberTableModel.applyToRelation(editedRelation);
    9696        Conflict<Relation> conflict = new Conflict<>(editor.getRelation(), editedRelation);
    97         MainApplication.undoRedo.add(new ConflictAddCommand(layer, conflict));
     97        MainApplication.undoRedo.add(new ConflictAddCommand(layer.data, conflict));
    9898    }
    9999
  • trunk/src/org/openstreetmap/josm/gui/layer/Layer.java

    r12170 r12718  
    339339     * @param name the name. If null, the name is set to the empty string.
    340340     */
    341     public final void setName(String name) {
     341    public void setName(String name) {
    342342        if (this.name != null) {
    343343            removeColorPropertyListener();
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r12675 r12718  
    295295
    296296    /**
    297      * A listener that gets notified of command queue (undo/redo) size changes.
    298      */
    299     @FunctionalInterface
    300     public interface CommandQueueListener {
    301         /**
    302          * Notifies the listener about the new queue size
    303          * @param queueSize Undo stack size
    304          * @param redoSize Redo stack size
    305          */
    306         void commandChanged(int queueSize, int redoSize);
    307     }
    308 
    309     /**
    310297     * Listener called when a state of this layer has changed.
    311298     * @since 10600 (functional interface)
     
    401388        CheckParameterUtil.ensureParameterNotNull(data, "data");
    402389        this.data = data;
     390        this.data.setName(name);
    403391        this.setAssociatedFile(associatedFile);
    404392        data.addDataSetListener(new DataSetListenerAdapter(this));
     
    603591            return;
    604592
    605         MainApplication.undoRedo.clean(this);
     593        MainApplication.undoRedo.clean(data);
    606594
    607595        // if uploaded, clean the modified flags as well
     
    11461134        invalidate();
    11471135    }
     1136
     1137    @Override
     1138    public void setName(String name) {
     1139        if (data != null) {
     1140            data.setName(name);
     1141        }
     1142        super.setName(name);
     1143    }
    11481144}
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r12713 r12718  
    3737import org.openstreetmap.josm.gui.MainApplication;
    3838import org.openstreetmap.josm.gui.MapFrame;
    39 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4039
    4140/**
     
    103102        }
    104103
    105         OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
    106104        DataSet dataset = ways.get(0).getDataSet();
    107105
     
    210208
    211209                                if (intNode == newNode) {
    212                                     cmds.add(layer != null ? new AddCommand(layer, intNode) : new AddCommand(dataset, intNode));
     210                                    cmds.add(new AddCommand(dataset, intNode));
    213211                                }
    214212                            }
  • trunk/src/org/openstreetmap/josm/tools/RightAndLefthandTraffic.java

    r12688 r12718  
    104104        }
    105105        // Purge all other ways and relations so dataset only contains lefthand traffic data
    106         PurgeCommand.build(null, toPurge, null).executeCommand();
     106        PurgeCommand.build(toPurge, null).executeCommand();
    107107        // Combine adjacent countries into a single polygon
    108108        Collection<Way> optimizedWays = new ArrayList<>();
  • trunk/test/unit/org/openstreetmap/josm/command/CommandTest.java

    r12636 r12718  
    22package org.openstreetmap.josm.command;
    33
    4 import static org.junit.Assert.assertFalse;
    54import static org.junit.Assert.assertSame;
    6 import static org.junit.Assert.assertTrue;
    75
    86import java.util.Arrays;
     
    5048
    5149    /**
    52      * Test {@link Command#invalidBecauselayerRemoved(org.openstreetmap.josm.gui.layer.Layer)}
     50     * Test {@link Command#getLayer()}
     51     * @deprecated to be removed end of 2017
    5352     */
    5453    @Test
    55     public void testInvalidBecauselayerRemoved() {
    56         OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null);
    57 
    58         Command command = new NopCommand();
    59         assertFalse(command.invalidBecauselayerRemoved(layer2));
    60         assertTrue(command.invalidBecauselayerRemoved(testData.layer));
    61 
    62         Command command2 = new NopCommand(layer2);
    63         assertTrue(command2.invalidBecauselayerRemoved(layer2));
    64         assertFalse(command2.invalidBecauselayerRemoved(testData.layer));
    65     }
    66 
    67     /**
    68      * Test {@link Command#getLayer()}
    69      */
    70     @Test
     54    @Deprecated
    7155    public void testGetLayer() {
    7256        OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "test", null);
    7357        Command command = new NopCommand();
    74         Command command2 = new NopCommand(layer2);
     58        Command command2 = new NopCommand(layer2.data);
    7559        assertSame(testData.layer, command.getLayer());
    7660        assertSame(layer2, command2.getLayer());
     
    9882        }
    9983
    100         NopCommand(OsmDataLayer layer) {
    101             super(layer);
     84        NopCommand(DataSet dataset) {
     85            super(dataset);
    10286        }
    10387
Note: See TracChangeset for help on using the changeset viewer.