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

Legend:

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