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/src/org/openstreetmap/josm/actions
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.