Changeset 12672 in josm


Ignore:
Timestamp:
2017-08-27T17:07:54+02:00 (4 weeks ago)
Author:
Don-vip
Message:

see #15182 - move ConflictCollection from OsmDataLayer to DataSet. Simplifies some code where a data set is enough, and a layer is not needed

Location:
trunk
Files:
15 edited

Legend:

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

    r12636 r12672  
    3636        DataSet set = getLayerManager().getEditDataSet();
    3737        if (set != null) {
    38             new InspectPrimitiveDialog(set.getAllSelected(), getLayerManager().getEditLayer()).showDialog();
     38            new InspectPrimitiveDialog(set.getAllSelected(), set).showDialog();
    3939        }
    4040    }
  • trunk/src/org/openstreetmap/josm/command/PurgeCommand.java

    r12605 r12672  
    122122                } else {
    123123                    getAffectedDataSet().removePrimitive(osm);
    124                     if (getLayer() != null) {
    125                         Conflict<?> conflict = getLayer().getConflicts().getConflictForMy(osm);
    126                         if (conflict != null) {
    127                             purgedConflicts.add(conflict);
    128                             getLayer().getConflicts().remove(conflict);
    129                         }
     124                    Conflict<?> conflict = getAffectedDataSet().getConflicts().getConflictForMy(osm);
     125                    if (conflict != null) {
     126                        purgedConflicts.add(conflict);
     127                        getAffectedDataSet().getConflicts().remove(conflict);
    130128                    }
    131129                }
     
    157155
    158156        for (Conflict<?> conflict : purgedConflicts) {
    159             getLayer().getConflicts().add(conflict);
     157            getAffectedDataSet().getConflicts().add(conflict);
    160158        }
    161159    }
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictAddCommand.java

    r12663 r12672  
    1313import org.openstreetmap.josm.command.Command;
    1414import org.openstreetmap.josm.data.conflict.Conflict;
     15import org.openstreetmap.josm.data.osm.DataSet;
    1516import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    1617import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    3839    }
    3940
     41    /**
     42     * Constructs a new {@code ConflictAddCommand}.
     43     * @param ds the data set. Must not be null.
     44     * @param conflict the conflict to add
     45     * @since 12672
     46     */
     47    public ConflictAddCommand(DataSet ds, Conflict<? extends OsmPrimitive> conflict) {
     48        super(ds);
     49        this.conflict = conflict;
     50    }
     51
    4052    protected void warnBecauseOfDoubleConflict() {
    4153        JOptionPane.showMessageDialog(
     
    5567    public boolean executeCommand() {
    5668        try {
    57             getLayer().getConflicts().add(conflict);
     69            getAffectedDataSet().getConflicts().add(conflict);
    5870        } catch (IllegalStateException e) {
    5971            Logging.error(e);
     
    7284            return;
    7385        }
    74         getLayer().getConflicts().remove(conflict);
     86        getAffectedDataSet().getConflicts().remove(conflict);
    7587    }
    7688
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java

    r12636 r12672  
    99import org.openstreetmap.josm.data.conflict.Conflict;
    1010import org.openstreetmap.josm.data.conflict.ConflictCollection;
     11import org.openstreetmap.josm.data.osm.DataSet;
    1112import org.openstreetmap.josm.gui.MainApplication;
    1213import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    5960     */
    6061    protected void reconstituteConflicts() {
    61         OsmDataLayer editLayer = getLayer();
     62        DataSet ds = getAffectedDataSet();
    6263        for (Conflict<?> c : resolvedConflicts) {
    63             if (!editLayer.getConflicts().hasConflictForMy(c.getMy())) {
    64                 editLayer.getConflicts().add(c);
     64            if (!ds.getConflicts().hasConflictForMy(c.getMy())) {
     65                ds.getConflicts().add(c);
    6566            }
    6667        }
  • trunk/src/org/openstreetmap/josm/command/conflict/ModifiedConflictResolveCommand.java

    r10216 r12672  
    5555            conflict.getMy().setModified(conflict.getTheir().isModified());
    5656        }
    57         getLayer().getConflicts().remove(conflict);
     57        getAffectedDataSet().getConflicts().remove(conflict);
    5858        rememberConflict(conflict);
    5959        return true;
  • trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java

    r12636 r12672  
    1111
    1212import org.openstreetmap.josm.data.conflict.Conflict;
     13import org.openstreetmap.josm.data.osm.DataSet;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1415import org.openstreetmap.josm.data.osm.Relation;
     
    8182
    8283        MainApplication.getLayerManager().setActiveLayer(layer);
    83         OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
     84        DataSet editDs = MainApplication.getLayerManager().getEditDataSet();
    8485
    8586        // restore the former state
     
    8990        // restore a conflict if necessary
    9091        //
    91         if (!editLayer.getConflicts().hasConflictForMy(conflict.getMy())) {
    92             editLayer.getConflicts().add(conflict);
     92        if (!editDs.getConflicts().hasConflictForMy(conflict.getMy())) {
     93            editDs.getConflicts().add(conflict);
    9394        }
    9495    }
  • trunk/src/org/openstreetmap/josm/command/conflict/VersionConflictResolveCommand.java

    r10216 r12672  
    6464            }
    6565        }
    66         getLayer().getConflicts().remove(conflict);
     66        getAffectedDataSet().getConflicts().remove(conflict);
    6767        rememberConflict(conflict);
    6868        return true;
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r12620 r12672  
    3030import org.openstreetmap.josm.data.ProjectionBounds;
    3131import org.openstreetmap.josm.data.SelectionChangedListener;
     32import org.openstreetmap.josm.data.conflict.ConflictCollection;
    3233import org.openstreetmap.josm.data.coor.EastNorth;
    3334import org.openstreetmap.josm.data.coor.LatLon;
     
    196197    private final Collection<DataSource> dataSources = new LinkedList<>();
    197198
     199    private final ConflictCollection conflicts = new ConflictCollection();
     200
    198201    /**
    199202     * Constructs a new {@code DataSet}.
     
    13471350    }
    13481351
     1352    /**
     1353     * Replies the set of conflicts currently managed in this layer.
     1354     *
     1355     * @return the set of conflicts currently managed in this layer
     1356     * @since 12672
     1357     */
     1358    public ConflictCollection getConflicts() {
     1359        return conflicts;
     1360    }
     1361
    13491362    /* --------------------------------------------------------------------------------- */
    13501363    /* interface ProjectionChangeListner                                                 */
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r12643 r12672  
    218218     */
    219219    public void refreshView() {
    220         OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
     220        DataSet editDs = MainApplication.getLayerManager().getEditDataSet();
    221221        synchronized (this) {
    222             conflicts = editLayer == null ? new ConflictCollection() : editLayer.getConflicts();
     222            conflicts = editDs == null ? new ConflictCollection() : editDs.getConflicts();
    223223        }
    224224        GuiHelper.runInEDT(() -> {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDataText.java

    r12213 r12672  
    1111import org.openstreetmap.josm.data.coor.EastNorth;
    1212import org.openstreetmap.josm.data.osm.BBox;
     13import org.openstreetmap.josm.data.osm.DataSet;
    1314import org.openstreetmap.josm.data.osm.Node;
    1415import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1617import org.openstreetmap.josm.data.osm.RelationMember;
    1718import org.openstreetmap.josm.data.osm.Way;
    18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1919import org.openstreetmap.josm.tools.Geometry;
    2020import org.openstreetmap.josm.tools.date.DateUtils;
     
    2929
    3030    private final StringBuilder s = new StringBuilder();
    31     private final OsmDataLayer layer;
    32 
    33     InspectPrimitiveDataText(OsmDataLayer layer) {
    34         this.layer = layer;
     31    private final DataSet ds;
     32
     33    InspectPrimitiveDataText(DataSet ds) {
     34        this.ds = ds;
    3535    }
    3636
     
    226226
    227227    void addConflicts(OsmPrimitive o) {
    228         Conflict<?> c = layer.getConflicts().getConflictForMy(o);
     228        Conflict<?> c = ds.getConflicts().getConflictForMy(o);
    229229        if (c != null) {
    230230            add(tr("In conflict with: "));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r12663 r12672  
    2222
    2323import org.openstreetmap.josm.Main;
     24import org.openstreetmap.josm.data.osm.DataSet;
    2425import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    2526import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    2829import org.openstreetmap.josm.gui.MainApplication;
    2930import org.openstreetmap.josm.gui.NavigatableComponent;
    30 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3131import org.openstreetmap.josm.gui.mappaint.Cascade;
    3232import org.openstreetmap.josm.gui.mappaint.ElemStyles;
     
    5353
    5454    protected transient List<OsmPrimitive> primitives;
    55     protected transient OsmDataLayer layer;
    5655    private boolean mappaintTabLoaded;
    5756    private boolean editcountTabLoaded;
     
    6059     * Constructs a new {@code InspectPrimitiveDialog}.
    6160     * @param primitives collection of primitives
    62      * @param layer data layer
     61     * @param data data set
     62     * @since 12672 (signature)
    6363     */
    64     public InspectPrimitiveDialog(final Collection<OsmPrimitive> primitives, OsmDataLayer layer) {
     64    public InspectPrimitiveDialog(final Collection<OsmPrimitive> primitives, DataSet data) {
    6565        super(Main.parent, tr("Advanced object info"), tr("Close"));
    6666        this.primitives = new ArrayList<>(primitives);
    67         this.layer = layer;
    6867        setRememberWindowGeometry(getClass().getName() + ".geometry",
    6968                WindowGeometry.centerInWindow(Main.parent, new Dimension(750, 550)));
     
    7271        final JTabbedPane tabs = new JTabbedPane();
    7372
    74         tabs.addTab(tr("data"), genericMonospacePanel(new JPanel(), buildDataText(layer, this.primitives)));
     73        tabs.addTab(tr("data"), genericMonospacePanel(new JPanel(), buildDataText(data, this.primitives)));
    7574
    7675        final JPanel pMapPaint = new JPanel();
     
    106105    }
    107106
    108     protected static String buildDataText(OsmDataLayer layer, List<OsmPrimitive> primitives) {
    109         InspectPrimitiveDataText dt = new InspectPrimitiveDataText(layer);
     107    protected static String buildDataText(DataSet data, List<OsmPrimitive> primitives) {
     108        InspectPrimitiveDataText dt = new InspectPrimitiveDataText(data);
    110109        primitives.stream()
    111110                .sorted(OsmPrimitiveComparator.orderingWaysRelationsNodes().thenComparing(OsmPrimitiveComparator.comparingNames()))
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationTree.java

    r12636 r12672  
    136136                return;
    137137            }
    138             DataSetMerger visitor = new DataSetMerger(MainApplication.getLayerManager().getEditLayer().data, ds);
     138            DataSet editData = MainApplication.getLayerManager().getEditDataSet();
     139            DataSetMerger visitor = new DataSetMerger(editData, ds);
    139140            visitor.merge();
    140141            if (!visitor.getConflicts().isEmpty()) {
    141                 MainApplication.getLayerManager().getEditLayer().getConflicts().add(visitor.getConflicts());
     142                editData.getConflicts().add(visitor.getConflicts());
    142143            }
    143144            final RelationTreeModel model = (RelationTreeModel) getModel();
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r12671 r12672  
    351351
    352352    /**
    353      * the collection of conflicts detected in this layer
    354      */
    355     private final ConflictCollection conflicts;
    356 
    357     /**
    358353     * a texture for non-downloaded area
    359354     */
     
    407402        this.data = data;
    408403        this.setAssociatedFile(associatedFile);
    409         conflicts = new ConflictCollection();
    410404        data.addDataSetListener(new DataSetListenerAdapter(this));
    411405        data.addDataSetListener(MultipolygonCache.getInstance());
     
    567561        int numNewConflicts = 0;
    568562        for (Conflict<?> c : visitor.getConflicts()) {
    569             if (!conflicts.hasConflict(c)) {
     563            if (!data.getConflicts().hasConflict(c)) {
    570564                numNewConflicts++;
    571                 conflicts.add(c);
     565                data.getConflicts().add(c);
    572566            }
    573567        }
     
    924918     */
    925919    public ConflictCollection getConflicts() {
    926         return conflicts;
     920        return data.getConflicts();
    927921    }
    928922
  • trunk/test/unit/org/openstreetmap/josm/command/conflict/ConflictAddCommandTest.java

    r12636 r12672  
    5959    @Test
    6060    public void testExecuteUndoCommand() {
    61         OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
     61        DataSet ds = MainApplication.getLayerManager().getEditDataSet();
    6262        Conflict<Node> conflict = new Conflict<>(new Node(), new Node());
    63         ConflictAddCommand cmd = new ConflictAddCommand(layer, conflict);
     63        ConflictAddCommand cmd = new ConflictAddCommand(ds, conflict);
    6464        assertTrue(cmd.executeCommand());
    65         assertFalse(layer.getConflicts().isEmpty());
    66         assertTrue(layer.getConflicts().hasConflict(conflict));
     65        assertFalse(ds.getConflicts().isEmpty());
     66        assertTrue(ds.getConflicts().hasConflict(conflict));
    6767        cmd.undoCommand();
    68         assertFalse(layer.getConflicts().hasConflict(conflict));
    69         assertTrue(layer.getConflicts().isEmpty());
     68        assertFalse(ds.getConflicts().hasConflict(conflict));
     69        assertTrue(ds.getConflicts().isEmpty());
    7070    }
    7171
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialogTest.java

    r12636 r12672  
    4747    public void testBuildDataText() {
    4848        DataSet ds = new DataSet();
    49         OsmDataLayer layer = new OsmDataLayer(ds, "", null);
    50         assertEquals("", InspectPrimitiveDialog.buildDataText(layer, new ArrayList<>(ds.allPrimitives())));
     49        assertEquals("", InspectPrimitiveDialog.buildDataText(ds, new ArrayList<>(ds.allPrimitives())));
    5150        Node n = new Node(LatLon.ZERO);
    5251        n.setOsmId(1, 1);
     
    6160                "  Coordinates: 0.0, 0.0\n" +
    6261                "  Coordinates (projected): 0.0, -7.081154551613622E-10\n" +
    63                 "\n", InspectPrimitiveDialog.buildDataText(layer, new ArrayList<>(ds.allPrimitives())));
     62                "\n", InspectPrimitiveDialog.buildDataText(ds, new ArrayList<>(ds.allPrimitives())));
    6463    }
    6564
Note: See TracChangeset for help on using the changeset viewer.