Changeset 13486 in josm for trunk/src/org


Ignore:
Timestamp:
2018-03-03T17:59:48+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #8039, see #10456 - fix bugs with non-downloadable layers

Location:
trunk/src/org/openstreetmap/josm
Files:
19 edited

Legend:

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

    r13067 r13486  
    4141import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    4242import org.openstreetmap.josm.gui.dialogs.relation.sort.RelationSorter;
     43import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4344import org.openstreetmap.josm.gui.util.GuiHelper;
    4445import org.openstreetmap.josm.spi.preferences.Config;
     
    160161
    161162        // download incomplete relation or incomplete members if necessary
    162         if (multipolygonRelation != null) {
     163        OsmDataLayer editLayer = getLayerManager().getEditLayer();
     164        if (multipolygonRelation != null && editLayer != null && editLayer.isDownloadable()) {
    163165            if (!multipolygonRelation.isNew() && multipolygonRelation.isIncomplete()) {
    164166                MainApplication.worker.submit(
    165                         new DownloadRelationTask(Collections.singleton(multipolygonRelation), getLayerManager().getEditLayer()));
     167                        new DownloadRelationTask(Collections.singleton(multipolygonRelation), editLayer));
    166168            } else if (multipolygonRelation.hasIncompleteMembers()) {
    167169                MainApplication.worker.submit(new DownloadRelationMemberTask(multipolygonRelation,
    168170                        DownloadSelectedIncompleteMembersAction.buildSetOfIncompleteMembers(Collections.singleton(multipolygonRelation)),
    169                         getLayerManager().getEditLayer()));
     171                        editLayer));
    170172            }
    171173        }
  • trunk/src/org/openstreetmap/josm/actions/DownloadReferrersAction.java

    r13434 r13486  
    1010
    1111import org.openstreetmap.josm.actions.downloadtasks.DownloadReferrersTask;
     12import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    1213import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1314import org.openstreetmap.josm.gui.MainApplication;
     
    6768    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    6869        updateEnabledStateOnModifiableSelection(selection);
     70        if (isEnabled() && selection != null && !selection.isEmpty()
     71                && DownloadPolicy.BLOCKED.equals(selection.iterator().next().getDataSet().getDownloadPolicy())) {
     72            setEnabled(false);
     73        }
    6974    }
    7075}
  • trunk/src/org/openstreetmap/josm/actions/JosmAction.java

    r13453 r13486  
    359359    /**
    360360     * 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.
     361     * Enables action if the collection is not empty and references primitives in a modifiable data layer.
    362362     * Can be called in {@link #updateEnabledState(Collection)} implementations.
    363363     * @param selection the collection of selected primitives
  • trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java

    r12675 r13486  
    4747    @Override
    4848    protected void updateEnabledState() {
    49         setEnabled(getLayerManager().getEditLayer() != null && !Main.isOffline(OnlineResource.OSM_API));
     49        OsmDataLayer editLayer = getLayerManager().getEditLayer();
     50        setEnabled(editLayer != null && editLayer.isDownloadable() && !Main.isOffline(OnlineResource.OSM_API));
    5051    }
    5152
     
    5354    public void actionPerformed(ActionEvent e) {
    5455        OsmDataLayer editLayer = getLayerManager().getEditLayer();
    55         if (!isEnabled() || editLayer == null)
     56        if (!isEnabled() || editLayer == null || !editLayer.isDownloadable())
    5657            return;
    5758
  • trunk/src/org/openstreetmap/josm/actions/UpdateSelectionAction.java

    r12636 r13486  
    1616import org.openstreetmap.josm.Main;
    1717import org.openstreetmap.josm.data.osm.DataSet;
     18import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    1819import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1920import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    119120    @Override
    120121    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    121         setEnabled(selection != null && !selection.isEmpty() && !Main.isOffline(OnlineResource.OSM_API));
     122        if (selection == null || selection.isEmpty()) {
     123            setEnabled(false);
     124        } else {
     125            DataSet ds = selection.iterator().next().getDataSet();
     126            setEnabled(!ds.isLocked() && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy())
     127                    && !Main.isOffline(OnlineResource.OSM_API));
     128        }
    122129    }
    123130
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r13464 r13486  
    1111import java.util.Collections;
    1212import java.util.HashSet;
    13 import java.util.Optional;
    1413import java.util.Set;
    1514import java.util.concurrent.Future;
     
    294293            OsmDataLayer layer = addNewLayerIfRequired(newLayerName);
    295294            if (layer == null) {
    296                 layer = Optional.ofNullable(getEditLayer()).orElseGet(this::getFirstModifiableDataLayer);
     295                layer = getEditLayer();
     296                if (layer == null || !layer.isDownloadable()) {
     297                    layer = getFirstModifiableDataLayer();
     298                }
    297299                Collection<OsmPrimitive> primitivesToUpdate = searchPrimitivesToUpdate(bounds, layer.data);
    298300                layer.mergeFrom(dataSet);
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java

    r12630 r13486  
    6262        super("Download referrers", false /* don't ignore exception*/);
    6363        CheckParameterUtil.ensureParameterNotNull(targetLayer, "targetLayer");
     64        if (!targetLayer.isDownloadable()) {
     65            throw new IllegalArgumentException("Non-downloadable layer: " + targetLayer);
     66        }
    6467        canceled = false;
    6568        this.children = new HashMap<>();
  • trunk/src/org/openstreetmap/josm/actions/relation/AbstractRelationAction.java

    r11922 r13486  
    77import javax.swing.AbstractAction;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.actions.OsmPrimitiveAction;
     11import org.openstreetmap.josm.data.osm.DataSet;
     12import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    1013import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1114import org.openstreetmap.josm.data.osm.Relation;
     15import org.openstreetmap.josm.io.OnlineResource;
    1216import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    1317
     
    4650        setEnabled(!relations.isEmpty());
    4751    }
     52
     53    protected final boolean canDownload() {
     54        if (relations.isEmpty()) {
     55            return false;
     56        }
     57        DataSet ds = relations.iterator().next().getDataSet();
     58        return !Main.isOffline(OnlineResource.OSM_API)
     59            && ds != null && !ds.isLocked() && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy());
     60    }
    4861}
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadMembersAction.java

    r13453 r13486  
    88import java.util.Collection;
    99
    10 import org.openstreetmap.josm.Main;
    1110import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1211import org.openstreetmap.josm.gui.MainApplication;
    1312import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
    14 import org.openstreetmap.josm.io.OnlineResource;
    1513import org.openstreetmap.josm.tools.ImageProvider;
    1614import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     
    4745    @Override
    4846    protected void updateEnabledState() {
    49         setEnabled(!relations.isEmpty() && !Main.isOffline(OnlineResource.OSM_API)
    50                 && !relations.iterator().next().getDataSet().isLocked());
     47        setEnabled(canDownload());
    5148    }
    5249}
  • trunk/src/org/openstreetmap/josm/actions/relation/DownloadSelectedIncompleteMembersAction.java

    r13453 r13486  
    99import java.util.Set;
    1010
    11 import org.openstreetmap.josm.Main;
    1211import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1312import org.openstreetmap.josm.data.osm.Relation;
    1413import org.openstreetmap.josm.gui.MainApplication;
    1514import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
    16 import org.openstreetmap.josm.io.OnlineResource;
    1715import org.openstreetmap.josm.tools.ImageProvider;
    1816import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     
    6765    @Override
    6866    protected void updateEnabledState() {
    69         setEnabled(!relations.isEmpty() && !incompleteMembers.isEmpty() && !Main.isOffline(OnlineResource.OSM_API)
    70                 && !relations.iterator().next().getDataSet().isLocked());
     67        setEnabled(!incompleteMembers.isEmpty() && canDownload());
    7168    }
    7269}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/DownloadRelationMemberTask.java

    r12675 r13486  
    99import java.util.Collection;
    1010import java.util.HashSet;
     11import java.util.Objects;
    1112import java.util.Set;
    1213
     
    3031/**
    3132 * The asynchronous task for downloading relation members.
    32  *
     33 * @since 2563
    3334 */
    3435public class DownloadRelationMemberTask extends PleaseWaitRunnable {
     
    4445        if (parent != null)
    4546            this.parents.add(parent);
    46         this.children = children;
    47         this.curLayer = curLayer;
     47        this.children = Objects.requireNonNull(children);
     48        this.curLayer = Objects.requireNonNull(curLayer);
     49        checkLayer();
    4850    }
    4951
     
    5254        if (parent != null)
    5355            this.parents.add(parent);
    54         this.children = children;
    55         this.curLayer = curLayer;
     56        this.children = Objects.requireNonNull(children);
     57        this.curLayer = Objects.requireNonNull(curLayer);
     58        checkLayer();
    5659    }
    5760
     
    6770        super(tr("Download relation members"), false /* don't ignore exception */);
    6871        this.parents.addAll(parents);
    69         this.children = children;
    70         this.curLayer = curLayer;
     72        this.children = Objects.requireNonNull(children);
     73        this.curLayer = Objects.requireNonNull(curLayer);
     74        checkLayer();
     75    }
     76
     77    private void checkLayer() {
     78        if (!curLayer.isDownloadable()) {
     79            throw new IllegalArgumentException("Non-downloadable layer: " + curLayer);
     80        }
    7181    }
    7282
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/DownloadRelationTask.java

    r12663 r13486  
    2727 * The asynchronous task for fully downloading a collection of relations. Does a full download
    2828 * for each relations and merges the relation into an {@link OsmDataLayer}
    29  *
     29 * @since 2563
    3030 */
    3131public class DownloadRelationTask extends PleaseWaitRunnable {
     
    5050        this.relations = relations;
    5151        this.layer = layer;
     52        if (!layer.isDownloadable()) {
     53            throw new IllegalArgumentException("Non-downloadable layer: " + layer);
     54        }
    5255    }
    5356
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java

    r12713 r13486  
    7878        CheckParameterUtil.ensure(child, "child", "id > 0", ch -> ch.getUniqueId() > 0);
    7979        CheckParameterUtil.ensureParameterNotNull(layer, "layer");
     80        if (!layer.isDownloadable()) {
     81            throw new IllegalArgumentException("Non-downloadable layer: " + layer);
     82        }
    8083        referrers = null;
    8184        this.layer = layer;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowserModel.java

    r12657 r13486  
    88
    99import org.openstreetmap.josm.data.osm.DataSet;
     10import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    1011import org.openstreetmap.josm.data.osm.Relation;
    1112import org.openstreetmap.josm.data.osm.RelationMember;
     
    3536    }
    3637
     38    /**
     39     * Sets the relation.
     40     * @param relation the relation
     41     */
    3742    public void setRelation(Relation relation) {
    3843        this.relation = relation;
     
    6267    }
    6368
     69    /**
     70     * Populates the model with parent referrers.
     71     * @param parents parent referrers
     72     */
    6473    public void populate(List<Relation> parents) {
    6574        referrers.clear();
     
    93102    }
    94103
     104    /**
     105     * Determines if reloading the relation is possible/authorized.
     106     * @return {@code true} if reloading the relation is possible/authorized
     107     */
    95108    public boolean canReload() {
    96         return relation != null && !relation.isNew();
     109        return relation != null && !relation.isNew()
     110                && !relation.getDataSet().isLocked()
     111                && !DownloadPolicy.BLOCKED.equals(relation.getDataSet().getDownloadPolicy());
    97112    }
    98113
     114    /**
     115     * Returns the relation.
     116     * @return the relation
     117     */
    99118    public Relation getRelation() {
    100119        return relation;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AbstractRelationEditorAction.java

    r12933 r13486  
    88import javax.swing.event.TableModelListener;
    99
     10import org.openstreetmap.josm.Main;
     11import org.openstreetmap.josm.data.osm.DataSet;
     12import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    1013import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    1114import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    1215import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1316import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     17import org.openstreetmap.josm.io.OnlineResource;
    1418
    1519/**
     
    4953
    5054    protected abstract void updateEnabledState();
     55
     56    protected final boolean canDownload() {
     57        DataSet ds = editor.getRelation().getDataSet();
     58        return !Main.isOffline(OnlineResource.OSM_API)
     59            && ds != null && !ds.isLocked() && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy());
     60    }
    5161}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadIncompleteMembersAction.java

    r13130 r13486  
    1515import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1616import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    17 import org.openstreetmap.josm.io.OnlineResource;
    1817import org.openstreetmap.josm.tools.ImageProvider;
    1918import org.openstreetmap.josm.tools.Shortcut;
     
    5958    @Override
    6059    protected void updateEnabledState() {
    61         setEnabled(memberTableModel.hasIncompleteMembers() && !Main.isOffline(OnlineResource.OSM_API));
     60        setEnabled(memberTableModel.hasIncompleteMembers() && canDownload());
    6261    }
    6362}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadSelectedIncompleteMembersAction.java

    r13130 r13486  
    77import java.awt.event.ActionEvent;
    88
    9 import org.openstreetmap.josm.Main;
    109import org.openstreetmap.josm.gui.MainApplication;
    1110import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
     
    1413import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    1514import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    16 import org.openstreetmap.josm.io.OnlineResource;
    1715import org.openstreetmap.josm.tools.ImageProvider;
    1816
     
    5452    @Override
    5553    protected void updateEnabledState() {
    56         setEnabled(memberTableModel.hasIncompleteSelectedMembers() && !Main.isOffline(OnlineResource.OSM_API));
     54        setEnabled(memberTableModel.hasIncompleteSelectedMembers() && canDownload());
    5755    }
    5856}
  • trunk/src/org/openstreetmap/josm/gui/io/AbstractPrimitiveTask.java

    r12675 r13486  
    5353        ensureParameterNotNull(layer, "layer");
    5454        this.layer = layer;
     55        if (!layer.isDownloadable()) {
     56            throw new IllegalArgumentException("Non-downloadable layer: " + layer);
     57        }
    5558    }
    5659
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadPrimitivesWithReferrersTask.java

    r12636 r13486  
    131131        // Append downloaded data to JOSM
    132132        OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();
    133         if (layer == null || this.newLayer)
     133        if (layer == null || this.newLayer || !layer.isDownloadable())
    134134            MainApplication.getLayerManager().addLayer(tmpLayer);
    135135        else
Note: See TracChangeset for help on using the changeset viewer.