Changeset 13453 in josm


Ignore:
Timestamp:
2018-02-24T18:58:28+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #8039, fix #10456: final fixes for the read-only/locked layers:

  • rename "read-only" to "locked" (in XML and Java classes/interfaces)
  • add a new download policy (true/never) to allow private layers forbidding only to download data, but allowing everything else

This leads to:

  • normal layers: download allowed, modifications allowed, upload allowed
  • private layers: download allowed or not (download=true/never), modifications allowed, upload allowed or not (upload=true/discouraged/never)
  • locked layers: nothing allowed, the data cannot be modified in any way
Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
31 edited
1 moved

Legend:

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

    r13435 r13453  
    251251    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    252252        int numWays = 0;
    253         if (selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isReadOnly)) {
     253        if (selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isLocked)) {
    254254            for (OsmPrimitive osm : selection) {
    255255                if (osm instanceof Way && !osm.isIncomplete() && ++numWays >= 2) {
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r13434 r13453  
    350350    protected final void updateEnabledStateOnCurrentSelection(boolean allowReadOnly) {
    351351        DataSet ds = getLayerManager().getActiveDataSet();
    352         if (ds != null && (allowReadOnly || !ds.isReadOnly())) {
     352        if (ds != null && (allowReadOnly || !ds.isLocked())) {
    353353            updateEnabledState(ds.getSelected());
    354354        } else {
     
    366366    protected final void updateEnabledStateOnModifiableSelection(Collection<? extends OsmPrimitive> selection) {
    367367        setEnabled(selection != null && !selection.isEmpty()
    368                 && selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isReadOnly));
     368                && selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isLocked));
    369369    }
    370370
  • trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java

    r13434 r13453  
    366366    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    367367        if (selection == null || selection.isEmpty()
    368                 || selection.stream().map(OsmPrimitive::getDataSet).anyMatch(DataSet::isReadOnly)) {
     368                || selection.stream().map(OsmPrimitive::getDataSet).anyMatch(DataSet::isLocked)) {
    369369            setEnabled(false);
    370370            return;
  • trunk/src/org/openstreetmap/josm/actions/MoveNodeAction.java

    r13434 r13453  
    6363    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    6464        if (selection == null || selection.isEmpty()
    65                 || selection.stream().map(OsmPrimitive::getDataSet).anyMatch(DataSet::isReadOnly)) {
     65                || selection.stream().map(OsmPrimitive::getDataSet).anyMatch(DataSet::isLocked)) {
    6666            setEnabled(false);
    6767            return;
  • trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java

    r13434 r13453  
    169169    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    170170        setEnabled(selection.stream().anyMatch(
    171                 o -> o instanceof Way && !o.isIncomplete() && !o.getDataSet().isReadOnly()));
     171                o -> o instanceof Way && !o.isIncomplete() && !o.getDataSet().isLocked()));
    172172    }
    173173}
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r13434 r13453  
    297297        // Selection still can be wrong, but let SplitWayAction process and tell user what's wrong
    298298        setEnabled(selection != null && !selection.isEmpty()
    299                 && selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isReadOnly)
     299                && selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isLocked)
    300300                && selection.stream().anyMatch(o -> o instanceof Node && !o.isIncomplete()));
    301301    }
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r13435 r13453  
    238238        private static Stream<OsmDataLayer> getModifiableDataLayers() {
    239239            return MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class)
    240                     .stream().filter(l -> !l.isReadOnly());
     240                    .stream().filter(OsmDataLayer::isDownloadable);
    241241        }
    242242
  • trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java

    r13434 r13453  
    250250     */
    251251    protected boolean isEditableDataLayer(Layer l) {
    252         return l instanceof OsmDataLayer && !((OsmDataLayer) l).isReadOnly();
     252        return l instanceof OsmDataLayer && !((OsmDataLayer) l).isLocked();
    253253    }
    254254}
  • trunk/src/org/openstreetmap/josm/actions/relation/AddSelectionToRelations.java

    r13434 r13453  
    7171    public void selectionChanged(final Collection<? extends OsmPrimitive> newSelection) {
    7272        GuiHelper.runInEDT(() -> setEnabled(newSelection != null && !newSelection.isEmpty() && !relations.isEmpty()
    73                 && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isReadOnly)));
     73                && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isLocked)));
    7474    }
    7575}
  • trunk/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java

    r13434 r13453  
    5151    @Override
    5252    protected void updateEnabledState() {
    53         setEnabled(!relations.isEmpty() && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isReadOnly));
     53        setEnabled(!relations.isEmpty() && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isLocked));
    5454    }
    5555}
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadMembersAction.java

    r13446 r13453  
    4848    protected void updateEnabledState() {
    4949        setEnabled(!relations.isEmpty() && !Main.isOffline(OnlineResource.OSM_API)
    50                 && !relations.iterator().next().getDataSet().isReadOnly());
     50                && !relations.iterator().next().getDataSet().isLocked());
    5151    }
    5252}
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java

    r13446 r13453  
    6868    protected void updateEnabledState() {
    6969        setEnabled(!relations.isEmpty() && !incompleteMembers.isEmpty() && !Main.isOffline(OnlineResource.OSM_API)
    70                 && !relations.iterator().next().getDataSet().isReadOnly());
     70                && !relations.iterator().next().getDataSet().isLocked());
    7171    }
    7272}
  • trunk/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java

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

    r13435 r13453  
    8989    protected void updateEnabledState() {
    9090        boolean enabled = false;
    91         if (relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isReadOnly)) {
     91        if (relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isLocked)) {
    9292            for (Relation r : relations) {
    9393                if (!r.isDeleted()) {
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r13434 r13453  
    104104 * @author imi
    105105 */
    106 public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener, ReadOnly {
     106public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener, Lockable {
     107
     108    /**
     109     * Download policy.
     110     *
     111     * Determines if download from the OSM server is intended, discouraged, or disabled / blocked.
     112     * @see UploadPolicy
     113     * @since 13453
     114     */
     115    public enum DownloadPolicy {
     116        /**
     117         * Normal dataset, download intended.
     118         */
     119        NORMAL("true"),
     120        /**
     121         * Download blocked.
     122         * Download options completely disabled. Intended for private layers, see #8039.
     123         */
     124        BLOCKED("never");
     125
     126        final String xmlFlag;
     127
     128        DownloadPolicy(String xmlFlag) {
     129            this.xmlFlag = xmlFlag;
     130        }
     131
     132        /**
     133         * Get the corresponding value of the <code>upload='...'</code> XML-attribute
     134         * in the .osm file.
     135         * @return value of the <code>download</code> attribute
     136         */
     137        public String getXmlFlag() {
     138            return xmlFlag;
     139        }
     140
     141        /**
     142         * Returns the {@code DownloadPolicy} for the given <code>upload='...'</code> XML-attribute
     143         * @param xmlFlag <code>download='...'</code> XML-attribute to convert
     144         * @return {@code DownloadPolicy} value
     145         * @throws IllegalArgumentException for invalid values
     146         */
     147        public static DownloadPolicy of(String xmlFlag) {
     148            for (DownloadPolicy policy : values()) {
     149                if (policy.getXmlFlag().equalsIgnoreCase(xmlFlag)) {
     150                    return policy;
     151                }
     152            }
     153            throw new IllegalArgumentException(xmlFlag);
     154        }
     155    }
    107156
    108157    /**
    109158     * Upload policy.
    110159     *
    111      * Determines if upload to the OSM server is intended, discouraged, or
    112      * disabled / blocked.
     160     * Determines if upload to the OSM server is intended, discouraged, or disabled / blocked.
     161     * @see DownloadPolicy
    113162     */
    114163    public enum UploadPolicy {
     
    173222
    174223    private final Storage<OsmPrimitive> allPrimitives = new Storage<>(new Storage.PrimitiveIdHash(), true);
    175     private final Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives.foreignKey(new Storage.PrimitiveIdHash());
     224    private final Map<PrimitiveId, OsmPrimitive> primitivesMap = allPrimitives
     225            .foreignKey(new Storage.PrimitiveIdHash());
    176226    private final CopyOnWriteArrayList<DataSetListener> listeners = new CopyOnWriteArrayList<>();
    177227
     
    187237
    188238    private String name;
     239    private DownloadPolicy downloadPolicy;
    189240    private UploadPolicy uploadPolicy;
    190241    /** Flag used to know if the dataset should not be editable */
     
    250301                primMap.put(w, newWay);
    251302                List<Node> newNodes = new ArrayList<>();
    252                 for (Node n: w.getNodes()) {
     303                for (Node n : w.getNodes()) {
    253304                    newNodes.add((Node) primMap.get(n));
    254305                }
     
    268319                Relation newRelation = (Relation) primMap.get(r);
    269320                List<RelationMember> newMembers = new ArrayList<>();
    270                 for (RelationMember rm: r.getMembers()) {
     321                for (RelationMember rm : r.getMembers()) {
    271322                    newMembers.add(new RelationMember(rm.getRole(), primMap.get(rm.getMember())));
    272323                }
     
    378429        checkModifiable();
    379430        this.version = version;
     431    }
     432
     433    /**
     434     * Get the download policy.
     435     * @return the download policy
     436     * @see #setDownloadPolicy(DownloadPolicy)
     437     * @since 13453
     438     */
     439    public DownloadPolicy getDownloadPolicy() {
     440        return this.downloadPolicy;
     441    }
     442
     443    /**
     444     * Sets the download policy.
     445     * @param downloadPolicy the download policy
     446     * @see #getUploadPolicy()
     447     * @since 13453
     448     */
     449    public void setDownloadPolicy(DownloadPolicy downloadPolicy) {
     450        this.downloadPolicy = downloadPolicy;
    380451    }
    381452
     
    529600     */
    530601    public Collection<OsmPrimitive> allNonDeletedPhysicalPrimitives() {
    531         return getPrimitives(primitive -> !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation));
     602        return getPrimitives(
     603                primitive -> !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation));
    532604    }
    533605
     
    565637            if (getPrimitiveById(primitive) != null)
    566638                throw new DataIntegrityProblemException(
    567                         tr("Unable to add primitive {0} to the dataset because it is already included", primitive.toString()));
     639                        tr("Unable to add primitive {0} to the dataset because it is already included",
     640                                primitive.toString()));
    568641
    569642            allPrimitives.add(primitive);
     
    690763     */
    691764    public Collection<OsmPrimitive> getSelectedNodesAndWays() {
    692         return new SubclassFilteredCollection<>(getSelected(), primitive -> primitive instanceof Node || primitive instanceof Way);
     765        return new SubclassFilteredCollection<>(getSelected(),
     766                primitive -> primitive instanceof Node || primitive instanceof Way);
    693767    }
    694768
     
    10061080        OsmPrimitive result = getPrimitiveById(primitiveId);
    10071081        if (result == null && primitiveId != null) {
    1008             Logging.warn(tr("JOSM expected to find primitive [{0} {1}] in dataset but it is not there. Please report this "
    1009                     + "at {2}. This is not a critical error, it should be safe to continue in your work.",
     1082            Logging.warn(tr(
     1083                    "JOSM expected to find primitive [{0} {1}] in dataset but it is not there. Please report this "
     1084                            + "at {2}. This is not a critical error, it should be safe to continue in your work.",
    10101085                    primitiveId.getType(), Long.toString(primitiveId.getUniqueId()), Main.getJOSMWebsite()));
    10111086            Logging.error(new Exception());
     
    11151190     */
    11161191    public boolean isModified() {
    1117         for (OsmPrimitive p: allPrimitives) {
     1192        for (OsmPrimitive p : allPrimitives) {
    11181193            if (p.isModified())
    11191194                return true;
     
    11281203     */
    11291204    public boolean requiresUploadToServer() {
    1130         for (OsmPrimitive p: allPrimitives) {
     1205        for (OsmPrimitive p : allPrimitives) {
    11311206            if (APIOperation.of(p) != null)
    11321207                return true;
     
    11991274                try {
    12001275                    if (eventsToFire.size() < MAX_SINGLE_EVENTS) {
    1201                         for (AbstractDatasetChangedEvent event: eventsToFire) {
     1276                        for (AbstractDatasetChangedEvent event : eventsToFire) {
    12021277                            fireEventToListeners(event);
    12031278                        }
     
    12191294
    12201295    private void fireEventToListeners(AbstractDatasetChangedEvent event) {
    1221         for (DataSetListener listener: listeners) {
     1296        for (DataSetListener listener : listeners) {
    12221297            event.fire(listener);
    12231298        }
     
    12601335
    12611336    void fireChangesetIdChanged(OsmPrimitive primitive, int oldChangesetId, int newChangesetId) {
    1262         fireEvent(new ChangesetIdChangedEvent(this, Collections.singletonList(primitive), oldChangesetId, newChangesetId));
     1337        fireEvent(new ChangesetIdChangedEvent(this, Collections.singletonList(primitive), oldChangesetId,
     1338                newChangesetId));
    12631339    }
    12641340
     
    12831359     */
    12841360    public void invalidateEastNorthCache() {
    1285         if (Main.getProjection() == null) return; // sanity check
     1361        if (Main.getProjection() == null)
     1362            return; // sanity check
    12861363        beginUpdate();
    12871364        try {
    1288             for (Node n: getNodes()) {
     1365            for (Node n : getNodes()) {
    12891366                n.invalidateEastNorthCache();
    12901367            }
     
    13261403        try {
    13271404            clearSelection();
    1328             for (OsmPrimitive primitive:allPrimitives) {
     1405            for (OsmPrimitive primitive : allPrimitives) {
    13291406                primitive.setDataset(null);
    13301407            }
     
    13431420    public void deleteInvisible() {
    13441421        checkModifiable();
    1345         for (OsmPrimitive primitive:allPrimitives) {
     1422        for (OsmPrimitive primitive : allPrimitives) {
    13461423            if (!primitive.isVisible()) {
    13471424                primitive.setDeleted(true);
     
    14541531
    14551532    @Override
    1456     public void setReadOnly() {
     1533    public void lock() {
    14571534        if (!isReadOnly.compareAndSet(false, true)) {
    14581535            Logging.warn("Trying to set readOnly flag on a readOnly dataset ", getName());
     
    14611538
    14621539    @Override
    1463     public void unsetReadOnly() {
     1540    public void unlock() {
    14641541        if (!isReadOnly.compareAndSet(true, false)) {
    14651542            Logging.warn("Trying to unset readOnly flag on a non-readOnly dataset ", getName());
     
    14681545
    14691546    @Override
    1470     public boolean isReadOnly() {
     1547    public boolean isLocked() {
    14711548        return isReadOnly.get();
    14721549    }
     
    14771554     */
    14781555    private void checkModifiable() {
    1479         if (isReadOnly()) {
     1556        if (isLocked()) {
    14801557            throw new IllegalStateException("DataSet is read-only");
    14811558        }
  • trunk/src/org/openstreetmap/josm/data/osm/Lockable.java

    r13452 r13453  
    33
    44/**
    5  * To be implemented by modifiable objects to offer a "read-only" mode.
    6  * @since 13434
     5 * To be implemented by modifiable objects to offer a "read-only/locked" mode.
     6 * @since 13453
    77 */
    8 public interface ReadOnly {
     8public interface Lockable {
    99
    1010    /**
    11      * Enables the read-only mode.
     11     * Enables the read-only/locked mode.
    1212     */
    13     void setReadOnly();
     13    void lock();
    1414
    1515    /**
    16      * Disables the read-only mode.
     16     * Disables the read-only/locked mode.
    1717     */
    18     void unsetReadOnly();
     18    void unlock();
    1919
    2020    /**
    21      * Determines if this is read-only (thus it cannot be modified).
    22      * @return {@code true} if this is read-only
     21     * Determines if this is read-only/locked (thus it cannot be modified).
     22     * @return {@code true} if this is read-only/locked
    2323     */
    24     boolean isReadOnly();
     24    boolean isLocked();
    2525}
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r13434 r13453  
    279279     */
    280280    protected final void checkDatasetNotReadOnly() {
    281         if (dataSet != null && dataSet.isReadOnly())
     281        if (dataSet != null && dataSet.isLocked())
    282282            throw new DataIntegrityProblemException("Primitive cannot be modified in read-only dataset: " + toString());
    283283    }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/AbstractMapRenderer.java

    r13444 r13453  
    128128     */
    129129    public void drawVirtualNodes(DataSet data, BBox bbox) {
    130         if (virtualNodeSize == 0 || data == null || bbox == null || data.isReadOnly())
     130        if (virtualNodeSize == 0 || data == null || bbox == null || data.isLocked())
    131131            return;
    132132        // print normal virtual nodes
  • trunk/src/org/openstreetmap/josm/data/validation/TestError.java

    r13434 r13453  
    360360    public boolean isFixable() {
    361361        return (fixingCommand != null || ((tester != null) && tester.isFixable(this)))
    362                 && primitives.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isReadOnly);
     362                && primitives.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isLocked);
    363363    }
    364364
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r13434 r13453  
    353353            DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
    354354            if (ds != null && isDoubleClick(e)) {
    355                 if (e.isControlDown() && !ds.isReadOnly()) {
     355                if (e.isControlDown() && !ds.isLocked()) {
    356356                    editCurrentRelation();
    357357                } else {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PresetListPanel.java

    r13446 r13453  
    4141            int answer = t.showDialog(selection, false);
    4242
    43             if (answer == TaggingPreset.DIALOG_ANSWER_APPLY && !selection.iterator().next().getDataSet().isReadOnly()) {
     43            if (answer == TaggingPreset.DIALOG_ANSWER_APPLY && !selection.iterator().next().getDataSet().isLocked()) {
    4444                presetHandler.updateTags(t.getChangedTags());
    4545            }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r13446 r13453  
    490490        MainApplication.getMap().relationListDialog.selectRelation(relation);
    491491        OsmDataLayer layer = MainApplication.getLayerManager().getActiveDataLayer();
    492         if (!layer.isReadOnly()) {
     492        if (!layer.isLocked()) {
    493493            RelationEditor.getEditor(
    494494                    layer, relation, ((MemberInfo) membershipData.getValueAt(row, 1)).role).setVisible(true);
     
    647647
    648648        DataSet ds = Main.main.getActiveDataSet();
    649         boolean isReadOnly = ds != null && ds.isReadOnly();
     649        boolean isReadOnly = ds != null && ds.isLocked();
    650650        boolean hasSelection = !newSel.isEmpty();
    651651        boolean hasTags = hasSelection && tagData.getRowCount() > 0;
     
    10601060        protected final void updateEnabledState() {
    10611061            DataSet ds = Main.main.getActiveDataSet();
    1062             setEnabled(ds != null && !ds.isReadOnly() &&
     1062            setEnabled(ds != null && !ds.isLocked() &&
    10631063                    ((tagTable != null && tagTable.getSelectedRowCount() >= 1)
    10641064                    || (membershipTable != null && membershipTable.getSelectedRowCount() > 0)
     
    11161116        protected void updateEnabledState() {
    11171117            DataSet ds = Main.main.getActiveDataSet();
    1118             setEnabled(ds != null && !ds.isReadOnly() &&
     1118            setEnabled(ds != null && !ds.isLocked() &&
    11191119                    ((tagTable != null && tagTable.getSelectedRowCount() == 1)
    11201120                    ^ (membershipTable != null && membershipTable.getSelectedRowCount() == 1)
     
    12711271            Collection<OsmPrimitive> sel = Main.main.getInProgressSelection();
    12721272            String clipboard = ClipboardUtils.getClipboardStringContent();
    1273             if (sel.isEmpty() || clipboard == null || sel.iterator().next().getDataSet().isReadOnly())
     1273            if (sel.isEmpty() || clipboard == null || sel.iterator().next().getDataSet().isLocked())
    12741274                return;
    12751275            MainApplication.undoRedo.add(new ChangePropertyCommand(sel, key, Utils.strip(clipboard)));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java

    r13434 r13453  
    564564        public void setupDialog() {
    565565            super.setupDialog();
    566             buttons.get(0).setEnabled(!Main.main.getActiveDataSet().isReadOnly());
     566            buttons.get(0).setEnabled(!Main.main.getActiveDataSet().isLocked());
    567567            final Dimension size = getSize();
    568568            // Set resizable only in width
  • trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java

    r13440 r13453  
    220220        // partially uploaded. Better run on EDT.
    221221        Runnable r = () -> {
    222             boolean readOnly = layer.isReadOnly();
     222            boolean readOnly = layer.isLocked();
    223223            if (readOnly) {
    224                 layer.unsetReadOnly();
     224                layer.unlock();
    225225            }
    226226            try {
     
    230230            } finally {
    231231                if (readOnly) {
    232                     layer.setReadOnly();
     232                    layer.lock();
    233233                }
    234234            }
  • trunk/src/org/openstreetmap/josm/gui/layer/AbstractModifiableLayer.java

    r13434 r13453  
    22package org.openstreetmap.josm.gui.layer;
    33
    4 import org.openstreetmap.josm.data.osm.ReadOnly;
     4import org.openstreetmap.josm.data.osm.Lockable;
    55import org.openstreetmap.josm.gui.io.AbstractIOTask;
    66import org.openstreetmap.josm.gui.io.AbstractUploadDialog;
     
    1111 * @since 7358
    1212 */
    13 public abstract class AbstractModifiableLayer extends Layer implements UploadToServer, SaveToFile, ReadOnly {
     13public abstract class AbstractModifiableLayer extends Layer implements DownloadFromServer, UploadToServer, SaveToFile, Lockable {
    1414
    1515    /**
     
    1919    public AbstractModifiableLayer(String name) {
    2020        super(name);
     21    }
     22
     23    @Override
     24    public boolean isDownloadable() {
     25        // Override if needed
     26        return false;
    2127    }
    2228
     
    8389
    8490    @Override
    85     public void setReadOnly() {
     91    public void lock() {
    8692        // Override if needed
    8793    }
    8894
    8995    @Override
    90     public void unsetReadOnly() {
     96    public void unlock() {
    9197        // Override if needed
    9298    }
    9399
    94100    @Override
    95     public boolean isReadOnly() {
     101    public boolean isLocked() {
    96102        // Override if needed
    97103        return false;
  • trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java

    r13437 r13453  
    376376     */
    377377    public synchronized OsmDataLayer getEditLayer() {
    378         if (dataLayer != null && !dataLayer.isReadOnly())
     378        if (dataLayer != null && !dataLayer.isLocked())
    379379            return dataLayer;
    380380        else
     
    402402     */
    403403    public synchronized DataSet getEditDataSet() {
    404         if (dataLayer != null && !dataLayer.isReadOnly()) {
     404        if (dataLayer != null && !dataLayer.isLocked()) {
    405405            return dataLayer.data;
    406406        } else {
     
    509509        GuiHelper.assertCallFromEdt();
    510510        layer.setUploadInProgress();
    511         layer.setReadOnly();
     511        layer.lock();
    512512
    513513        // Reset only the edit layer as empty
     
    528528    public synchronized void processLayerAfterUpload(OsmDataLayer layer) {
    529529        GuiHelper.assertCallFromEdt();
    530         layer.unsetReadOnly();
     530        layer.unlock();
    531531        layer.unsetUploadInProgress();
    532532
  • trunk/src/org/openstreetmap/josm/gui/layer/NoteLayer.java

    r13437 r13453  
    134134
    135135    @Override
     136    public boolean isDownloadable() {
     137        return true;
     138    }
     139
     140    @Override
    136141    public boolean isUploadable() {
    137142        return true;
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r13435 r13453  
    6464import org.openstreetmap.josm.data.osm.DataSelectionListener;
    6565import org.openstreetmap.josm.data.osm.DataSet;
     66import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    6667import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    6768import org.openstreetmap.josm.data.osm.DataSetMerger;
     
    421422    public Icon getIcon() {
    422423        ImageProvider base = getBaseIconProvider().setMaxSize(ImageSizes.LAYER);
    423         if (isUploadDiscouraged() || data.getUploadPolicy() == UploadPolicy.BLOCKED) {
     424        if (data.getDownloadPolicy() != null && data.getDownloadPolicy() != DownloadPolicy.NORMAL) {
     425            base.addOverlay(new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.0, 1.0, 0.5));
     426        }
     427        if (data.getUploadPolicy() != null && data.getUploadPolicy() != UploadPolicy.NORMAL) {
    424428            base.addOverlay(new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.5, 1.0, 1.0));
    425429        }
     
    428432            // If the layer is being uploaded then change the default icon to a clock
    429433            base = new ImageProvider("clock").setMaxSize(ImageSizes.LAYER);
    430         } else if (isReadOnly()) {
     434        } else if (isLocked()) {
    431435            // If the layer is read only then change the default icon to a lock
    432436            base = new ImageProvider("lock").setMaxSize(ImageSizes.LAYER);
     
    940944
    941945    @Override
     946    public boolean isDownloadable() {
     947        return data.getDownloadPolicy() != DownloadPolicy.BLOCKED && !isLocked();
     948    }
     949
     950    @Override
    942951    public boolean isUploadable() {
    943         return data.getUploadPolicy() != UploadPolicy.BLOCKED;
     952        return data.getUploadPolicy() != UploadPolicy.BLOCKED && !isLocked();
    944953    }
    945954
     
    10311040    }
    10321041
    1033     /**
    1034      * Determines if upload is being discouraged.
    1035      * (i.e. this dataset contains private data which should not be uploaded)
    1036      * @return {@code true} if upload is being discouraged, {@code false} otherwise
    1037      */
    10381042    @Override
    10391043    public final boolean isUploadDiscouraged() {
     
    11741178
    11751179    @Override
    1176     public void setReadOnly() {
    1177         data.setReadOnly();
    1178     }
    1179 
    1180     @Override
    1181     public void unsetReadOnly() {
    1182         data.unsetReadOnly();
    1183     }
    1184 
    1185     @Override
    1186     public boolean isReadOnly() {
    1187         return data.isReadOnly();
     1180    public void lock() {
     1181        data.lock();
     1182    }
     1183
     1184    @Override
     1185    public void unlock() {
     1186        data.unlock();
     1187    }
     1188
     1189    @Override
     1190    public boolean isLocked() {
     1191        return data.isLocked();
    11881192    }
    11891193
  • trunk/src/org/openstreetmap/josm/gui/layer/UploadToServer.java

    r13434 r13453  
    88/**
    99 * Interface for layers that can upload data.
     10 * @see DownloadFromServer
    1011 * @since 9751
    1112 */
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPreset.java

    r13446 r13453  
    493493
    494494            answer = new PresetDialog(p, title, preset_name_label ? null : (ImageIcon) getValue(Action.SMALL_ICON),
    495                     sel.isEmpty() || sel.iterator().next().getDataSet().isReadOnly(), showNewRelation).getValue();
     495                    sel.isEmpty() || sel.iterator().next().getDataSet().isLocked(), showNewRelation).getValue();
    496496        }
    497497        if (!showNewRelation && answer == 2)
  • trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java

    r13440 r13453  
    123123        boolean readOnly = false;
    124124        if (ds != null) {
    125             readOnly = ds.isReadOnly();
     125            readOnly = ds.isLocked();
    126126            if (readOnly) {
    127                 ds.unsetReadOnly();
     127                ds.unlock();
    128128            }
    129129            ds.beginUpdate();
     
    158158                ds.endUpdate();
    159159                if (readOnly) {
    160                     ds.setReadOnly();
     160                    ds.lock();
    161161                }
    162162            }
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r13434 r13453  
    1212import java.util.List;
    1313import java.util.Objects;
     14import java.util.function.Consumer;
    1415import java.util.regex.Matcher;
    1516import java.util.regex.Pattern;
     
    2728import org.openstreetmap.josm.data.osm.Changeset;
    2829import org.openstreetmap.josm.data.osm.DataSet;
     30import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    2931import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    3032import org.openstreetmap.josm.data.osm.Node;
     
    139141        }
    140142        ds.setVersion(v);
    141         String upload = parser.getAttributeValue(null, "upload");
    142         if (upload != null) {
    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();
     143        parsePolicy("download", policy -> ds.setDownloadPolicy(DownloadPolicy.of(policy)));
     144        parsePolicy("upload", policy -> ds.setUploadPolicy(UploadPolicy.of(policy)));
     145        if ("true".equalsIgnoreCase(parser.getAttributeValue(null, "locked"))) {
     146            ds.lock();
    151147        }
    152148        String generator = parser.getAttributeValue(null, "generator");
     
    185181            } else if (event == XMLStreamConstants.END_ELEMENT) {
    186182                return;
     183            }
     184        }
     185    }
     186
     187    private void parsePolicy(String key, Consumer<String> consumer) throws XMLStreamException {
     188        String policy = parser.getAttributeValue(null, key);
     189        if (policy != null) {
     190            try {
     191                consumer.accept(policy);
     192            } catch (IllegalArgumentException e) {
     193                throwException(MessageFormat.format("Illegal value for attribute ''{0}''. Got ''{1}''.", key, policy), e);
    187194            }
    188195        }
     
    621628            progressMonitor.worked(1);
    622629
    623             boolean readOnly = getDataSet().isReadOnly();
     630            boolean readOnly = getDataSet().isLocked();
    624631
    625632            progressMonitor.indeterminateSubTask(tr("Preparing data set..."));
    626633            if (readOnly) {
    627                 getDataSet().unsetReadOnly();
     634                getDataSet().unlock();
    628635            }
    629636            prepareDataSet();
    630637            if (readOnly) {
    631                 getDataSet().setReadOnly();
     638                getDataSet().lock();
    632639            }
    633640            progressMonitor.worked(1);
     
    641648            }
    642649            // Make sure postprocessors did not change the read-only state
    643             if (readOnly && !getDataSet().isReadOnly()) {
    644                 getDataSet().setReadOnly();
     650            if (readOnly && !getDataSet().isLocked()) {
     651                getDataSet().lock();
    645652            }
    646653            return getDataSet();
Note: See TracChangeset for help on using the changeset viewer.