Ignore:
Timestamp:
2018-02-18T05:02:23+01:00 (21 months ago)
Author:
Don-vip
Message:

see #8039, see #10456 - support read-only data layers

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
32 edited

Legend:

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

    r13402 r13434  
    527527            return ((DrawAction) map.mapMode).getInProgressSelection();
    528528        } else {
    529             DataSet ds = layerManager.getEditDataSet();
     529            DataSet ds = layerManager.getActiveDataSet();
    530530            if (ds == null) return null;
    531531            return ds.getSelected();
     
    539539
    540540    @Override
    541     public void setEditDataSet(DataSet ds) {
     541    public DataSet getActiveDataSet() {
     542        return getLayerManager().getActiveDataSet();
     543    }
     544
     545    @Override
     546    public void setActiveDataSet(DataSet ds) {
    542547        Optional<OsmDataLayer> layer = getLayerManager().getLayersOfType(OsmDataLayer.class).stream()
    543548                .filter(l -> l.data.equals(ds)).findFirst();
  • trunk/src/org/openstreetmap/josm/gui/MapStatus.java

    r13178 r13434  
    327327                boolean middleMouseDown = (ms.modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0;
    328328
    329                 ds = mv.getLayerManager().getEditDataSet();
     329                ds = mv.getLayerManager().getActiveDataSet();
    330330                if (ds != null) {
    331331                    // This is not perfect, if current dataset was changed during execution, the lock would be useless
     
    512512         */
    513513        private void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {
    514             DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     514            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    515515            // Find some items that are required for cycling through
    516516            OsmPrimitive firstItem = null;
     
    603603         */
    604604        private void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {
    605             DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     605            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    606606            if (ds.isSelected(osm)) {
    607607                lbl.setBackground(SystemColor.textHighlight);
     
    676676                @Override
    677677                public void mouseClicked(MouseEvent e) {
    678                     DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     678                    DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    679679                    // Let the user toggle the selection
    680680                    ds.toggleSelected(osm);
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r13400 r13434  
    381381
    382382    /**
    383      * Replies true if the active data layer (edit layer) is visible.
     383     * Replies true if the active data layer is visible.
    384384     *
    385      * @return true if the active data layer (edit layer) is visible, false otherwise
     385     * @return true if the active data layer is visible, false otherwise
    386386     */
    387387    public boolean isActiveLayerVisible() {
    388         OsmDataLayer e = layerManager.getEditLayer();
     388        OsmDataLayer e = layerManager.getActiveDataLayer();
    389389        return e != null && e.isVisible();
    390390    }
  • trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r13200 r13434  
    939939    private Map<Double, List<Node>> getNearestNodesImpl(Point p, Predicate<OsmPrimitive> predicate) {
    940940        Map<Double, List<Node>> nearestMap = new TreeMap<>();
    941         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     941        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    942942
    943943        if (ds != null) {
     
    11481148    private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p, Predicate<OsmPrimitive> predicate) {
    11491149        Map<Double, List<WaySegment>> nearestMap = new TreeMap<>();
    1150         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     1150        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    11511151
    11521152        if (ds != null) {
     
    15091509    public final OsmPrimitive getNearestNodeOrWay(Point p, Predicate<OsmPrimitive> predicate, boolean useSelected) {
    15101510        Collection<OsmPrimitive> sel;
    1511         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     1511        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    15121512        if (useSelected && ds != null) {
    15131513            sel = ds.getSelected();
  • trunk/src/org/openstreetmap/josm/gui/SelectionManager.java

    r12961 r13434  
    183183    @Override
    184184    public void mousePressed(MouseEvent e) {
    185         if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1 && MainApplication.getLayerManager().getEditDataSet() != null) {
     185        if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1 && MainApplication.getLayerManager().getActiveDataSet() != null) {
    186186            SelectByInternalPointAction.performSelection(MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY()),
    187187                    (e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0,
     
    374374        }
    375375
    376         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     376        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    377377        if (clicked) {
    378378            Point center = new Point(selectionResult.xpoints[0], selectionResult.ypoints[0]);
  • trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java

    r12881 r13434  
    2222
    2323import org.openstreetmap.josm.actions.mapmode.MapMode;
    24 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
    25 import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    2624import org.openstreetmap.josm.data.osm.BBox;
    2725import org.openstreetmap.josm.data.osm.DataSet;
     
    5654import org.openstreetmap.josm.gui.widgets.OSDLabel;
    5755import org.openstreetmap.josm.spi.preferences.Config;
     56import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     57import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    5858import org.openstreetmap.josm.tools.Logging;
    5959
     
    194194
    195195    private static Set<String> getTagValues(String key) {
    196         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     196        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    197197        Set<String> values = new TreeSet<>();
    198198        if (ds != null) {
     
    371371            model.executeFilters();
    372372            if (model.isChanged()) {
    373                 OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    374                 if (editLayer != null) {
    375                     editLayer.invalidate();
     373                OsmDataLayer dataLayer = MainApplication.getLayerManager().getActiveDataLayer();
     374                if (dataLayer != null) {
     375                    dataLayer.invalidate();
    376376                }
    377377            }
     
    422422    @Override
    423423    public void layerRemoving(LayerRemoveEvent e) {
    424         if (MainApplication.getLayerManager().getEditLayer() == null) {
     424        if (MainApplication.getLayerManager().getActiveDataLayer() == null) {
    425425            resetCurrentAutoFilter();
    426426        }
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r13426 r13434  
    4848import org.openstreetmap.josm.data.imagery.TileLoaderFactory;
    4949import org.openstreetmap.josm.data.osm.BBox;
     50import org.openstreetmap.josm.data.osm.DataSet;
    5051import org.openstreetmap.josm.data.preferences.BooleanProperty;
    5152import org.openstreetmap.josm.data.preferences.StringProperty;
     
    5354import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer;
    5455import org.openstreetmap.josm.gui.layer.MainLayerManager;
    55 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5656import org.openstreetmap.josm.gui.layer.TMSLayer;
    5757import org.openstreetmap.josm.spi.preferences.Config;
     
    237237        Graphics2D g2d = (Graphics2D) g;
    238238
    239         // draw shaded area for non-downloaded region of current "edit layer", but only if there *is* a current "edit layer",
     239        // draw shaded area for non-downloaded region of current data set, but only if there *is* a current data set,
    240240        // and it has defined bounds. Routine is analogous to that in OsmDataLayer's paint routine (but just different
    241241        // enough to make sharing code impractical)
    242         final OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    243         if (editLayer != null && this.showDownloadAreaButtonModel.isSelected() && !editLayer.data.getDataSources().isEmpty()) {
     242        final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     243        if (ds != null && this.showDownloadAreaButtonModel.isSelected() && !ds.getDataSources().isEmpty()) {
    244244            // initialize area with current viewport
    245245            Rectangle b = this.getBounds();
     
    249249
    250250            // combine successively downloaded areas after converting to screen-space
    251             for (Bounds bounds : editLayer.data.getDataSourceBounds()) {
     251            for (Bounds bounds : ds.getDataSourceBounds()) {
    252252                if (bounds.isCollapsed()) {
    253253                    continue;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java

    r12846 r13434  
    5353import org.openstreetmap.josm.gui.help.HelpUtil;
    5454import org.openstreetmap.josm.gui.io.CloseChangesetTask;
    55 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5655import org.openstreetmap.josm.gui.util.GuiHelper;
    5756import org.openstreetmap.josm.gui.widgets.ListPopupMenu;
     
    123122        ChangesetCache.getInstance().addChangesetCacheListener(inActiveDataLayerModel);
    124123        MainApplication.getLayerManager().addActiveLayerChangeListener(inActiveDataLayerModel);
    125         OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    126         if (editLayer != null) {
    127             editLayer.data.addDataSetListener(inActiveDataLayerModel);
    128             inActiveDataLayerModel.initFromDataSet(editLayer.data);
    129             inSelectionModel.initFromPrimitives(editLayer.data.getAllSelected());
     124        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     125        if (ds != null) {
     126            ds.addDataSetListener(inActiveDataLayerModel);
     127            inActiveDataLayerModel.initFromDataSet(ds);
     128            inSelectionModel.initFromPrimitives(ds.getAllSelected());
    130129        }
    131130    }
     
    133132    protected void unregisterAsListener() {
    134133        // remove the list model for the current edit layer as listener
    135         //
    136134        ChangesetCache.getInstance().removeChangesetCacheListener(inActiveDataLayerModel);
    137135        MainApplication.getLayerManager().removeActiveLayerChangeListener(inActiveDataLayerModel);
    138         OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    139         if (editLayer != null) {
    140             editLayer.data.removeDataSetListener(inActiveDataLayerModel);
    141         }
    142 
    143         // remove the list model for the changesets in the current selection as
    144         // listener
     136        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     137        if (ds != null) {
     138            ds.removeDataSetListener(inActiveDataLayerModel);
     139        }
     140
     141        // remove the list model for the changesets in the current selection as listener
    145142        SelectionEventManager.getInstance().removeSelectionListener(inSelectionModel);
    146143        ChangesetCache.getInstance().removeChangesetCacheListener(inSelectionModel);
     
    235232
    236233    protected void initWithCurrentData() {
    237         OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    238         if (editLayer != null) {
    239             inSelectionModel.initFromPrimitives(editLayer.data.getAllSelected());
    240             inActiveDataLayerModel.initFromDataSet(editLayer.data);
     234        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     235        if (ds != null) {
     236            inSelectionModel.initFromPrimitives(ds.getAllSelected());
     237            inActiveDataLayerModel.initFromDataSet(ds);
    241238        }
    242239    }
     
    266263            if (sel.isEmpty())
    267264                return;
    268             if (MainApplication.getLayerManager().getEditDataSet() == null)
    269                 return;
    270             new SelectObjectsAction().selectObjectsByChangesetIds(MainApplication.getLayerManager().getEditDataSet(), sel);
     265            if (MainApplication.getLayerManager().getActiveDataSet() == null)
     266                return;
     267            new SelectObjectsAction().selectObjectsByChangesetIds(MainApplication.getLayerManager().getActiveDataSet(), sel);
    271268        }
    272269
     
    314311        @Override
    315312        public void actionPerformed(ActionEvent e) {
    316             if (MainApplication.getLayerManager().getEditLayer() == null)
     313            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     314            if (ds == null)
    317315                return;
    318316            ChangesetListModel model = getCurrentChangesetListModel();
     
    321319                return;
    322320
    323             DataSet ds = MainApplication.getLayerManager().getEditLayer().data;
    324321            selectObjectsByChangesetIds(ds, sel);
    325322        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java

    r13367 r13434  
    160160    public void hideNotify() {
    161161        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
    162         removeEditLayerListeners(MainApplication.getLayerManager().getEditLayer());
     162        removeDataLayerListeners(MainApplication.getLayerManager().getEditLayer());
    163163    }
    164164
     
    269269    @Override
    270270    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    271         removeEditLayerListeners(e.getPreviousEditLayer());
    272         addEditLayerListeners(e.getSource().getEditLayer());
     271        removeDataLayerListeners(e.getPreviousDataLayer());
     272        addDataLayerListeners(e.getSource().getActiveDataLayer());
    273273        refreshView();
    274274    }
    275275
    276     private void addEditLayerListeners(OsmDataLayer newLayer) {
     276    private void addDataLayerListeners(OsmDataLayer newLayer) {
    277277        if (newLayer != null) {
    278278            newLayer.getConflicts().addConflictListener(this);
     
    281281    }
    282282
    283     private void removeEditLayerListeners(OsmDataLayer oldLayer) {
     283    private void removeDataLayerListeners(OsmDataLayer oldLayer) {
    284284        if (oldLayer != null) {
    285285            oldLayer.getConflicts().removeConflictListener(this);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r12678 r13434  
    114114
    115115    protected static String buildMapPaintText() {
    116         final Collection<OsmPrimitive> sel = MainApplication.getLayerManager().getEditDataSet().getAllSelected();
     116        final Collection<OsmPrimitive> sel = MainApplication.getLayerManager().getActiveDataSet().getAllSelected();
    117117        ElemStyles elemstyles = MapPaintStyles.getStyles();
    118118        NavigatableComponent nc = MainApplication.getMap().mapView;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r13210 r13434  
    342342
    343343        protected void setCurrentRelationAsSelection() {
    344             MainApplication.getLayerManager().getEditDataSet().setSelected(displaylist.getSelectedValue());
     344            MainApplication.getLayerManager().getActiveDataSet().setSelected(displaylist.getSelectedValue());
    345345        }
    346346
     
    351351        @Override
    352352        public void mouseClicked(MouseEvent e) {
    353             if (MainApplication.getLayerManager().getEditLayer() == null) return;
    354             if (isDoubleClick(e)) {
    355                 if (e.isControlDown()) {
     353            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     354            if (ds != null && isDoubleClick(e)) {
     355                if (e.isControlDown() && !ds.isReadOnly()) {
    356356                    editCurrentRelation();
    357357                } else {
     
    733733            return;
    734734        // trigger a sort of the relation list because the display name may have changed
    735         //
    736735        List<Relation> sel = model.getSelectedRelations();
    737736        model.sort();
     
    742741    @Override
    743742    public void dataChanged(DataChangedEvent event) {
    744         initFromLayer(MainApplication.getLayerManager().getEditLayer());
     743        initFromLayer(MainApplication.getLayerManager().getActiveDataLayer());
    745744    }
    746745
  • trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r13141 r13434  
    7373import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    7474import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    75 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    7675import org.openstreetmap.josm.gui.util.GuiHelper;
    7776import org.openstreetmap.josm.gui.util.HighlightHelper;
     
    200199            if (idx < 0) return;
    201200            if (isDoubleClick(e)) {
    202                 OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
    203                 if (layer == null) return;
     201                DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     202                if (ds == null) return;
    204203                OsmPrimitive osm = model.getElementAt(idx);
    205                 Collection<OsmPrimitive> sel = layer.data.getSelected();
     204                Collection<OsmPrimitive> sel = ds.getSelected();
    206205                if (sel.size() != 1 || !sel.iterator().next().equals(osm)) {
    207206                    // Select primitive if it's not the whole current selection
    208                     layer.data.setSelected(Collections.singleton(osm));
     207                    ds.setSelected(Collections.singleton(osm));
    209208                } else if (osm instanceof Relation) {
    210209                    // else open relation editor if applicable
     
    296295
    297296        protected void updateEnabledState() {
    298             setEnabled(MainApplication.getLayerManager().getEditLayer() != null);
     297            setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null);
    299298        }
    300299
     
    321320            Collection<OsmPrimitive> sel = model.getSelected();
    322321            if (sel.isEmpty()) return;
    323             OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    324             if (editLayer == null) return;
    325             editLayer.data.setSelected(sel);
     322            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     323            if (ds == null) return;
     324            ds.setSelected(sel);
    326325            model.selectionModel.setSelectionInterval(0, sel.size()-1);
    327326        }
     
    830829        @Override
    831830        public void actionPerformed(ActionEvent e) {
    832             MainApplication.getLayerManager().getEditDataSet().setSelected(sel);
     831            MainApplication.getLayerManager().getActiveDataSet().setSelected(sel);
    833832        }
    834833    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r12636 r13434  
    3232import org.openstreetmap.josm.actions.AbstractInfoAction;
    3333import org.openstreetmap.josm.data.osm.DataSelectionListener;
     34import org.openstreetmap.josm.data.osm.DataSet;
    3435import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3536import org.openstreetmap.josm.data.osm.User;
     
    347348                users.add(data.get(index).user);
    348349            }
    349             Collection<OsmPrimitive> selected = MainApplication.getLayerManager().getEditDataSet().getAllSelected();
     350            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     351            Collection<OsmPrimitive> selected = ds.getAllSelected();
    350352            Collection<OsmPrimitive> byUser = new LinkedList<>();
    351353            for (OsmPrimitive p : selected) {
     
    354356                }
    355357            }
    356             MainApplication.getLayerManager().getEditDataSet().setSelected(byUser);
     358            ds.setSelected(byUser);
    357359        }
    358360
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

    r13149 r13434  
    132132            @Override
    133133            public void actionPerformed(ActionEvent e) {
    134                 final DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     134                final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    135135                if (ds == null) {
    136136                    return;
     
    181181    public void showNotify() {
    182182        DataSet.addSelectionListener(this);
    183         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     183        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    184184        if (ds != null) {
    185185            updateSelection(ds.getAllSelected());
     
    350350            }
    351351        }
    352         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     352        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    353353        if (ds != null) {
    354354            ds.setSelected(sel);
     
    494494
    495495            if (isDblClick) {
    496                 DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     496                DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    497497                if (ds != null) {
    498498                    ds.setSelected(sel);
     
    630630            try {
    631631                monitor.setTicksCount(testErrors.size());
    632                 final DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     632                final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    633633                int i = 0;
    634634                SwingUtilities.invokeAndWait(ds::beginUpdate);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java

    r13130 r13434  
    3636import org.openstreetmap.josm.actions.downloadtasks.ChangesetContentDownloadTask;
    3737import org.openstreetmap.josm.data.osm.Changeset;
     38import org.openstreetmap.josm.data.osm.DataSet;
    3839import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3940import org.openstreetmap.josm.data.osm.PrimitiveId;
     
    4950import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    5051import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    51 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5252import org.openstreetmap.josm.gui.util.GuiHelper;
    5353import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
     
    279279
    280280        @Override
    281         public void actionPerformed(ActionEvent arg0) {
     281        public void actionPerformed(ActionEvent e) {
    282282            Set<HistoryOsmPrimitive> selected = model.getSelectedPrimitives();
    283283            if (selected.isEmpty()) return;
     
    301301
    302302        @Override
    303         public void actionPerformed(ActionEvent arg0) {
     303        public void actionPerformed(ActionEvent e) {
    304304            final List<PrimitiveId> primitiveIds = model.getSelectedPrimitives().stream().map(HistoryOsmPrimitive::getPrimitiveId)
    305305                    .collect(Collectors.toList());
     
    323323                return null;
    324324            }
    325             OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
    326             if (layer == null) {
     325            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     326            if (ds == null) {
    327327                return null;
    328328            }
    329329            Set<OsmPrimitive> target = new HashSet<>();
    330330            for (HistoryOsmPrimitive p : model.getSelectedPrimitives()) {
    331                 OsmPrimitive op = layer.data.getPrimitiveById(p.getPrimitiveId());
     331                OsmPrimitive op = ds.getPrimitiveById(p.getPrimitiveId());
    332332                if (op != null) {
    333333                    target.add(op);
     
    338338
    339339        public final void updateEnabledState() {
    340             setEnabled(MainApplication.getLayerManager().getEditLayer() != null && model.hasSelectedPrimitives());
     340            setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null && model.hasSelectedPrimitives());
    341341        }
    342342
     
    350350            updateEnabledState();
    351351        }
    352 
    353352    }
    354353
     
    363362
    364363        @Override
    365         public void actionPerformed(ActionEvent arg0) {
     364        public void actionPerformed(ActionEvent e) {
    366365            final Set<OsmPrimitive> target = getTarget();
    367366            if (target == null) {
     
    372371                return;
    373372            }
    374             MainApplication.getLayerManager().getEditLayer().data.setSelected(target);
     373            MainApplication.getLayerManager().getActiveDataSet().setSelected(target);
    375374        }
    376375    }
     
    386385
    387386        @Override
    388         public void actionPerformed(ActionEvent arg0) {
     387        public void actionPerformed(ActionEvent e) {
    389388            final Set<OsmPrimitive> target = getTarget();
    390389            if (target == null) {
     
    395394                return;
    396395            }
    397             MainApplication.getLayerManager().getEditLayer().data.setSelected(target);
     396            MainApplication.getLayerManager().getActiveDataSet().setSelected(target);
    398397            AutoScaleAction.zoomToSelection();
    399398        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java

    r12871 r13434  
    3535import org.openstreetmap.josm.data.osm.Changeset;
    3636import org.openstreetmap.josm.data.osm.ChangesetCache;
     37import org.openstreetmap.josm.data.osm.DataSet;
    3738import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3839import org.openstreetmap.josm.gui.HelpAwareOptionPane;
     
    4243import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    4344import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    44 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4545import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    4646import org.openstreetmap.josm.gui.widgets.JosmTextField;
     
    7272    private final ZoomInCurrentLayerAction       actZoomInCurrentLayerAction = new ZoomInCurrentLayerAction();
    7373    // CHECKSTYLE.ON: SingleSpaceSeparator
    74    
     74
    7575    private JButton btnOpenChangesetPopupMenu;
    7676
     
    374374                            + "edit layer ''{1}''.</html>",
    375375                            currentChangeset.getId(),
    376                             Utils.escapeReservedCharactersHTML(MainApplication.getLayerManager().getEditLayer().getName())
     376                            Utils.escapeReservedCharactersHTML(MainApplication.getLayerManager().getActiveDataSet().getName())
    377377                    ),
    378378                    tr("Nothing to select"),
     
    383383
    384384        @Override
    385         public void actionPerformed(ActionEvent arg0) {
     385        public void actionPerformed(ActionEvent e) {
    386386            if (!isEnabled())
    387387                return;
    388             OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
    389             if (layer == null) {
     388            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     389            if (ds == null) {
    390390                return;
    391391            }
    392392            Set<OsmPrimitive> target = new HashSet<>();
    393             for (OsmPrimitive p: layer.data.allPrimitives()) {
     393            for (OsmPrimitive p: ds.allPrimitives()) {
    394394                if (p.isUsable() && p.getChangesetId() == currentChangeset.getId()) {
    395395                    target.add(p);
     
    400400                return;
    401401            }
    402             layer.data.setSelected(target);
     402            ds.setSelected(target);
    403403        }
    404404
    405405        public void updateEnabledState() {
    406             setEnabled(MainApplication.getLayerManager().getEditLayer() != null && currentChangeset != null);
     406            setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null && currentChangeset != null);
    407407        }
    408408
     
    433433                            + "edit layer ''{1}''.</html>",
    434434                            currentChangeset.getId(),
    435                             MainApplication.getLayerManager().getEditLayer().getName()
     435                            MainApplication.getLayerManager().getActiveDataSet().getName()
    436436                    ),
    437437                    tr("Nothing to zoom to"),
     
    442442
    443443        @Override
    444         public void actionPerformed(ActionEvent arg0) {
     444        public void actionPerformed(ActionEvent e) {
    445445            if (!isEnabled())
    446446                return;
    447             OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
    448             if (layer == null) {
     447            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     448            if (ds == null) {
    449449                return;
    450450            }
    451451            Set<OsmPrimitive> target = new HashSet<>();
    452             for (OsmPrimitive p: layer.data.allPrimitives()) {
     452            for (OsmPrimitive p: ds.allPrimitives()) {
    453453                if (p.isUsable() && p.getChangesetId() == currentChangeset.getId()) {
    454454                    target.add(p);
     
    459459                return;
    460460            }
    461             layer.data.setSelected(target);
     461            ds.setSelected(target);
    462462            AutoScaleAction.zoomToSelection();
    463463        }
    464464
    465465        public void updateEnabledState() {
    466             setEnabled(MainApplication.getLayerManager().getEditLayer() != null && currentChangeset != null);
     466            setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null && currentChangeset != null);
    467467        }
    468468
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetsInActiveDataLayerListModel.java

    r12372 r13434  
    44import javax.swing.DefaultListSelectionModel;
    55
     6import org.openstreetmap.josm.data.osm.DataSet;
    67import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
    78import org.openstreetmap.josm.data.osm.event.DataChangedEvent;
     
    1516import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    1617import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
    17 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1818
    1919/**
     
    8181        // just init the model content. Don't register as DataSetListener. The mode
    8282        // is already registered to receive DataChangedEvents from the current edit layer
    83         OsmDataLayer editLayer = e.getSource().getEditLayer();
    84         if (editLayer != null) {
    85             initFromDataSet(editLayer.data);
     83        DataSet ds = e.getSource().getActiveDataSet();
     84        if (ds != null) {
     85            initFromDataSet(ds);
    8686        } else {
    8787            initFromDataSet(null);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r13130 r13434  
    6464import org.openstreetmap.josm.command.Command;
    6565import org.openstreetmap.josm.data.SelectionChangedListener;
     66import org.openstreetmap.josm.data.osm.DataSet;
    6667import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    6768import org.openstreetmap.josm.data.osm.IRelation;
     
    9192import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
    9293import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
     94import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    9395import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    9496import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler;
     
    231233
    232234    private final PreferenceChangedListener preferenceListener = e -> {
    233                 if (MainApplication.getLayerManager().getEditDataSet() != null) {
     235                if (MainApplication.getLayerManager().getActiveDataSet() != null) {
    234236                    // Re-load data when display preference change
    235237                    updateSelection();
     
    487489        Relation relation = (Relation) membershipData.getValueAt(row, 0);
    488490        MainApplication.getMap().relationListDialog.selectRelation(relation);
    489         RelationEditor.getEditor(
    490                 MainApplication.getLayerManager().getEditLayer(),
    491                 relation,
    492                 ((MemberInfo) membershipData.getValueAt(row, 1)).role
    493         ).setVisible(true);
     491        OsmDataLayer layer = MainApplication.getLayerManager().getActiveDataLayer();
     492        if (!layer.isReadOnly()) {
     493            RelationEditor.getEditor(
     494                    layer, relation, ((MemberInfo) membershipData.getValueAt(row, 1)).role).setVisible(true);
     495        }
    494496    }
    495497
     
    534536    public void setVisible(boolean b) {
    535537        super.setVisible(b);
    536         if (b && MainApplication.getLayerManager().getEditDataSet() != null) {
     538        if (b && MainApplication.getLayerManager().getActiveDataSet() != null) {
    537539            updateSelection();
    538540        }
     
    644646        membershipTable.setVisible(membershipData.getRowCount() > 0);
    645647
     648        DataSet ds = Main.main.getActiveDataSet();
     649        boolean isReadOnly = ds != null && ds.isReadOnly();
    646650        boolean hasSelection = !newSel.isEmpty();
    647651        boolean hasTags = hasSelection && tagData.getRowCount() > 0;
    648652        boolean hasMemberships = hasSelection && membershipData.getRowCount() > 0;
    649         addAction.setEnabled(hasSelection);
    650         editAction.setEnabled(hasTags || hasMemberships);
    651         deleteAction.setEnabled(hasTags || hasMemberships);
     653        addAction.setEnabled(!isReadOnly && hasSelection);
     654        editAction.setEnabled(!isReadOnly && (hasTags || hasMemberships));
     655        deleteAction.setEnabled(!isReadOnly && (hasTags || hasMemberships));
    652656        tagTable.setVisible(hasTags);
    653657        tagTable.getTableHeader().setVisible(hasTags);
     
    10551059        @Override
    10561060        protected final void updateEnabledState() {
    1057             setEnabled(
    1058                     (tagTable != null && tagTable.getSelectedRowCount() >= 1)
     1061            DataSet ds = Main.main.getActiveDataSet();
     1062            setEnabled(ds != null && !ds.isReadOnly() &&
     1063                    ((tagTable != null && tagTable.getSelectedRowCount() >= 1)
    10591064                    || (membershipTable != null && membershipTable.getSelectedRowCount() > 0)
    1060                     );
     1065                    ));
    10611066        }
    10621067
     
    11101115        @Override
    11111116        protected void updateEnabledState() {
    1112             setEnabled(
    1113                     (tagTable != null && tagTable.getSelectedRowCount() == 1)
     1117            DataSet ds = Main.main.getActiveDataSet();
     1118            setEnabled(ds != null && !ds.isReadOnly() &&
     1119                    ((tagTable != null && tagTable.getSelectedRowCount() == 1)
    11141120                    ^ (membershipTable != null && membershipTable.getSelectedRowCount() == 1)
    1115                     );
     1121                    ));
    11161122        }
    11171123
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r13190 r13434  
    447447            mainPanel.add(p, BorderLayout.CENTER);
    448448
    449             AutoCompletionManager autocomplete = AutoCompletionManager.of(MainApplication.getLayerManager().getEditLayer().data);
     449            AutoCompletionManager autocomplete = AutoCompletionManager.of(Main.main.getActiveDataSet());
    450450            List<AutoCompletionItem> keyList = autocomplete.getTagKeys(DEFAULT_AC_ITEM_COMPARATOR);
    451451
     
    564564        public void setupDialog() {
    565565            super.setupDialog();
     566            buttons.get(0).setEnabled(!Main.main.getActiveDataSet().isReadOnly());
    566567            final Dimension size = getSize();
    567568            // Set resizable only in width
     
    699700
    700701            cacheRecentTags();
    701             AutoCompletionManager autocomplete = AutoCompletionManager.of(Main.main.getEditDataSet());
     702            AutoCompletionManager autocomplete = AutoCompletionManager.of(Main.main.getActiveDataSet());
    702703            List<AutoCompletionItem> keyList = autocomplete.getTagKeys(DEFAULT_AC_ITEM_COMPARATOR);
    703704
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r12657 r13434  
    114114    @Override
    115115    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    116         if (MainApplication.getLayerManager().getEditLayer() != this.layer) return;
     116        if (MainApplication.getLayerManager().getActiveDataLayer() != this.layer) return;
    117117        // just trigger a repaint
    118118        Collection<RelationMember> sel = getSelectedMembers();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java

    r12657 r13434  
    107107    @Override
    108108    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    109         if (layer == MainApplication.getLayerManager().getEditLayer()) {
     109        if (layer == MainApplication.getLayerManager().getActiveDataLayer()) {
    110110            cache.clear();
    111111            cache.addAll(newSelection);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

    r12951 r13434  
    416416    @Override
    417417    public void destroy() {
    418         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     418        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    419419        if (ds != null) {
    420420            ds.removeDataSetListener(this);
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r13202 r13434  
    1212import org.openstreetmap.josm.Main;
    1313import org.openstreetmap.josm.data.UserIdentityManager;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1415import org.openstreetmap.josm.data.osm.Node;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    102103
    103104        if (Main.main != null) {
    104             OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    105             if (editLayer != null) {
    106                 editLayer.data.addDataSetListener(this);
     105            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     106            if (ds != null) {
     107                ds.addDataSetListener(this);
    107108            }
    108109        }
     
    169170        if (history.getNumVersions() > 0) {
    170171            HistoryOsmPrimitive newLatest = null;
    171             OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    172             if (editLayer != null) {
    173                 OsmPrimitive p = editLayer.data.getPrimitiveById(history.getId(), history.getType());
     172            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     173            if (ds != null) {
     174                OsmPrimitive p = ds.getPrimitiveById(history.getId(), history.getType());
    174175                if (canShowAsLatest(p)) {
    175176                    newLatest = new HistoryPrimitiveBuilder().build(p);
     
    530531     */
    531532    public void unlinkAsListener() {
    532         OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    533         if (editLayer != null) {
    534             editLayer.data.removeDataSetListener(this);
     533        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     534        if (ds != null) {
     535            ds.removeDataSetListener(this);
    535536        }
    536537        MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
  • trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    r13130 r13434  
    2222
    2323import org.openstreetmap.josm.actions.AutoScaleAction;
     24import org.openstreetmap.josm.data.osm.DataSet;
    2425import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2526import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    2930import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
    3031import org.openstreetmap.josm.gui.MainApplication;
    31 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3232import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
    3333import org.openstreetmap.josm.gui.util.GuiHelper;
     
    249249            OsmPrimitive p = getPrimitiveToZoom();
    250250            if (p != null) {
    251                 OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    252                 if (editLayer != null) {
    253                     editLayer.data.setSelected(p.getPrimitiveId());
     251                DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     252                if (ds != null) {
     253                    ds.setSelected(p.getPrimitiveId());
    254254                    AutoScaleAction.autoScale("selection");
    255255                }
     
    265265            if (primitiveId == null)
    266266                return null;
    267             OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    268             if (editLayer == null)
     267            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     268            if (ds == null)
    269269                return null;
    270             return editLayer.data.getPrimitiveById(primitiveId);
     270            return ds.getPrimitiveById(primitiveId);
    271271        }
    272272
    273273        public void updateEnabledState() {
    274             setEnabled(MainApplication.getLayerManager().getEditLayer() != null && getPrimitiveToZoom() != null);
     274            setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null && getPrimitiveToZoom() != null);
    275275        }
    276276    }
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractModifiableLayer.java

    r9751 r13434  
    22package org.openstreetmap.josm.gui.layer;
    33
     4import org.openstreetmap.josm.data.osm.ReadOnly;
    45import org.openstreetmap.josm.gui.io.AbstractIOTask;
    56import org.openstreetmap.josm.gui.io.AbstractUploadDialog;
     
    1011 * @since 7358
    1112 */
    12 public abstract class AbstractModifiableLayer extends Layer implements UploadToServer, SaveToFile {
     13public abstract class AbstractModifiableLayer extends Layer implements UploadToServer, SaveToFile, ReadOnly {
    1314
    1415    /**
     
    2021    }
    2122
    22     /**
    23      * Determines if the layer is able to upload data and implements the
    24      * {@code UploadToServer} interface.
    25      *
    26      * @return true if the layer is able to upload data; false, otherwise
    27      */
    2823    @Override
    2924    public boolean isUploadable() {
     
    3227    }
    3328
    34     /**
    35      * Determines if the data managed by this layer needs to be uploaded to
    36      * the server because it contains modified data.
    37      *
    38      * @return true if the data managed by this layer needs to be uploaded to
    39      * the server because it contains modified data; false, otherwise
    40      */
    4129    @Override
    4230    public boolean requiresUploadToServer() {
     
    4533    }
    4634
    47     /**
    48      * Determines if the data managed by this layer needs to be saved to
    49      * a file. Only replies true if a file is assigned to this layer and
    50      * if the data managed by this layer has been modified since the last
    51      * save operation to the file.
    52      *
    53      * @return true if the data managed by this layer needs to be saved to a file
    54      */
    5535    @Override
    5636    public boolean requiresSaveToFile() {
     
    5939    }
    6040
    61     /**
    62      * Determines if upload of data managed by this layer is discouraged.
    63      * This feature allows to use "private" data layers.
    64      *
    65      * @return true if upload is discouraged for this layer; false, otherwise
    66      */
    6741    @Override
    6842    public boolean isUploadDiscouraged() {
     
    7751    public abstract boolean isModified();
    7852
    79     /**
    80      * Initializes the layer after a successful save of data to a file.
    81      */
    8253    @Override
    8354    public void onPostSaveToFile() {
     
    9364    }
    9465
    95     /**
    96      * Creates a new {@code AbstractIOTask} for uploading data.
    97      * @param monitor The progress monitor
    98      * @return a new {@code AbstractIOTask} for uploading data, or {@code null} if not applicable
    99      */
    10066    @Override
    10167    public AbstractIOTask createUploadTask(ProgressMonitor monitor) {
     
    10470    }
    10571
    106     /**
    107      * Returns the upload dialog for this layer.
    108      * @return the upload dialog for this layer, or {@code null} if not applicable
    109      */
    11072    @Override
    11173    public AbstractUploadDialog getUploadDialog() {
     
    11375        return null;
    11476    }
     77
     78    @Override
     79    public boolean isUploadInProgress() {
     80        // Override if needed
     81        return false;
     82    }
     83
     84    @Override
     85    public void setReadOnly() {
     86        // Override if needed
     87    }
     88
     89    @Override
     90    public void unsetReadOnly() {
     91        // Override if needed
     92    }
     93
     94    @Override
     95    public boolean isReadOnly() {
     96        // Override if needed
     97        return false;
     98    }
    11599}
  • trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java

    r13219 r13434  
    4848
    4949    /**
    50      * This event is fired whenever the active or the edit layer changes.
     50     * This event is fired whenever the active or the data layer changes.
    5151     * @author Michael Zangl
    5252     */
    5353    public static class ActiveLayerChangeEvent extends LayerManagerEvent {
    5454
    55         private final OsmDataLayer previousEditLayer;
     55        private final OsmDataLayer previousDataLayer;
    5656
    5757        private final Layer previousActiveLayer;
     
    6060         * Create a new {@link ActiveLayerChangeEvent}
    6161         * @param source The source
    62          * @param previousEditLayer the previous edit layer
     62         * @param previousDataLayer the previous data layer
    6363         * @param previousActiveLayer the previous active layer
    6464         */
    65         ActiveLayerChangeEvent(MainLayerManager source, OsmDataLayer previousEditLayer,
     65        ActiveLayerChangeEvent(MainLayerManager source, OsmDataLayer previousDataLayer,
    6666                Layer previousActiveLayer) {
    6767            super(source);
    68             this.previousEditLayer = previousEditLayer;
     68            this.previousDataLayer = previousDataLayer;
    6969            this.previousActiveLayer = previousActiveLayer;
    7070        }
    7171
    7272        /**
    73          * Gets the edit layer that was previously used.
    74          * @return The old edit layer, <code>null</code> if there is none.
    75          */
     73         * Gets the data layer that was previously used.
     74         * @return The old data layer, <code>null</code> if there is none.
     75         * @deprecated use {@link #getPreviousDataLayer}
     76         */
     77        @Deprecated
    7678        public OsmDataLayer getPreviousEditLayer() {
    77             return previousEditLayer;
     79            return getPreviousDataLayer();
     80        }
     81
     82        /**
     83         * Gets the data layer that was previously used.
     84         * @return The old data layer, <code>null</code> if there is none.
     85         * @since 13434
     86         */
     87        public OsmDataLayer getPreviousDataLayer() {
     88            return previousDataLayer;
    7889        }
    7990
     
    8899        /**
    89100         * Gets the data set that was previously used.
    90          * @return The data set of {@link #getPreviousEditLayer()}.
    91          */
     101         * @return The data set of {@link #getPreviousDataLayer()}.
     102         * @deprecated use {@link #getPreviousDataSet}
     103         */
     104        @Deprecated
    92105        public DataSet getPreviousEditDataSet() {
    93             if (previousEditLayer != null) {
    94                 return previousEditLayer.data;
     106            return getPreviousDataSet();
     107        }
     108
     109        /**
     110         * Gets the data set that was previously used.
     111         * @return The data set of {@link #getPreviousDataLayer()}.
     112         * @since 13434
     113         */
     114        public DataSet getPreviousDataSet() {
     115            if (previousDataLayer != null) {
     116                return previousDataLayer.data;
    95117            } else {
    96118                return null;
     
    151173
    152174    /**
    153      * The edit layer is the current active data layer.
    154      */
    155     private OsmDataLayer editLayer;
     175     * The current active data layer. It might be editable or not, based on its read-only status.
     176     */
     177    private OsmDataLayer dataLayer;
    156178
    157179    private final List<ActiveLayerChangeListener> activeLayerChangeListeners = new CopyOnWriteArrayList<>();
     
    214236
    215237    /**
    216      * Set the active layer, unless the layer is read-only.
     238     * Set the active layer, unless the layer is being uploaded.
    217239     * If the layer is an OsmDataLayer, the edit layer is also changed.
    218240     * @param layer The active layer.
     
    221243        // we force this on to the EDT Thread to make events fire from there.
    222244        // The synchronization lock needs to be held by the EDT.
    223         if (layer instanceof OsmDataLayer && ((OsmDataLayer) layer).isReadOnly()) {
     245        if (layer instanceof OsmDataLayer && ((OsmDataLayer) layer).isUploadInProgress()) {
    224246            GuiHelper.runInEDT(() ->
    225247                    JOptionPane.showMessageDialog(
     
    240262
    241263    private void setActiveLayer(Layer layer, boolean forceEditLayerUpdate) {
    242         ActiveLayerChangeEvent event = new ActiveLayerChangeEvent(this, editLayer, activeLayer);
     264        ActiveLayerChangeEvent event = new ActiveLayerChangeEvent(this, dataLayer, activeLayer);
    243265        activeLayer = layer;
    244266        if (activeLayer instanceof OsmDataLayer) {
    245             editLayer = (OsmDataLayer) activeLayer;
     267            dataLayer = (OsmDataLayer) activeLayer;
    246268        } else if (forceEditLayerUpdate) {
    247             editLayer = null;
     269            dataLayer = null;
    248270        }
    249271        fireActiveLayerChange(event);
     
    252274    private void fireActiveLayerChange(ActiveLayerChangeEvent event) {
    253275        GuiHelper.assertCallFromEdt();
    254         if (event.getPreviousActiveLayer() != activeLayer || event.getPreviousEditLayer() != editLayer) {
     276        if (event.getPreviousActiveLayer() != activeLayer || event.getPreviousDataLayer() != dataLayer) {
    255277            for (ActiveLayerChangeListener l : activeLayerChangeListeners) {
    256278                l.activeOrEditLayerChanged(event);
     
    277299    @Override
    278300    protected Collection<Layer> realRemoveSingleLayer(Layer layer) {
    279         if ((layer instanceof OsmDataLayer) && (((OsmDataLayer) layer).isReadOnly())) {
     301        if ((layer instanceof OsmDataLayer) && (((OsmDataLayer) layer).isUploadInProgress())) {
    280302            GuiHelper.runInEDT(() -> JOptionPane.showMessageDialog(MainApplication.parent,
    281303                    tr("Trying to delete the layer with background upload. Please wait until the upload is finished.")));
     
    285307        }
    286308
    287         if (layer == activeLayer || layer == editLayer) {
     309        if (layer == activeLayer || layer == dataLayer) {
    288310            Layer nextActive = suggestNextActiveLayer(layer);
    289311            setActiveLayer(nextActive, true);
     
    337359    public synchronized Layer getActiveLayer() {
    338360        if (activeLayer instanceof OsmDataLayer) {
    339             if (!((OsmDataLayer) activeLayer).isReadOnly()) {
     361            if (!((OsmDataLayer) activeLayer).isUploadInProgress()) {
    340362                return activeLayer;
    341363            } else {
     
    351373     *
    352374     * @return the current edit layer. May be null.
     375     * @see #getActiveDataLayer
    353376     */
    354377    public synchronized OsmDataLayer getEditLayer() {
    355         if (editLayer != null && !editLayer.isReadOnly())
    356             return editLayer;
     378        if (dataLayer != null && !dataLayer.isReadOnly())
     379            return dataLayer;
    357380        else
    358381            return null;
     
    360383
    361384    /**
    362      * Gets the data set of the active edit layer.
     385     * Replies the active data layer. The layer can be read-only.
     386     *
     387     * @return the current data layer. May be null or read-only.
     388     * @see #getEditLayer
     389     * @since 13434
     390     */
     391    public synchronized OsmDataLayer getActiveDataLayer() {
     392        if (dataLayer != null)
     393            return dataLayer;
     394        else
     395            return null;
     396    }
     397
     398    /**
     399     * Gets the data set of the active edit layer, if not readOnly.
    363400     * @return That data set, <code>null</code> if there is no edit layer.
     401     * @see #getActiveDataSet
    364402     */
    365403    public synchronized DataSet getEditDataSet() {
    366         if (editLayer != null) {
    367             return editLayer.data;
     404        if (dataLayer != null && !dataLayer.isReadOnly()) {
     405            return dataLayer.data;
     406        } else {
     407            return null;
     408        }
     409    }
     410
     411    /**
     412     * Gets the data set of the active data layer. The dataset can be read-only.
     413     * @return That data set, <code>null</code> if there is no active data layer.
     414     * @see #getEditDataSet
     415     * @since 13434
     416     */
     417    public synchronized DataSet getActiveDataSet() {
     418        if (dataLayer != null) {
     419            return dataLayer.data;
    368420        } else {
    369421            return null;
     
    413465     */
    414466    public void invalidateEditLayer() {
    415         if (editLayer != null) {
    416             editLayer.invalidate();
     467        if (dataLayer != null) {
     468            dataLayer.invalidate();
    417469        }
    418470    }
     
    445497     */
    446498    public void prepareLayerForUpload(OsmDataLayer layer) {
    447 
    448499        GuiHelper.assertCallFromEdt();
     500        layer.setUploadInProgress();
    449501        layer.setReadOnly();
    450502
    451503        // Reset only the edit layer as empty
    452         if (editLayer == layer) {
    453             ActiveLayerChangeEvent activeLayerChangeEvent = new ActiveLayerChangeEvent(this, editLayer, activeLayer);
    454             editLayer = null;
     504        if (dataLayer == layer) {
     505            ActiveLayerChangeEvent activeLayerChangeEvent = new ActiveLayerChangeEvent(this, dataLayer, activeLayer);
     506            dataLayer = null;
    455507            fireActiveLayerChange(activeLayerChangeEvent);
    456508        }
     
    467519        GuiHelper.assertCallFromEdt();
    468520        layer.unsetReadOnly();
     521        layer.unsetUploadInProgress();
    469522
    470523        // Set the layer as edit layer if the edit layer is empty.
    471         if (editLayer == null) {
    472             ActiveLayerChangeEvent layerChangeEvent = new ActiveLayerChangeEvent(this, editLayer, activeLayer);
    473             editLayer = layer;
     524        if (dataLayer == null) {
     525            ActiveLayerChangeEvent layerChangeEvent = new ActiveLayerChangeEvent(this, dataLayer, activeLayer);
     526            dataLayer = layer;
    474527            fireActiveLayerChange(layerChangeEvent);
    475528        }
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r13210 r13434  
    131131    private boolean requiresSaveToFile;
    132132    private boolean requiresUploadToServer;
    133     /** Flag used to know if the layer should not be editable */
    134     private final AtomicBoolean isReadOnly = new AtomicBoolean(false);
     133    /** Flag used to know if the layer is being uploaded */
     134    private final AtomicBoolean isUploadInProgress = new AtomicBoolean(false);
    135135
    136136    /**
     
    425425        }
    426426
    427         if (isReadOnly()) {
    428             // If the layer is read only then change the default icon to a clock
     427        if (isUploadInProgress()) {
     428            // If the layer is being uploaded then change the default icon to a clock
    429429            base = new ImageProvider("clock").setMaxSize(ImageSizes.LAYER);
     430        } else if (isReadOnly()) {
     431            // If the layer is read only then change the default icon to a lock
     432            base = new ImageProvider("lock").setMaxSize(ImageSizes.LAYER);
    430433        }
    431434        return base.get();
     
    11701173    }
    11711174
    1172     /**
    1173      * Sets the isReadOnly flag for the OsmDataLayer as true
    1174      */
     1175    @Override
    11751176    public void setReadOnly() {
    1176         if (!isReadOnly.compareAndSet(false, true)) {
    1177             Logging.warn("Trying to set readOnly flag on a readOnly layer ", this.getName());
    1178         }
    1179     }
    1180 
    1181     /**
    1182      * Sets the isReadOnly flag for the OsmDataLayer as false
    1183      */
     1177        data.setReadOnly();
     1178    }
     1179
     1180    @Override
    11841181    public void unsetReadOnly() {
    1185         if (!isReadOnly.compareAndSet(true, false)) {
    1186             Logging.warn("Trying to unset readOnly flag on a non-readOnly layer ", this.getName());
    1187         }
    1188     }
    1189 
    1190     /**
    1191      * Returns the value of the isReadOnly flag for the OsmDataLayer
    1192      * @return isReadOnly
    1193      */
     1182        data.unsetReadOnly();
     1183    }
     1184
     1185    @Override
    11941186    public boolean isReadOnly() {
    1195         return isReadOnly.get();
     1187        return data.isReadOnly();
     1188    }
     1189
     1190    public void setUploadInProgress() {
     1191        if (!isUploadInProgress.compareAndSet(false, true)) {
     1192            Logging.warn("Trying to set uploadInProgress flag on layer already being uploaded ", getName());
     1193        }
     1194    }
     1195
     1196    public void unsetUploadInProgress() {
     1197        if (!isUploadInProgress.compareAndSet(true, false)) {
     1198            Logging.warn("Trying to unset uploadInProgress flag on layer not being uploaded ", getName());
     1199        }
     1200    }
     1201
     1202    @Override
     1203    public boolean isUploadInProgress() {
     1204        return isUploadInProgress.get();
    11961205    }
    11971206}
  • trunk/src/org/openstreetmap/josm/gui/layer/UploadToServer.java

    r9751 r13434  
    4040
    4141    /**
     42     * Determines if upload of data managed by this layer is currently in progress.
     43     *
     44     * @return {@code true} if upload is in progress
     45     * @since 13434
     46     */
     47    boolean isUploadInProgress();
     48
     49    /**
    4250     * Initializes the layer after a successful upload to the server.
    4351     */
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java

    r12636 r13434  
    6767        public void updateEnabledState() {
    6868            setEnabled(MainApplication.isDisplayingMapView()
    69                     && (MainApplication.getLayerManager().getEditLayer() != null || mapHasGpxorMarkerLayer()));
     69                    && (MainApplication.getLayerManager().getActiveDataSet() != null || mapHasGpxorMarkerLayer()));
    7070        }
    7171
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java

    r13173 r13434  
    145145     * Constructs a new {@code AutoCompletionManager}.
    146146     * @param ds data set
     147     * @throws NullPointerException if ds is null
    147148     */
    148149    public AutoCompletionManager(DataSet ds) {
    149         this.ds = ds;
     150        this.ds = Objects.requireNonNull(ds);
    150151        this.dirty = true;
    151152    }
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java

    r13069 r13434  
    77import java.awt.event.KeyEvent;
    88import java.util.HashSet;
    9 import java.util.Set;
    109
    1110import org.openstreetmap.josm.Main;
    1211import org.openstreetmap.josm.actions.JosmAction;
    13 import org.openstreetmap.josm.data.osm.OsmPrimitive;
     12import org.openstreetmap.josm.data.osm.DataSet;
    1413import org.openstreetmap.josm.gui.ExtendedDialog;
    1514import org.openstreetmap.josm.gui.MainApplication;
     
    4443        @Override
    4544        public void actionPerformed(ActionEvent e) {
    46             if (MainApplication.getLayerManager().getEditLayer() != null) {
     45            if (MainApplication.getLayerManager().getActiveDataSet() != null) {
    4746                TaggingPresetSearchPrimitiveDialog.getInstance().showDialog();
    4847            }
     
    5150        @Override
    5251        protected void updateEnabledState() {
    53             setEnabled(getLayerManager().getEditLayer() != null);
     52            setEnabled(getLayerManager().getActiveDataSet() != null);
    5453        }
    5554    }
     
    8786            TaggingPreset preset = selector.getSelectedPresetAndUpdateClassification();
    8887            if (preset != null) {
    89                 final Set<OsmPrimitive> matching = new HashSet<>(Main.main.getEditDataSet().getPrimitives(preset));
    90                 Main.main.getEditDataSet().setSelected(matching);
     88                DataSet ds = Main.main.getActiveDataSet();
     89                ds.setSelected(new HashSet<>(ds.getPrimitives(preset)));
    9190            }
    9291        }
  • trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java

    r12636 r13434  
    132132     */
    133133    public static void clearAllHighlighted() {
    134         DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     134        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    135135        if (ds != null) {
    136136            for (OsmPrimitive p: ds.allNonDeletedPrimitives()) {
Note: See TracChangeset for help on using the changeset viewer.