Changeset 13497 in josm


Ignore:
Timestamp:
2018-03-04T15:18:05+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #16051, see #8039, see #10456 - more fixes for download/upload policies and locked status (merge of layers)

Location:
trunk
Files:
6 edited

Legend:

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

    r10382 r13497  
    1111import org.openstreetmap.josm.Main;
    1212import org.openstreetmap.josm.data.osm.DataSet;
     13import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    1314import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1415import org.openstreetmap.josm.io.OnlineResource;
     
    4647    @Override
    4748    protected void updateEnabledState() {
    48         setEnabled(getLayerManager().getEditDataSet() != null && !Main.isOffline(OnlineResource.OSM_API));
     49        DataSet ds = getLayerManager().getEditDataSet();
     50        setEnabled(ds != null && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy())
     51                && !Main.isOffline(OnlineResource.OSM_API));
    4952    }
    5053
  • trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java

    r13434 r13497  
    6464    protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) {
    6565        updateEnabledStateOnModifiableSelection(selection);
     66        OsmDataLayer editLayer = getLayerManager().getEditLayer();
     67        if (editLayer != null && !editLayer.isUploadable()) {
     68            setEnabled(false);
     69        }
    6670    }
    6771
     
    8993    public void actionPerformed(ActionEvent e) {
    9094        OsmDataLayer editLayer = getLayerManager().getEditLayer();
    91         if (!isEnabled())
     95        if (!isEnabled() || !editLayer.isUploadable())
    9296            return;
    9397        if (editLayer.isUploadDiscouraged() && UploadAction.warnUploadDiscouraged(editLayer)) {
     
    203207                hull.add(w);
    204208                for (Node n: w.getNodes()) {
    205                     // we upload modified nodes even if they aren't in the current
    206                     // selection.
     209                    // we upload modified nodes even if they aren't in the current selection.
    207210                    n.accept(this);
    208211                }
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r13453 r13497  
    329329            version = copyFrom.version;
    330330            uploadPolicy = copyFrom.uploadPolicy;
     331            downloadPolicy = copyFrom.downloadPolicy;
    331332            isReadOnly.set(copyFrom.isReadOnly.get());
    332333        } finally {
  • trunk/src/org/openstreetmap/josm/data/osm/DataSetMerger.java

    r11374 r13497  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.geom.Area;
    67import java.util.ArrayList;
    78import java.util.Collection;
     
    1415import java.util.Set;
    1516
     17import org.openstreetmap.josm.data.DataSource;
    1618import org.openstreetmap.josm.data.conflict.Conflict;
    1719import org.openstreetmap.josm.data.conflict.ConflictCollection;
     
    432434            candidates.clear();
    433435            fixReferences();
     436
     437            Area a = targetDataSet.getDataSourceArea();
     438
     439            // copy the merged layer's data source info.
     440            // only add source rectangles if they are not contained in the layer already.
     441            for (DataSource src : sourceDataSet.getDataSources()) {
     442                if (a == null || !a.contains(src.bounds.asRect())) {
     443                    targetDataSet.addDataSource(src);
     444                }
     445            }
     446
     447            // copy the merged layer's API version
     448            if (targetDataSet.getVersion() == null) {
     449                targetDataSet.setVersion(sourceDataSet.getVersion());
     450            }
     451
     452            // copy the merged layer's policies and locked status
     453            if (sourceDataSet.getUploadPolicy() != null && (targetDataSet.getUploadPolicy() == null
     454                    || sourceDataSet.getUploadPolicy().compareTo(targetDataSet.getUploadPolicy()) > 0)) {
     455                targetDataSet.setUploadPolicy(sourceDataSet.getUploadPolicy());
     456            }
     457            if (sourceDataSet.getDownloadPolicy() != null && (targetDataSet.getDownloadPolicy() == null
     458                    || sourceDataSet.getDownloadPolicy().compareTo(targetDataSet.getDownloadPolicy()) > 0)) {
     459                targetDataSet.setDownloadPolicy(sourceDataSet.getDownloadPolicy());
     460            }
     461            if (sourceDataSet.isLocked() && !targetDataSet.isLocked()) {
     462                targetDataSet.lock();
     463            }
    434464        } finally {
    435465            targetDataSet.endUpdate();
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r13462 r13497  
    552552        }
    553553
    554         Area a = data.getDataSourceArea();
    555 
    556         // copy the merged layer's data source info.
    557         // only add source rectangles if they are not contained in the layer already.
    558         for (DataSource src : from.getDataSources()) {
    559             if (a == null || !a.contains(src.bounds.asRect())) {
    560                 data.addDataSource(src);
    561             }
    562         }
    563 
    564         // copy the merged layer's API version
    565         if (data.getVersion() == null) {
    566             data.setVersion(from.getVersion());
    567         }
    568 
    569554        int numNewConflicts = 0;
    570555        for (Conflict<?> c : visitor.getConflicts()) {
  • trunk/test/unit/org/openstreetmap/josm/data/osm/DataSetTest.java

    r12479 r13497  
    33
    44import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
    56import static org.junit.Assert.assertTrue;
    67
     
    1415import org.junit.Test;
    1516import org.openstreetmap.josm.data.coor.LatLon;
     17import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
    1618import org.openstreetmap.josm.data.osm.DataSet.UploadPolicy;
    1719import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    194196    }
    195197
     198    /**
     199     * Unit test for {@link DataSet#mergeFrom} - Policies.
     200     */
     201    @Test
     202    public void testMergePolicies() {
     203        DataSet ds1 = new DataSet();
     204        DataSet ds2 = new DataSet();
     205
     206        ds1.setUploadPolicy(UploadPolicy.BLOCKED);
     207        ds2.setUploadPolicy(UploadPolicy.NORMAL);
     208        ds1.mergeFrom(ds2);
     209        assertEquals(UploadPolicy.BLOCKED, ds1.getUploadPolicy());
     210
     211        ds1.setUploadPolicy(UploadPolicy.NORMAL);
     212        ds2.setUploadPolicy(UploadPolicy.BLOCKED);
     213        ds1.mergeFrom(ds2);
     214        assertEquals(UploadPolicy.BLOCKED, ds1.getUploadPolicy());
     215
     216        ds1.setDownloadPolicy(DownloadPolicy.BLOCKED);
     217        ds2.setDownloadPolicy(DownloadPolicy.NORMAL);
     218        ds1.mergeFrom(ds2);
     219        assertEquals(DownloadPolicy.BLOCKED, ds1.getDownloadPolicy());
     220
     221        ds1.setDownloadPolicy(DownloadPolicy.NORMAL);
     222        ds2.setDownloadPolicy(DownloadPolicy.BLOCKED);
     223        ds1.mergeFrom(ds2);
     224        assertEquals(DownloadPolicy.BLOCKED, ds1.getDownloadPolicy());
     225
     226        ds2.lock();
     227        assertFalse(ds1.isLocked());
     228        assertTrue(ds2.isLocked());
     229        ds1.mergeFrom(ds2);
     230        assertTrue(ds1.isLocked());
     231    }
     232
    196233    private static void assertEqualsDataSet(DataSet ds1, DataSet ds2) {
    197234        assertEquals(new ArrayList<>(ds1.getNodes()), new ArrayList<>(ds2.getNodes()));
     
    202239        assertEquals(ds1.getVersion(), ds2.getVersion());
    203240    }
     241
     242    /**
     243     * Checks that enum values are defined in the correct order.
     244     */
     245    @Test
     246    public void testEnumOrder() {
     247        assertTrue(DownloadPolicy.BLOCKED.compareTo(DownloadPolicy.NORMAL) > 0);
     248        assertTrue(UploadPolicy.BLOCKED.compareTo(UploadPolicy.NORMAL) > 0);
     249        assertTrue(UploadPolicy.BLOCKED.compareTo(UploadPolicy.DISCOURAGED) > 0);
     250        assertTrue(UploadPolicy.DISCOURAGED.compareTo(UploadPolicy.NORMAL) > 0);
     251    }
    204252}
Note: See TracChangeset for help on using the changeset viewer.