Ignore:
Timestamp:
2017-09-04T00:50:22+02:00 (9 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/command/conflict
Files:
3 edited

Legend:

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