Changeset 13434 in josm for trunk/src


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

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

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
103 edited

Legend:

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

    r13326 r13434  
    270270
    271271    /**
    272      * Gets the active edit data set.
     272     * Gets the active edit data set (not read-only).
    273273     * @return That data set, <code>null</code>.
     274     * @see #getActiveDataSet
    274275     * @since 12691
    275276     */
     
    277278
    278279    /**
    279      * Sets the active data set.
    280      * @param ds New edit data set, or <code>null</code>
    281      * @since 12718
    282      */
    283     public abstract void setEditDataSet(DataSet ds);
     280     * Gets the active data set (can be read-only).
     281     * @return That data set, <code>null</code>.
     282     * @see #getEditDataSet
     283     * @since 13434
     284     */
     285    public abstract DataSet getActiveDataSet();
     286
     287    /**
     288     * Sets the active data set (and also edit data set if not read-only).
     289     * @param ds New data set, or <code>null</code>
     290     * @since 13434
     291     */
     292    public abstract void setActiveDataSet(DataSet ds);
    284293
    285294    /**
  • trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java

    r12630 r13434  
    101101    protected void launchInfoBrowsersForSelectedPrimitivesAndNote() {
    102102        List<OsmPrimitive> primitivesToShow = new ArrayList<>();
    103         DataSet ds = getLayerManager().getEditDataSet();
     103        DataSet ds = getLayerManager().getActiveDataSet();
    104104        if (ds != null) {
    105105            primitivesToShow.addAll(ds.getAllSelected());
     
    155155    @Override
    156156    protected void updateEnabledState() {
    157         DataSet ds = getLayerManager().getEditDataSet();
     157        DataSet ds = getLayerManager().getActiveDataSet();
    158158        setEnabled(ds != null && !ds.selectionEmpty());
    159159    }
  • trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java

    r13107 r13434  
    340340    @Override
    341341    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    342         setEnabled(selection != null && !selection.isEmpty());
     342        updateEnabledStateOnModifiableSelection(selection);
    343343    }
    344344
  • trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java

    r13108 r13434  
    434434    @Override
    435435    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    436         setEnabled(selection != null && !selection.isEmpty());
     436        updateEnabledStateOnModifiableSelection(selection);
    437437    }
    438438}
  • trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java

    r12853 r13434  
    7676     */
    7777    public static void zoomToSelection() {
    78         DataSet dataSet = MainApplication.getLayerManager().getEditDataSet();
     78        DataSet dataSet = MainApplication.getLayerManager().getActiveDataSet();
    7979        if (dataSet == null) {
    8080            return;
     
    286286        Collection<OsmPrimitive> sel = new HashSet<>();
    287287        if ("selection".equals(mode)) {
    288             DataSet dataSet = getLayerManager().getEditDataSet();
     288            DataSet dataSet = getLayerManager().getActiveDataSet();
    289289            if (dataSet != null) {
    290290                sel = dataSet.getSelected();
     
    324324            lastZoomTime = -1;
    325325        }
    326         final DataSet dataset = getLayerManager().getEditDataSet();
     326        final DataSet dataset = getLayerManager().getActiveDataSet();
    327327        if (dataset != null) {
    328328            List<DataSource> dataSources = new ArrayList<>(dataset.getDataSources());
     
    337337                } else {
    338338                    lastZoomArea = -1;
    339                     Area sourceArea = getLayerManager().getEditDataSet().getDataSourceArea();
     339                    Area sourceArea = getLayerManager().getActiveDataSet().getDataSourceArea();
    340340                    if (sourceArea != null) {
    341341                        v.visit(new Bounds(sourceArea.getBounds2D()));
     
    353353    @Override
    354354    protected void updateEnabledState() {
    355         DataSet ds = getLayerManager().getEditDataSet();
     355        DataSet ds = getLayerManager().getActiveDataSet();
    356356        MapFrame map = MainApplication.getMap();
    357357        switch (mode) {
  • trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java

    r12641 r13434  
    251251    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    252252        int numWays = 0;
    253         for (OsmPrimitive osm : selection) {
    254             if (osm instanceof Way && !osm.isIncomplete() && ++numWays >= 2) {
    255                 break;
     253        if (selection.stream().map(o -> o.getDataSet()).noneMatch(DataSet::isReadOnly)) {
     254            for (OsmPrimitive osm : selection) {
     255                if (osm instanceof Way && !osm.isIncomplete() && ++numWays >= 2) {
     256                    break;
     257                }
    256258            }
    257259        }
  • trunk/src/org/openstreetmap/josm/actions/CopyAction.java

    r12639 r13434  
    4343    @Override
    4444    public void actionPerformed(ActionEvent e) {
    45         DataSet set = getLayerManager().getEditDataSet();
     45        DataSet set = getLayerManager().getActiveDataSet();
    4646        Collection<OsmPrimitive> selection = set == null ? Collections.<OsmPrimitive>emptySet() : set.getSelected();
    4747        if (selection.isEmpty()) {
     
    5050        }
    5151
    52         copy(getLayerManager().getEditLayer(), selection);
     52        copy(getLayerManager().getActiveDataLayer(), selection);
    5353    }
    5454
     
    6666    @Override
    6767    protected void updateEnabledState() {
    68         updateEnabledStateOnCurrentSelection();
     68        updateEnabledStateOnCurrentSelection(true);
    6969    }
    7070
  • trunk/src/org/openstreetmap/josm/actions/CopyCoordinatesAction.java

    r13106 r13434  
    5555
    5656    private Collection<Node> getSelectedNodes() {
    57         DataSet ds = getLayerManager().getEditDataSet();
     57        DataSet ds = getLayerManager().getActiveDataSet();
    5858        if (ds == null) {
    5959            return Collections.emptyList();
  • trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java

    r13107 r13434  
    297297    @Override
    298298    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    299         setEnabled(selection != null && !selection.isEmpty());
     299        updateEnabledStateOnModifiableSelection(selection);
    300300    }
    301301}
  • trunk/src/org/openstreetmap/josm/actions/DeleteAction.java

    r12763 r13434  
    8282    @Override
    8383    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    84         setEnabled(selection != null && !selection.isEmpty());
     84        updateEnabledStateOnModifiableSelection(selection);
    8585    }
    8686
  • trunk/src/org/openstreetmap/josm/actions/DistributeAction.java

    r12641 r13434  
    305305    @Override
    306306    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    307         setEnabled(selection != null && !selection.isEmpty());
     307        updateEnabledStateOnModifiableSelection(selection);
    308308    }
    309309}
  • trunk/src/org/openstreetmap/josm/actions/DownloadReferrersAction.java

    r12636 r13434  
    6666    @Override
    6767    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    68         setEnabled(selection != null && !selection.isEmpty());
     68        updateEnabledStateOnModifiableSelection(selection);
    6969    }
    7070}
  • trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java

    r10766 r13434  
    4343    @Override
    4444    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    45         setEnabled(selection != null && !selection.isEmpty());
     45        updateEnabledStateOnModifiableSelection(selection);
    4646    }
    4747}
  • trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java

    r12726 r13434  
    5656    @Override
    5757    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    58         setEnabled(selection != null && !selection.isEmpty());
     58        updateEnabledStateOnModifiableSelection(selection);
    5959    }
    6060
  • trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java

    r12637 r13434  
    3838    @Override
    3939    public void actionPerformed(ActionEvent ae) {
    40         DataSet set = getLayerManager().getEditDataSet();
     40        DataSet set = getLayerManager().getActiveDataSet();
    4141        if (set != null && !set.selectionEmpty()) {
    4242            HistoryBrowserDialogManager.getInstance().showHistory(set.getAllSelected());
  • trunk/src/org/openstreetmap/josm/actions/InfoAction.java

    r12672 r13434  
    3434    @Override
    3535    public void actionPerformed(ActionEvent ae) {
    36         DataSet set = getLayerManager().getEditDataSet();
     36        DataSet set = getLayerManager().getActiveDataSet();
    3737        if (set != null) {
    3838            new InspectPrimitiveDialog(set.getAllSelected(), set).showDialog();
     
    4242    @Override
    4343    public void updateEnabledState() {
    44         updateEnabledStateOnCurrentSelection();
     44        updateEnabledStateOnCurrentSelection(true);
    4545    }
    4646
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r13173 r13434  
    16191619    @Override
    16201620    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    1621         setEnabled(selection != null && !selection.isEmpty());
     1621        updateEnabledStateOnModifiableSelection(selection);
    16221622    }
    16231623}
  • trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

    r12778 r13434  
    215215    @Override
    216216    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    217         setEnabled(selection != null && !selection.isEmpty());
     217        updateEnabledStateOnModifiableSelection(selection);
    218218    }
    219219}
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r12749 r13434  
    335335     * Updates enabled state according to primitives currently selected in edit data set, if any.
    336336     * Can be called in {@link #updateEnabledState()} implementations.
     337     * @see #updateEnabledStateOnCurrentSelection(boolean)
    337338     * @since 10409
    338339     */
    339340    protected final void updateEnabledStateOnCurrentSelection() {
    340         DataSet ds = getLayerManager().getEditDataSet();
    341         if (ds == null) {
     341        updateEnabledStateOnCurrentSelection(false);
     342    }
     343
     344    /**
     345     * Updates enabled state according to primitives currently selected in active data set, if any.
     346     * Can be called in {@link #updateEnabledState()} implementations.
     347     * @param allowReadOnly if {@code true}, read-only data sets are considered
     348     * @since 13434
     349     */
     350    protected final void updateEnabledStateOnCurrentSelection(boolean allowReadOnly) {
     351        DataSet ds = getLayerManager().getActiveDataSet();
     352        if (ds != null && (allowReadOnly || !ds.isReadOnly())) {
     353            updateEnabledState(ds.getSelected());
     354        } else {
    342355            setEnabled(false);
    343         } else {
    344             updateEnabledState(ds.getSelected());
    345         }
     356        }
     357    }
     358
     359    /**
     360     * Updates enabled state according to selected primitives, if any.
     361     * Enables action if the colleciton is not empty and references primitives in a modifiable data layer.
     362     * Can be called in {@link #updateEnabledState(Collection)} implementations.
     363     * @param selection the collection of selected primitives
     364     * @since 13434
     365     */
     366    protected final void updateEnabledStateOnModifiableSelection(Collection<? extends OsmPrimitive> selection) {
     367        setEnabled(selection != null && !selection.isEmpty()
     368                && selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isReadOnly));
    346369    }
    347370
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r13189 r13434  
    2828import org.openstreetmap.josm.data.coor.EastNorth;
    2929import org.openstreetmap.josm.data.coor.LatLon;
     30import org.openstreetmap.josm.data.osm.DataSet;
    3031import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    3132import org.openstreetmap.josm.data.osm.Node;
     
    364365    @Override
    365366    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    366         if (selection == null || selection.isEmpty()) {
     367        if (selection == null || selection.isEmpty()
     368                || selection.stream().map(OsmPrimitive::getDataSet).anyMatch(DataSet::isReadOnly)) {
    367369            setEnabled(false);
    368370            return;
  • trunk/src/org/openstreetmap/josm/actions/MergeSelectionAction.java

    r11848 r13434  
    7676    @Override
    7777    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    78         setEnabled(selection != null && !selection.isEmpty());
     78        updateEnabledStateOnModifiableSelection(selection);
    7979    }
    8080
  • trunk/src/org/openstreetmap/josm/actions/MirrorAction.java

    r12641 r13434  
    9090    @Override
    9191    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    92         setEnabled(selection != null && !selection.isEmpty());
     92        updateEnabledStateOnModifiableSelection(selection);
    9393    }
    9494}
  • trunk/src/org/openstreetmap/josm/actions/MoveAction.java

    r13308 r13434  
    175175    @Override
    176176    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    177         setEnabled(selection != null && !selection.isEmpty());
     177        updateEnabledStateOnModifiableSelection(selection);
    178178    }
    179179}
  • trunk/src/org/openstreetmap/josm/actions/MoveNodeAction.java

    r12641 r13434  
    1111import org.openstreetmap.josm.command.MoveCommand;
    1212import org.openstreetmap.josm.data.coor.LatLon;
     13import org.openstreetmap.josm.data.osm.DataSet;
    1314import org.openstreetmap.josm.data.osm.Node;
    1415import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    6162    @Override
    6263    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    63         if (selection == null || selection.isEmpty()) {
     64        if (selection == null || selection.isEmpty()
     65                || selection.stream().map(OsmPrimitive::getDataSet).anyMatch(DataSet::isReadOnly)) {
    6466            setEnabled(false);
    6567            return;
  • trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    r13123 r13434  
    139139        @Override
    140140        protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    141             setEnabled(selection != null && !selection.isEmpty());
     141            updateEnabledStateOnModifiableSelection(selection);
    142142        }
    143143    }
     
    646646    @Override
    647647    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    648         setEnabled(selection != null && !selection.isEmpty());
     648        updateEnabledStateOnModifiableSelection(selection);
    649649    }
    650650}
  • trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java

    r12537 r13434  
    99import java.util.Collection;
    1010
    11 import org.openstreetmap.josm.data.osm.DataSet;
    1211import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1312import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler;
     
    5049    @Override
    5150    protected void updateEnabledState() {
    52         DataSet ds = getLayerManager().getEditDataSet();
    53         if (ds == null) {
    54             setEnabled(false);
    55             return;
    56         }
    57         // buffer listening slows down the program and is not very good for arbitrary text in buffer
    58         setEnabled(!ds.selectionEmpty());
     51        updateEnabledStateOnCurrentSelection();
    5952    }
    6053
    6154    @Override
    6255    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    63         setEnabled(selection != null && !selection.isEmpty());
     56        updateEnabledStateOnModifiableSelection(selection);
    6457    }
    6558}
  • trunk/src/org/openstreetmap/josm/actions/PurgeAction.java

    r13206 r13434  
    196196    @Override
    197197    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    198         setEnabled(selection != null && !selection.isEmpty());
     198        updateEnabledStateOnModifiableSelection(selection);
    199199    }
    200200}
  • trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java

    r13123 r13434  
    168168    @Override
    169169    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    170         setEnabled(selection.stream().anyMatch(o -> o instanceof Way && !o.isIncomplete()));
     170        setEnabled(selection.stream().anyMatch(
     171                o -> o instanceof Way && !o.isIncomplete() && !o.getDataSet().isReadOnly()));
    171172    }
    172173}
  • trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java

    r12581 r13434  
    3030        if (!isEnabled())
    3131            return;
    32         DataSet ds = getLayerManager().getEditDataSet();
     32        DataSet ds = getLayerManager().getActiveDataSet();
    3333        ds.setSelected(ds.getPrimitives(OsmPrimitive::isSelectable));
    3434    }
     
    3636    /**
    3737     * Refreshes the enabled state
    38      *
    3938     */
    4039    @Override
    4140    protected void updateEnabledState() {
    42         setEnabled(getLayerManager().getEditLayer() != null);
     41        setEnabled(getLayerManager().getActiveDataSet() != null);
    4342    }
    4443}
  • trunk/src/org/openstreetmap/josm/actions/SelectByInternalPointAction.java

    r12636 r13434  
    3838     */
    3939    public static Collection<OsmPrimitive> getSurroundingObjects(EastNorth internalPoint) {
    40         return getSurroundingObjects(MainApplication.getLayerManager().getEditDataSet(), internalPoint, false);
     40        return getSurroundingObjects(MainApplication.getLayerManager().getActiveDataSet(), internalPoint, false);
    4141    }
    4242
     
    103103    public static void performSelection(EastNorth internalPoint, boolean doAdd, boolean doRemove) {
    104104        final Collection<OsmPrimitive> surroundingObjects = getSurroundingObjects(internalPoint);
    105         final DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     105        final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    106106        if (surroundingObjects.isEmpty()) {
    107107            return;
  • trunk/src/org/openstreetmap/josm/actions/SelectNonBranchingWaySequencesAction.java

    r12636 r13434  
    3030    @Override
    3131    public void actionPerformed(ActionEvent ev) {
    32         DataSet ds = getLayerManager().getEditDataSet();
     32        DataSet ds = getLayerManager().getActiveDataSet();
    3333        SelectNonBranchingWaySequences ws = new SelectNonBranchingWaySequences(ds.getSelectedWays());
    3434        ws.extend(ds);
     
    4141    @Override
    4242    protected void updateEnabledState() {
    43         setEnabled(getLayerManager().getEditDataSet() != null);
     43        setEnabled(getLayerManager().getActiveDataSet() != null);
    4444    }
    4545}
  • trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java

    r12881 r13434  
    2727import org.openstreetmap.josm.data.osm.DataSet;
    2828import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
    29 import org.openstreetmap.josm.spi.preferences.Setting;
    3029import org.openstreetmap.josm.data.preferences.sources.MapPaintPrefHelper;
    3130import org.openstreetmap.josm.data.preferences.sources.PresetPrefHelper;
     
    3938import org.openstreetmap.josm.plugins.PluginHandler;
    4039import org.openstreetmap.josm.spi.preferences.Config;
     40import org.openstreetmap.josm.spi.preferences.Setting;
    4141import org.openstreetmap.josm.tools.Logging;
    4242import org.openstreetmap.josm.tools.PlatformHookUnixoid;
     
    178178        }
    179179        if (Main.main != null) {
    180             DataSet dataset = MainApplication.getLayerManager().getEditDataSet();
     180            DataSet dataset = MainApplication.getLayerManager().getActiveDataSet();
    181181            if (dataset != null) {
    182182                String result = DatasetConsistencyTest.runTests(dataset);
  • trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java

    r12846 r13434  
    301301    @Override
    302302    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    303         setEnabled(selection != null && !selection.isEmpty());
     303        updateEnabledStateOnModifiableSelection(selection);
    304304    }
    305305}
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r13206 r13434  
    2626import org.openstreetmap.josm.Main;
    2727import org.openstreetmap.josm.command.SplitWayCommand;
     28import org.openstreetmap.josm.data.osm.DataSet;
    2829import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
    2930import org.openstreetmap.josm.data.osm.Node;
     
    294295    @Override
    295296    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    296         if (selection == null) {
    297             setEnabled(false);
    298             return;
    299         }
    300         for (OsmPrimitive primitive: selection) {
    301             if (primitive instanceof Node) {
    302                 setEnabled(true); // Selection still can be wrong, but let SplitWayAction process and tell user what's wrong
    303                 return;
    304             }
    305         }
    306         setEnabled(false);
     297        // Selection still can be wrong, but let SplitWayAction process and tell user what's wrong
     298        setEnabled(selection != null && !selection.isEmpty()
     299                && selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isReadOnly)
     300                && selection.stream().anyMatch(o -> o instanceof Node && !o.isIncomplete()));
    307301    }
    308302}
  • trunk/src/org/openstreetmap/josm/actions/TaggingPresetSearchAction.java

    r12834 r13434  
    3131    public void actionPerformed(ActionEvent e) {
    3232
    33         if (MainApplication.getLayerManager().getEditLayer() == null)
     33        if (MainApplication.getLayerManager().getActiveDataSet() == null)
    3434            return;
    3535
  • trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java

    r12749 r13434  
    654654    @Override
    655655    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    656         setEnabled(selection != null && !selection.isEmpty());
     656        updateEnabledStateOnModifiableSelection(selection);
    657657    }
    658658
  • trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java

    r13329 r13434  
    177177    @Override
    178178    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    179         setEnabled(selection != null && !selection.isEmpty());
     179        updateEnabledStateOnModifiableSelection(selection);
    180180    }
    181181}
  • trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java

    r12581 r13434  
    3030        if (!isEnabled())
    3131            return;
    32         getLayerManager().getEditDataSet().setSelected();
     32        getLayerManager().getActiveDataSet().setSelected();
    3333    }
    3434
     
    3838    @Override
    3939    protected void updateEnabledState() {
    40         setEnabled(getLayerManager().getEditLayer() != null);
     40        setEnabled(getLayerManager().getActiveDataSet() != null);
    4141    }
    4242}
  • trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java

    r12809 r13434  
    6363    @Override
    6464    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    65         setEnabled(selection != null && !selection.isEmpty());
     65        updateEnabledStateOnModifiableSelection(selection);
    6666    }
    6767
  • trunk/src/org/openstreetmap/josm/actions/ValidateAction.java

    r12649 r13434  
    7676        Collection<OsmPrimitive> selection;
    7777        if (getSelectedItems) {
    78             selection = getLayerManager().getEditDataSet().getAllSelected();
     78            selection = getLayerManager().getActiveDataSet().getAllSelected();
    7979            if (selection.isEmpty()) {
    80                 selection = getLayerManager().getEditDataSet().allNonDeletedPrimitives();
     80                selection = getLayerManager().getActiveDataSet().allNonDeletedPrimitives();
    8181                lastSelection = null;
    8282            } else {
     
    8787        } else {
    8888            selection = Optional.ofNullable(lastSelection).orElseGet(
    89                     () -> getLayerManager().getEditDataSet().allNonDeletedPrimitives());
     89                    () -> getLayerManager().getActiveDataSet().allNonDeletedPrimitives());
    9090        }
    9191
     
    9595    @Override
    9696    public void updateEnabledState() {
    97         setEnabled(getLayerManager().getEditLayer() != null);
     97        setEnabled(getLayerManager().getActiveDataSet() != null);
    9898    }
    9999
     
    105105
    106106    /**
    107      * Asynchronous task for running a collection of tests against a collection
    108      * of primitives
    109      *
     107     * Asynchronous task for running a collection of tests against a collection of primitives
    110108     */
    111109    static class ValidationTask extends PleaseWaitRunnable {
     
    117115
    118116        /**
    119          *
     117         * Constructs a new {@code ValidationTask}
    120118         * @param tests  the tests to run
    121119         * @param validatedPrimitives the collection of primitives to validate.
  • trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java

    r12637 r13434  
    3838    @Override
    3939    protected void updateEnabledState() {
    40         setEnabled(getLayerManager().getEditLayer() != null);
     40        setEnabled(getLayerManager().getActiveDataSet() != null);
    4141    }
    4242
  • trunk/src/org/openstreetmap/josm/actions/ZoomToAction.java

    r12636 r13434  
    105105
    106106    protected final void updateEnabledState() {
    107         if (Main.main == null || MainApplication.getLayerManager().getEditLayer() != this.table.getLayer()) {
     107        if (Main.main == null || MainApplication.getLayerManager().getActiveDataLayer() != this.table.getLayer()) {
    108108            setEnabled(false);
    109109            putValue(SHORT_DESCRIPTION, descriptionInactiveLayer);
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r12679 r13434  
    1616import java.util.regex.Matcher;
    1717import java.util.regex.Pattern;
     18import java.util.stream.Stream;
    1819
    1920import org.openstreetmap.josm.data.Bounds;
     
    227228        }
    228229
     230        /**
     231         * Returns the number of modifiable data layers
     232         * @return number of modifiable data layers
     233         * @deprecated Use {@link #getNumModifiableDataLayers}
     234         */
     235        @Deprecated
    229236        protected int getNumDataLayers() {
    230             return MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).size();
    231         }
    232 
    233         protected OsmDataLayer getFirstDataLayer() {
    234             return Utils.find(MainApplication.getLayerManager().getLayers(), OsmDataLayer.class);
     237            return (int) getNumModifiableDataLayers();
     238        }
     239
     240        private static Stream<OsmDataLayer> getModifiableDataLayers() {
     241            return MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class)
     242                    .stream().filter(l -> !l.isReadOnly());
     243        }
     244
     245        /**
     246         * Returns the number of modifiable data layers
     247         * @return number of modifiable data layers
     248         * @since 13434
     249         */
     250        protected long getNumModifiableDataLayers() {
     251            return getModifiableDataLayers().count();
     252        }
     253
     254        /**
     255         * Returns the first modifiable data layer
     256         * @return the first modifiable data layer
     257         * @since 13434
     258         */
     259        protected OsmDataLayer getFirstModifiableDataLayer() {
     260            return getModifiableDataLayers().findFirst().orElse(null);
    235261        }
    236262
     
    257283
    258284        protected OsmDataLayer addNewLayerIfRequired(String newLayerName) {
    259             int numDataLayers = getNumDataLayers();
     285            long numDataLayers = getNumModifiableDataLayers();
    260286            if (newLayer || numDataLayers == 0 || (numDataLayers > 1 && getEditLayer() == null)) {
    261287                // the user explicitly wants a new layer, we don't have any layer at all
     
    272298            OsmDataLayer layer = addNewLayerIfRequired(newLayerName);
    273299            if (layer == null) {
    274                 layer = Optional.ofNullable(getEditLayer()).orElseGet(this::getFirstDataLayer);
     300                layer = Optional.ofNullable(getEditLayer()).orElseGet(this::getFirstModifiableDataLayer);
    275301                Collection<OsmPrimitive> primitivesToUpdate = searchPrimitivesToUpdate(bounds, layer.data);
    276302                layer.mergeFrom(dataSet);
  • trunk/src/org/openstreetmap/josm/actions/mapmode/AddNoteAction.java

    r12630 r13434  
    1717import org.openstreetmap.josm.gui.NoteInputDialog;
    1818import org.openstreetmap.josm.gui.Notification;
     19import org.openstreetmap.josm.gui.layer.Layer;
     20import org.openstreetmap.josm.gui.layer.NoteLayer;
    1921import org.openstreetmap.josm.gui.util.KeyPressReleaseListener;
    2022import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    100102        // Do nothing
    101103    }
     104
     105    @Override
     106    public boolean layerIsSupported(Layer l) {
     107        return l instanceof NoteLayer;
     108    }
    102109}
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r12846 r13434  
    320320    @Override
    321321    public boolean layerIsSupported(Layer l) {
    322         return l instanceof OsmDataLayer;
     322        return isEditableDataLayer(l);
    323323    }
    324324
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    r13334 r13434  
    13731373    @Override
    13741374    public boolean layerIsSupported(Layer l) {
    1375         return l instanceof OsmDataLayer;
     1375        return isEditableDataLayer(l);
    13761376    }
    13771377
  • trunk/src/org/openstreetmap/josm/actions/mapmode/DrawSnapHelper.java

    r12846 r13434  
    448448        projectionSource = null;
    449449        if (DrawAction.SNAP_TO_PROJECTIONS.get()) {
    450             DataSet ds = drawAction.getLayerManager().getEditDataSet();
     450            DataSet ds = drawAction.getLayerManager().getActiveDataSet();
    451451            Collection<Way> selectedWays = ds.getSelectedWays();
    452452            if (selectedWays.size() == 1) {
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

    r13135 r13434  
    5454import org.openstreetmap.josm.gui.layer.Layer;
    5555import org.openstreetmap.josm.gui.layer.MapViewPaintable;
    56 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5756import org.openstreetmap.josm.gui.util.GuiHelper;
    5857import org.openstreetmap.josm.gui.util.KeyPressReleaseListener;
     
    292291    @Override
    293292    public boolean layerIsSupported(Layer l) {
    294         return l instanceof OsmDataLayer;
     293        return isEditableDataLayer(l);
    295294    }
    296295
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java

    r13277 r13434  
    4747import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable;
    4848import org.openstreetmap.josm.gui.layer.Layer;
    49 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5049import org.openstreetmap.josm.gui.util.ModifierExListener;
    5150import org.openstreetmap.josm.tools.ImageProvider;
     
    210209    @Override
    211210    public boolean layerIsSupported(Layer l) {
    212         return l instanceof OsmDataLayer;
     211        return isEditableDataLayer(l);
    213212    }
    214213
  • trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r13309 r13434  
    1616import org.openstreetmap.josm.gui.MapFrame;
    1717import org.openstreetmap.josm.gui.layer.Layer;
     18import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1819import org.openstreetmap.josm.spi.preferences.Config;
    1920import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;
     
    240241        return Collections.emptySet();
    241242    }
     243
     244    /**
     245     * Determines if the given layer is a data layer that can be modified.
     246     * Useful for {@link #layerIsSupported(Layer)} implementations.
     247     * @param l layer
     248     * @return {@code true} if the given layer is a data layer that can be modified
     249     * @since 13434
     250     */
     251    protected boolean isEditableDataLayer(Layer l) {
     252        return l instanceof OsmDataLayer && !((OsmDataLayer) l).isReadOnly();
     253    }
    242254}
  • trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    r12987 r13434  
    3535import org.openstreetmap.josm.data.preferences.BooleanProperty;
    3636import org.openstreetmap.josm.data.preferences.CachingProperty;
    37 import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    3837import org.openstreetmap.josm.data.preferences.DoubleProperty;
    3938import org.openstreetmap.josm.data.preferences.IntegerProperty;
     39import org.openstreetmap.josm.data.preferences.NamedColorProperty;
    4040import org.openstreetmap.josm.data.preferences.StrokeProperty;
    4141import org.openstreetmap.josm.gui.MainApplication;
     
    4646import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable;
    4747import org.openstreetmap.josm.gui.layer.Layer;
    48 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4948import org.openstreetmap.josm.gui.util.ModifierExListener;
    5049import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    212211
    213212    @Override
    214     public boolean layerIsSupported(Layer layer) {
    215         return layer instanceof OsmDataLayer;
     213    public boolean layerIsSupported(Layer l) {
     214        return isEditableDataLayer(l);
    216215    }
    217216
  • trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java

    r13277 r13434  
    9292    enum SelectActionCursor {
    9393
    94         rect(NORMAL, /* ICON(cursor/modifier/)*/ "selection"), 
     94        rect(NORMAL, /* ICON(cursor/modifier/)*/ "selection"),
    9595        rect_add(NORMAL, /* ICON(cursor/modifier/)*/ "select_add"),
    9696        rect_rm(NORMAL, /* ICON(cursor/modifier/)*/ "select_remove"),
     
    102102        node_rm(NORMAL, /* ICON(cursor/modifier/)*/ "select_node_remove"),
    103103        virtual_node(NORMAL, /* ICON(cursor/modifier/)*/ "addnode"),
    104         scale(/* ICON(cursor/)*/ "scale", null), 
     104        scale(/* ICON(cursor/)*/ "scale", null),
    105105        rotate(/* ICON(cursor/)*/ "rotate", null),
    106106        merge(/* ICON(cursor/)*/ "crosshair", null),
    107         lasso(NORMAL, /* ICON(cursor/modifier/)*/ "rope"), 
     107        lasso(NORMAL, /* ICON(cursor/modifier/)*/ "rope"),
    108108        merge_to_node(/* ICON(cursor/)*/ "crosshair", /* ICON(cursor/modifier/)*/"joinnode"),
    109109        move(Cursor.MOVE_CURSOR);
     
    265265
    266266        virtualManager.clear();
    267         if (mode == Mode.MOVE && !dragInProgress() && virtualManager.activateVirtualNodeNearPoint(e.getPoint())) {
    268             DataSet ds = getLayerManager().getEditDataSet();
     267        if ((mode == Mode.MOVE || mode == Mode.SELECT)
     268                && !dragInProgress() && virtualManager.activateVirtualNodeNearPoint(e.getPoint())) {
     269            DataSet ds = getLayerManager().getActiveDataSet();
    269270            if (ds != null && drawTargetHighlight) {
    270271                ds.setHighlightedVirtualNodes(virtualManager.virtualWays);
     
    278279
    279280        // return early if there can't be any highlights
    280         if (!drawTargetHighlight || mode != Mode.MOVE || !c.isPresent())
     281        if (!drawTargetHighlight || (mode != Mode.MOVE && mode != Mode.SELECT) || !c.isPresent())
    281282            return repaintIfRequired(newHighlight);
    282283
     
    354355    private boolean removeHighlighting() {
    355356        boolean needsRepaint = false;
    356         DataSet ds = getLayerManager().getEditDataSet();
     357        DataSet ds = getLayerManager().getActiveDataSet();
    357358        if (ds != null && !ds.getHighlightedVirtualNodes().isEmpty()) {
    358359            needsRepaint = true;
     
    583584
    584585            // Select Draw Tool if no selection has been made
    585             if (!cancelDrawMode && getLayerManager().getEditDataSet().selectionEmpty()) {
     586            if (!cancelDrawMode && getLayerManager().getActiveDataSet().selectionEmpty()) {
    586587                map.selectDrawTool(true);
    587588                updateStatusLine();
     
    662663     */
    663664    private void determineMapMode(boolean hasSelectionNearby) {
    664         if (shift && ctrl) {
    665             mode = Mode.ROTATE;
    666         } else if (alt && ctrl) {
    667             mode = Mode.SCALE;
    668         } else if (hasSelectionNearby || dragInProgress()) {
    669             mode = Mode.MOVE;
    670         } else {
    671             mode = Mode.SELECT;
    672         }
     665        if (getLayerManager().getEditDataSet() != null) {
     666            if (shift && ctrl) {
     667                mode = Mode.ROTATE;
     668            } else if (alt && ctrl) {
     669                mode = Mode.SCALE;
     670            } else if (hasSelectionNearby || dragInProgress()) {
     671                mode = Mode.MOVE;
     672            }
     673        }
     674        mode = Mode.SELECT;
    673675    }
    674676
     
    956958
    957959    private void selectPrims(Collection<OsmPrimitive> prims, boolean released, boolean area) {
    958         DataSet ds = getLayerManager().getEditDataSet();
     960        DataSet ds = getLayerManager().getActiveDataSet();
    959961
    960962        // not allowed together: do not change dataset selection, return early
     
    11201122            // updateKeyModifiers() already called before!
    11211123
    1122             DataSet ds = getLayerManager().getEditDataSet();
     1124            DataSet ds = getLayerManager().getActiveDataSet();
    11231125            OsmPrimitive first = cycleList.iterator().next(), foundInDS = null;
    11241126            OsmPrimitive nxt = first;
  • trunk/src/org/openstreetmap/josm/actions/relation/AddSelectionToRelations.java

    r13130 r13434  
    1414import org.openstreetmap.josm.command.SequenceCommand;
    1515import org.openstreetmap.josm.data.SelectionChangedListener;
     16import org.openstreetmap.josm.data.osm.DataSet;
    1617import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1718import org.openstreetmap.josm.data.osm.Relation;
     
    3940        Collection<Command> cmds = new LinkedList<>();
    4041        for (Relation orig : relations) {
    41             Command c = GenericRelationEditor.addPrimitivesToRelation(orig, MainApplication.getLayerManager().getEditDataSet().getSelected());
     42            Command c = GenericRelationEditor.addPrimitivesToRelation(orig, MainApplication.getLayerManager().getActiveDataSet().getSelected());
    4243            if (c != null) {
    4344                cmds.add(c);
     
    5758    @Override
    5859    public void updateEnabledState() {
    59         putValue(NAME, trn("Add selection to {0} relation", "Add selection to {0} relations",
    60                 relations.size(), relations.size()));
     60        int size = relations.size();
     61        putValue(NAME, trn("Add selection to {0} relation", "Add selection to {0} relations", size, size));
     62        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     63        if (ds != null) {
     64            selectionChanged(ds.getSelected());
     65        } else {
     66            setEnabled(false);
     67        }
    6168    }
    6269
    6370    @Override
    6471    public void selectionChanged(final Collection<? extends OsmPrimitive> newSelection) {
    65         GuiHelper.runInEDT(() -> setEnabled(newSelection != null && !newSelection.isEmpty()));
     72        GuiHelper.runInEDT(() -> setEnabled(newSelection != null && !newSelection.isEmpty() && !relations.isEmpty()
     73                && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isReadOnly)));
    6674    }
    6775}
  • trunk/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java

    r12636 r13434  
    88
    99import org.openstreetmap.josm.actions.mapmode.DeleteAction;
     10import org.openstreetmap.josm.data.osm.DataSet;
    1011import org.openstreetmap.josm.data.osm.Relation;
    1112import org.openstreetmap.josm.gui.MainApplication;
     
    4748        deleteRelation(relations);
    4849    }
     50
     51    @Override
     52    protected void updateEnabledState() {
     53        setEnabled(!relations.isEmpty() && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isReadOnly));
     54    }
    4955}
  • trunk/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java

    r12636 r13434  
    5252    protected void updateEnabledState() {
    5353        // only one selected relation can be edited
    54         setEnabled(relations.size() == 1);
     54        setEnabled(relations.size() == 1 && !relations.iterator().next().getDataSet().isReadOnly());
    5555    }
    5656}
  • trunk/src/org/openstreetmap/josm/actions/relation/EditRelationAction.java

    r12846 r13434  
    1313
    1414import org.openstreetmap.josm.Main;
     15import org.openstreetmap.josm.data.osm.DataSet;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1617import org.openstreetmap.josm.data.osm.Relation;
     
    8889    protected void updateEnabledState() {
    8990        boolean enabled = false;
    90         for (Relation r : relations) {
    91             if (!r.isDeleted()) {
    92                 enabled = true;
    93                 break;
     91        if (relations.stream().map(r -> r.getDataSet()).noneMatch(DataSet::isReadOnly)) {
     92            for (Relation r : relations) {
     93                if (!r.isDeleted()) {
     94                    enabled = true;
     95                    break;
     96                }
    9497            }
    9598        }
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectMembersAction.java

    r13130 r13434  
    4343        }
    4444        if (add) {
    45             MainApplication.getLayerManager().getEditLayer().data.addSelected(members);
     45            MainApplication.getLayerManager().getActiveDataSet().addSelected(members);
    4646        } else {
    47             MainApplication.getLayerManager().getEditLayer().data.setSelected(members);
     47            MainApplication.getLayerManager().getActiveDataSet().setSelected(members);
    4848        }
    4949    }
  • trunk/src/org/openstreetmap/josm/actions/relation/SelectRelationAction.java

    r12636 r13434  
    66import java.awt.event.ActionEvent;
    77
     8import org.openstreetmap.josm.data.osm.DataSet;
    89import org.openstreetmap.josm.gui.MainApplication;
    9 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1010import org.openstreetmap.josm.tools.ImageProvider;
    1111
     
    3434    public void actionPerformed(ActionEvent e) {
    3535        if (!isEnabled() || relations.isEmpty()) return;
    36         OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();
    37         if (editLayer == null || editLayer.data == null) return;
     36        DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
     37        if (ds == null) return;
    3838        if (add) {
    39             editLayer.data.addSelected(relations);
     39            ds.addSelected(relations);
    4040        } else {
    41             editLayer.data.setSelected(relations);
     41            ds.setSelected(relations);
    4242        }
    4343    }
  • trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java

    r13432 r13434  
    761761
    762762        static SearchTask newSearchTask(SearchSetting setting, SearchReceiver resultReceiver) {
    763             final DataSet ds = MainApplication.getLayerManager().getEditDataSet();
     763            final DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    764764            return newSearchTask(setting, ds, resultReceiver);
    765765        }
     
    879879    /**
    880880     * Refreshes the enabled state
    881      *
    882881     */
    883882    @Override
    884883    protected void updateEnabledState() {
    885         setEnabled(getLayerManager().getEditLayer() != null);
     884        setEnabled(getLayerManager().getActiveDataSet() != null);
    886885    }
    887886
  • trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java

    r13173 r13434  
    7272            }
    7373
    74             Main.main.setEditDataSet(ds);
     74            Main.main.setActiveDataSet(ds);
    7575        }
    7676        reconstituteConflicts();
  • trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java

    r12726 r13434  
    7272    @Override
    7373    public void undoCommand() {
    74         DataSet editDs = getAffectedDataSet();
    75         if (!Main.main.containsDataSet(editDs)) {
     74        DataSet ds = getAffectedDataSet();
     75        if (!Main.main.containsDataSet(ds)) {
    7676            Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more",
    7777                    this.toString(),
    78                     editDs.getName()
     78                    ds.getName()
    7979            ));
    8080            return;
    8181        }
    8282
    83         Main.main.setEditDataSet(editDs);
     83        Main.main.setActiveDataSet(ds);
    8484
    8585        // restore the former state
     
    8989        // restore a conflict if necessary
    9090        //
    91         if (!editDs.getConflicts().hasConflictForMy(conflict.getMy())) {
    92             editDs.getConflicts().add(conflict);
     91        if (!ds.getConflicts().hasConflictForMy(conflict.getMy())) {
     92            ds.getConflicts().add(conflict);
    9393        }
    9494    }
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r13420 r13434  
    1717import java.util.Set;
    1818import java.util.concurrent.CopyOnWriteArrayList;
     19import java.util.concurrent.atomic.AtomicBoolean;
    1920import java.util.concurrent.locks.Lock;
    2021import java.util.concurrent.locks.ReadWriteLock;
     
    103104 * @author imi
    104105 */
    105 public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener {
     106public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener, ReadOnly {
    106107
    107108    /**
     
    143144            return xmlFlag;
    144145        }
     146
     147        /**
     148         * Returns the {@code UploadPolicy} for the given <code>upload='...'</code> XML-attribute
     149         * @param xmlFlag <code>upload='...'</code> XML-attribute to convert
     150         * @return {@code UploadPolicy} value
     151         * @throws IllegalArgumentException for invalid values
     152         * @since 13434
     153         */
     154        public static UploadPolicy of(String xmlFlag) {
     155            for (UploadPolicy policy : values()) {
     156                if (policy.getXmlFlag().equalsIgnoreCase(xmlFlag)) {
     157                    return policy;
     158                }
     159            }
     160            throw new IllegalArgumentException(xmlFlag);
     161        }
    145162    }
    146163
     
    171188    private String name;
    172189    private UploadPolicy uploadPolicy;
     190    /** Flag used to know if the dataset should not be editable */
     191    private final AtomicBoolean isReadOnly = new AtomicBoolean(false);
    173192
    174193    private final ReadWriteLock lock = new ReentrantReadWriteLock();
     
    259278            version = copyFrom.version;
    260279            uploadPolicy = copyFrom.uploadPolicy;
     280            isReadOnly.set(copyFrom.isReadOnly.get());
    261281        } finally {
    262282            copyFrom.getReadLock().unlock();
     
    353373     *
    354374     * @param version the API version, i.e. "0.6"
     375     * @throws IllegalStateException if the dataset is read-only
    355376     */
    356377    public void setVersion(String version) {
     378        checkModifiable();
    357379        this.version = version;
    358380    }
     
    533555     *
    534556     * @param primitive the primitive.
     557     * @throws IllegalStateException if the dataset is read-only
    535558     */
    536559    @Override
    537560    public void addPrimitive(OsmPrimitive primitive) {
    538561        Objects.requireNonNull(primitive, "primitive");
     562        checkModifiable();
    539563        beginUpdate();
    540564        try {
     
    561585     *
    562586     * @param primitiveId the id of the primitive
     587     * @throws IllegalStateException if the dataset is read-only
    563588     */
    564589    public void removePrimitive(PrimitiveId primitiveId) {
     590        checkModifiable();
    565591        beginUpdate();
    566592        try {
     
    587613    @Override
    588614    protected void removePrimitive(OsmPrimitive primitive) {
     615        checkModifiable();
    589616        beginUpdate();
    590617        try {
     
    9981025     * @param node the node
    9991026     * @return The set of ways that have been modified
     1027     * @throws IllegalStateException if the dataset is read-only
    10001028     */
    10011029    public Set<Way> unlinkNodeFromWays(Node node) {
     1030        checkModifiable();
    10021031        Set<Way> result = new HashSet<>();
    10031032        beginUpdate();
     
    10251054     * @param primitive the primitive
    10261055     * @return The set of relations that have been modified
     1056     * @throws IllegalStateException if the dataset is read-only
    10271057     */
    10281058    public Set<Relation> unlinkPrimitiveFromRelations(OsmPrimitive primitive) {
     1059        checkModifiable();
    10291060        Set<Relation> result = new HashSet<>();
    10301061        beginUpdate();
     
    10591090     * @param referencedPrimitive the referenced primitive
    10601091     * @return The set of primitives that have been modified
     1092     * @throws IllegalStateException if the dataset is read-only
    10611093     */
    10621094    public Set<OsmPrimitive> unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive) {
     1095        checkModifiable();
    10631096        Set<OsmPrimitive> result = new HashSet<>();
    10641097        beginUpdate();
     
    11311164     * }
    11321165     * </pre>
     1166     * @see #endUpdate()
    11331167     */
    11341168    public void beginUpdate() {
     
    11381172
    11391173    /**
     1174     * Must be called after a previous call to {@link #beginUpdate()} to fire change events.
     1175     * <br>
     1176     * Typical usecase should look like this:
     1177     * <pre>
     1178     * ds.beginUpdate();
     1179     * try {
     1180     *   ...
     1181     * } finally {
     1182     *   ds.endUpdate();
     1183     * }
     1184     * </pre>
    11401185     * @see DataSet#beginUpdate()
    11411186     */
     
    12731318     * Removes all primitives from the dataset and resets the currently selected primitives
    12741319     * to the empty collection. Also notifies selection change listeners if necessary.
     1320     * @throws IllegalStateException if the dataset is read-only
    12751321     */
    12761322    @Override
    12771323    public void clear() {
     1324        checkModifiable();
    12781325        beginUpdate();
    12791326        try {
     
    12921339     * Marks all "invisible" objects as deleted. These objects should be always marked as
    12931340     * deleted when downloaded from the server. They can be undeleted later if necessary.
    1294      *
     1341     * @throws IllegalStateException if the dataset is read-only
    12951342     */
    12961343    public void deleteInvisible() {
     1344        checkModifiable();
    12971345        for (OsmPrimitive primitive:allPrimitives) {
    12981346            if (!primitive.isVisible()) {
     
    13141362     * @param from The source DataSet
    13151363     * @param progressMonitor The progress monitor
     1364     * @throws IllegalStateException if the dataset is read-only
    13161365     */
    13171366    public synchronized void mergeFrom(DataSet from, ProgressMonitor progressMonitor) {
    13181367        if (from != null) {
     1368            checkModifiable();
    13191369            new DataSetMerger(this, from).merge(progressMonitor);
    13201370            synchronized (from) {
     
    14021452        mappaintCacheIdx++;
    14031453    }
     1454
     1455    @Override
     1456    public void setReadOnly() {
     1457        if (!isReadOnly.compareAndSet(false, true)) {
     1458            Logging.warn("Trying to set readOnly flag on a readOnly dataset ", getName());
     1459        }
     1460    }
     1461
     1462    @Override
     1463    public void unsetReadOnly() {
     1464        if (!isReadOnly.compareAndSet(true, false)) {
     1465            Logging.warn("Trying to unset readOnly flag on a non-readOnly dataset ", getName());
     1466        }
     1467    }
     1468
     1469    @Override
     1470    public boolean isReadOnly() {
     1471        return isReadOnly.get();
     1472    }
     1473
     1474    /**
     1475     * Checks the dataset is modifiable (not read-only).
     1476     * @throws IllegalStateException if the dataset is read-only
     1477     */
     1478    private void checkModifiable() {
     1479        if (isReadOnly()) {
     1480            throw new IllegalStateException("DataSet is read-only");
     1481        }
     1482    }
    14041483}
  • trunk/src/org/openstreetmap/josm/data/osm/FilterModel.java

    r13208 r13434  
    9898     */
    9999    public void executeFilters() {
    100         DataSet ds = Main.main.getEditDataSet();
     100        DataSet ds = Main.main.getActiveDataSet();
    101101        changed = false;
    102102        if (ds == null) {
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r13420 r13434  
    275275    }
    276276
     277    /**
     278     * Throws exception if primitive is in a read-only dataset
     279     */
     280    protected final void checkDatasetNotReadOnly() {
     281        if (dataSet != null && dataSet.isReadOnly())
     282            throw new DataIntegrityProblemException("Primitive cannot be modified in read-only dataset: " + toString());
     283    }
     284
    277285    protected boolean writeLock() {
    278286        if (dataSet != null) {
     
    305313    @Override
    306314    public void setOsmId(long id, int version) {
     315        checkDatasetNotReadOnly();
    307316        boolean locked = writeLock();
    308317        try {
     
    343352    @Override
    344353    public void setUser(User user) {
     354        checkDatasetNotReadOnly();
    345355        boolean locked = writeLock();
    346356        try {
     
    353363    @Override
    354364    public void setChangesetId(int changesetId) {
     365        checkDatasetNotReadOnly();
    355366        boolean locked = writeLock();
    356367        try {
     
    367378    @Override
    368379    public void setTimestamp(Date timestamp) {
     380        checkDatasetNotReadOnly();
    369381        boolean locked = writeLock();
    370382        try {
     
    534546    @Override
    535547    public void setModified(boolean modified) {
     548        checkDatasetNotReadOnly();
    536549        boolean locked = writeLock();
    537550        try {
     
    548561    @Override
    549562    public void setVisible(boolean visible) {
     563        checkDatasetNotReadOnly();
    550564        boolean locked = writeLock();
    551565        try {
     
    559573    @Override
    560574    public void setDeleted(boolean deleted) {
     575        checkDatasetNotReadOnly();
    561576        boolean locked = writeLock();
    562577        try {
     
    577592    @Override
    578593    protected final void setIncomplete(boolean incomplete) {
     594        checkDatasetNotReadOnly();
    579595        boolean locked = writeLock();
    580596        try {
     
    891907    @Override
    892908    public final void setKeys(TagMap keys) {
     909        checkDatasetNotReadOnly();
    893910        boolean locked = writeLock();
    894911        try {
     
    901918    @Override
    902919    public final void setKeys(Map<String, String> keys) {
     920        checkDatasetNotReadOnly();
    903921        boolean locked = writeLock();
    904922        try {
     
    911929    @Override
    912930    public final void put(String key, String value) {
     931        checkDatasetNotReadOnly();
    913932        boolean locked = writeLock();
    914933        try {
     
    921940    @Override
    922941    public final void remove(String key) {
     942        checkDatasetNotReadOnly();
    923943        boolean locked = writeLock();
    924944        try {
     
    931951    @Override
    932952    public final void removeAll() {
     953        checkDatasetNotReadOnly();
    933954        boolean locked = writeLock();
    934955        try {
     
    966987     */
    967988    protected void addReferrer(OsmPrimitive referrer) {
     989        checkDatasetNotReadOnly();
    968990        if (referrers == null) {
    969991            referrers = referrer;
     
    9861008     */
    9871009    protected void removeReferrer(OsmPrimitive referrer) {
     1010        checkDatasetNotReadOnly();
    9881011        if (referrers instanceof OsmPrimitive) {
    9891012            if (referrers == referrer) {
     
    11481171     */
    11491172    public void mergeFrom(OsmPrimitive other) {
     1173        checkDatasetNotReadOnly();
    11501174        boolean locked = writeLock();
    11511175        try {
     
    12391263     */
    12401264    public void load(PrimitiveData data) {
     1265        checkDatasetNotReadOnly();
    12411266        // Write lock is provided by subclasses
    12421267        setKeys(data.hasKeys() ? data.getKeys() : null);
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r13206 r13434  
    4646     */
    4747    public void setMembers(List<RelationMember> members) {
     48        checkDatasetNotReadOnly();
    4849        boolean locked = writeLock();
    4950        try {
     
    8889     */
    8990    public void addMember(RelationMember member) {
     91        checkDatasetNotReadOnly();
    9092        boolean locked = writeLock();
    9193        try {
     
    105107     */
    106108    public void addMember(int index, RelationMember member) {
     109        checkDatasetNotReadOnly();
    107110        boolean locked = writeLock();
    108111        try {
     
    127130     */
    128131    public RelationMember setMember(int index, RelationMember member) {
     132        checkDatasetNotReadOnly();
    129133        boolean locked = writeLock();
    130134        try {
     
    150154     */
    151155    public RelationMember removeMember(int index) {
     156        checkDatasetNotReadOnly();
    152157        boolean locked = writeLock();
    153158        try {
     
    376381     */
    377382    public void removeMembersFor(Collection<? extends OsmPrimitive> primitives) {
     383        checkDatasetNotReadOnly();
    378384        if (primitives == null || primitives.isEmpty())
    379385            return;
  • trunk/src/org/openstreetmap/josm/data/osm/Way.java

    r13206 r13434  
    5353     */
    5454    public void setNodes(List<Node> nodes) {
     55        checkDatasetNotReadOnly();
    5556        boolean locked = writeLock();
    5657        try {
     
    361362     */
    362363    public void removeNode(Node n) {
     364        checkDatasetNotReadOnly();
    363365        if (n == null || isIncomplete()) return;
    364366        boolean locked = writeLock();
     
    389391     */
    390392    public void removeNodes(Set<? extends Node> selection) {
     393        checkDatasetNotReadOnly();
    391394        if (selection == null || isIncomplete()) return;
    392395        boolean locked = writeLock();
     
    425428     */
    426429    public void addNode(Node n) {
     430        checkDatasetNotReadOnly();
    427431        if (n == null) return;
    428432
     
    452456     */
    453457    public void addNode(int offs, Node n) {
     458        checkDatasetNotReadOnly();
    454459        if (n == null) return;
    455460
  • trunk/src/org/openstreetmap/josm/data/osm/event/DatasetEventManager.java

    r12636 r13434  
    182182    @Override
    183183    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    184         DataSet oldData = e.getPreviousEditDataSet();
     184        DataSet oldData = e.getPreviousDataSet();
    185185        if (oldData != null) {
    186186            oldData.removeDataSetListener(myListener);
    187187        }
    188188
    189         DataSet newData = e.getSource().getEditDataSet();
     189        DataSet newData = e.getSource().getActiveDataSet();
    190190        if (newData != null) {
    191191            newData.addDataSetListener(myListener);
  • trunk/src/org/openstreetmap/josm/data/osm/event/SelectionEventManager.java

    r13223 r13434  
    184184    @Override
    185185    public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) {
    186         DataSet oldDataSet = e.getPreviousEditDataSet();
     186        DataSet oldDataSet = e.getPreviousDataSet();
    187187        if (oldDataSet != null) {
    188188            // Fake a selection removal
     
    194194            oldDataSet.removeSelectionListener(this);
    195195        }
    196         DataSet newDataSet = e.getSource().getEditDataSet();
     196        DataSet newDataSet = e.getSource().getActiveDataSet();
    197197        if (newDataSet != null) {
    198198            newDataSet.addSelectionListener(this);
  • trunk/src/org/openstreetmap/josm/data/projection/Projections.java

    r13423 r13434  
    320320                cproj.update(pd.definition);
    321321            } catch (ProjectionConfigurationException ex) {
    322                 throw new RuntimeException("Error loading " + code, ex);
     322                throw new JosmRuntimeException("Error loading " + code, ex);
    323323            }
    324324            proj = cproj;
  • trunk/src/org/openstreetmap/josm/data/validation/TestError.java

    r12390 r13434  
    1212
    1313import org.openstreetmap.josm.command.Command;
     14import org.openstreetmap.josm.data.osm.DataSet;
    1415import org.openstreetmap.josm.data.osm.Node;
    1516import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    358359     */
    359360    public boolean isFixable() {
    360         return fixingCommand != null || ((tester != null) && tester.isFixable(this));
     361        return (fixingCommand != null || ((tester != null) && tester.isFixable(this)))
     362                && primitives.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isReadOnly);
    361363    }
    362364
  • 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()) {
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r13196 r13434  
    141141        String upload = parser.getAttributeValue(null, "upload");
    142142        if (upload != null) {
    143             for (UploadPolicy policy : UploadPolicy.values()) {
    144                 if (policy.getXmlFlag().equalsIgnoreCase(upload)) {
    145                     ds.setUploadPolicy(policy);
    146                     break;
    147                 }
    148             }
     143            try {
     144                ds.setUploadPolicy(UploadPolicy.of(upload));
     145            } catch (IllegalArgumentException e) {
     146                throwException(MessageFormat.format("Illegal value for attribute ''upload''. Got ''{0}''.", upload), e);
     147            }
     148        }
     149        if ("true".equalsIgnoreCase(parser.getAttributeValue(null, "read-only"))) {
     150            ds.setReadOnly();
    149151        }
    150152        String generator = parser.getAttributeValue(null, "generator");
     
    181183                    parseUnknown();
    182184                }
    183             } else if (event == XMLStreamConstants.END_ELEMENT)
     185            } else if (event == XMLStreamConstants.END_ELEMENT) {
    184186                return;
     187            }
    185188        }
    186189    }
     
    618621            progressMonitor.worked(1);
    619622
     623            boolean readOnly = getDataSet().isReadOnly();
     624
    620625            progressMonitor.indeterminateSubTask(tr("Preparing data set..."));
     626            if (readOnly) {
     627                getDataSet().unsetReadOnly();
     628            }
    621629            prepareDataSet();
     630            if (readOnly) {
     631                getDataSet().setReadOnly();
     632            }
    622633            progressMonitor.worked(1);
    623634
     
    628639                    pp.postprocessDataSet(getDataSet(), progressMonitor);
    629640                }
     641            }
     642            // Make sure postprocessors did not change the read-only state
     643            if (readOnly && !getDataSet().isReadOnly()) {
     644                getDataSet().setReadOnly();
    630645            }
    631646            return getDataSet();
Note: See TracChangeset for help on using the changeset viewer.