- Timestamp:
- 2018-02-18T05:02:23+01:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 103 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r13326 r13434 270 270 271 271 /** 272 * Gets the active edit data set .272 * Gets the active edit data set (not read-only). 273 273 * @return That data set, <code>null</code>. 274 * @see #getActiveDataSet 274 275 * @since 12691 275 276 */ … … 277 278 278 279 /** 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); 284 293 285 294 /** -
trunk/src/org/openstreetmap/josm/actions/AbstractInfoAction.java
r12630 r13434 101 101 protected void launchInfoBrowsersForSelectedPrimitivesAndNote() { 102 102 List<OsmPrimitive> primitivesToShow = new ArrayList<>(); 103 DataSet ds = getLayerManager().get EditDataSet();103 DataSet ds = getLayerManager().getActiveDataSet(); 104 104 if (ds != null) { 105 105 primitivesToShow.addAll(ds.getAllSelected()); … … 155 155 @Override 156 156 protected void updateEnabledState() { 157 DataSet ds = getLayerManager().get EditDataSet();157 DataSet ds = getLayerManager().getActiveDataSet(); 158 158 setEnabled(ds != null && !ds.selectionEmpty()); 159 159 } -
trunk/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
r13107 r13434 340 340 @Override 341 341 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 342 setEnabled(selection != null && !selection.isEmpty());342 updateEnabledStateOnModifiableSelection(selection); 343 343 } 344 344 -
trunk/src/org/openstreetmap/josm/actions/AlignInLineAction.java
r13108 r13434 434 434 @Override 435 435 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 436 setEnabled(selection != null && !selection.isEmpty());436 updateEnabledStateOnModifiableSelection(selection); 437 437 } 438 438 } -
trunk/src/org/openstreetmap/josm/actions/AutoScaleAction.java
r12853 r13434 76 76 */ 77 77 public static void zoomToSelection() { 78 DataSet dataSet = MainApplication.getLayerManager().get EditDataSet();78 DataSet dataSet = MainApplication.getLayerManager().getActiveDataSet(); 79 79 if (dataSet == null) { 80 80 return; … … 286 286 Collection<OsmPrimitive> sel = new HashSet<>(); 287 287 if ("selection".equals(mode)) { 288 DataSet dataSet = getLayerManager().get EditDataSet();288 DataSet dataSet = getLayerManager().getActiveDataSet(); 289 289 if (dataSet != null) { 290 290 sel = dataSet.getSelected(); … … 324 324 lastZoomTime = -1; 325 325 } 326 final DataSet dataset = getLayerManager().get EditDataSet();326 final DataSet dataset = getLayerManager().getActiveDataSet(); 327 327 if (dataset != null) { 328 328 List<DataSource> dataSources = new ArrayList<>(dataset.getDataSources()); … … 337 337 } else { 338 338 lastZoomArea = -1; 339 Area sourceArea = getLayerManager().get EditDataSet().getDataSourceArea();339 Area sourceArea = getLayerManager().getActiveDataSet().getDataSourceArea(); 340 340 if (sourceArea != null) { 341 341 v.visit(new Bounds(sourceArea.getBounds2D())); … … 353 353 @Override 354 354 protected void updateEnabledState() { 355 DataSet ds = getLayerManager().get EditDataSet();355 DataSet ds = getLayerManager().getActiveDataSet(); 356 356 MapFrame map = MainApplication.getMap(); 357 357 switch (mode) { -
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r12641 r13434 251 251 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 252 252 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 } 256 258 } 257 259 } -
trunk/src/org/openstreetmap/josm/actions/CopyAction.java
r12639 r13434 43 43 @Override 44 44 public void actionPerformed(ActionEvent e) { 45 DataSet set = getLayerManager().get EditDataSet();45 DataSet set = getLayerManager().getActiveDataSet(); 46 46 Collection<OsmPrimitive> selection = set == null ? Collections.<OsmPrimitive>emptySet() : set.getSelected(); 47 47 if (selection.isEmpty()) { … … 50 50 } 51 51 52 copy(getLayerManager().get EditLayer(), selection);52 copy(getLayerManager().getActiveDataLayer(), selection); 53 53 } 54 54 … … 66 66 @Override 67 67 protected void updateEnabledState() { 68 updateEnabledStateOnCurrentSelection( );68 updateEnabledStateOnCurrentSelection(true); 69 69 } 70 70 -
trunk/src/org/openstreetmap/josm/actions/CopyCoordinatesAction.java
r13106 r13434 55 55 56 56 private Collection<Node> getSelectedNodes() { 57 DataSet ds = getLayerManager().get EditDataSet();57 DataSet ds = getLayerManager().getActiveDataSet(); 58 58 if (ds == null) { 59 59 return Collections.emptyList(); -
trunk/src/org/openstreetmap/josm/actions/CreateCircleAction.java
r13107 r13434 297 297 @Override 298 298 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 299 setEnabled(selection != null && !selection.isEmpty());299 updateEnabledStateOnModifiableSelection(selection); 300 300 } 301 301 } -
trunk/src/org/openstreetmap/josm/actions/DeleteAction.java
r12763 r13434 82 82 @Override 83 83 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 84 setEnabled(selection != null && !selection.isEmpty());84 updateEnabledStateOnModifiableSelection(selection); 85 85 } 86 86 -
trunk/src/org/openstreetmap/josm/actions/DistributeAction.java
r12641 r13434 305 305 @Override 306 306 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 307 setEnabled(selection != null && !selection.isEmpty());307 updateEnabledStateOnModifiableSelection(selection); 308 308 } 309 309 } -
trunk/src/org/openstreetmap/josm/actions/DownloadReferrersAction.java
r12636 r13434 66 66 @Override 67 67 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 68 setEnabled(selection != null && !selection.isEmpty());68 updateEnabledStateOnModifiableSelection(selection); 69 69 } 70 70 } -
trunk/src/org/openstreetmap/josm/actions/DuplicateAction.java
r10766 r13434 43 43 @Override 44 44 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 45 setEnabled(selection != null && !selection.isEmpty());45 updateEnabledStateOnModifiableSelection(selection); 46 46 } 47 47 } -
trunk/src/org/openstreetmap/josm/actions/FollowLineAction.java
r12726 r13434 56 56 @Override 57 57 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 58 setEnabled(selection != null && !selection.isEmpty());58 updateEnabledStateOnModifiableSelection(selection); 59 59 } 60 60 -
trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java
r12637 r13434 38 38 @Override 39 39 public void actionPerformed(ActionEvent ae) { 40 DataSet set = getLayerManager().get EditDataSet();40 DataSet set = getLayerManager().getActiveDataSet(); 41 41 if (set != null && !set.selectionEmpty()) { 42 42 HistoryBrowserDialogManager.getInstance().showHistory(set.getAllSelected()); -
trunk/src/org/openstreetmap/josm/actions/InfoAction.java
r12672 r13434 34 34 @Override 35 35 public void actionPerformed(ActionEvent ae) { 36 DataSet set = getLayerManager().get EditDataSet();36 DataSet set = getLayerManager().getActiveDataSet(); 37 37 if (set != null) { 38 38 new InspectPrimitiveDialog(set.getAllSelected(), set).showDialog(); … … 42 42 @Override 43 43 public void updateEnabledState() { 44 updateEnabledStateOnCurrentSelection( );44 updateEnabledStateOnCurrentSelection(true); 45 45 } 46 46 -
trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java
r13173 r13434 1619 1619 @Override 1620 1620 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 1621 setEnabled(selection != null && !selection.isEmpty());1621 updateEnabledStateOnModifiableSelection(selection); 1622 1622 } 1623 1623 } -
trunk/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
r12778 r13434 215 215 @Override 216 216 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 217 setEnabled(selection != null && !selection.isEmpty());217 updateEnabledStateOnModifiableSelection(selection); 218 218 } 219 219 } -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r12749 r13434 335 335 * Updates enabled state according to primitives currently selected in edit data set, if any. 336 336 * Can be called in {@link #updateEnabledState()} implementations. 337 * @see #updateEnabledStateOnCurrentSelection(boolean) 337 338 * @since 10409 338 339 */ 339 340 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 { 342 355 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)); 346 369 } 347 370 -
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r13189 r13434 28 28 import org.openstreetmap.josm.data.coor.EastNorth; 29 29 import org.openstreetmap.josm.data.coor.LatLon; 30 import org.openstreetmap.josm.data.osm.DataSet; 30 31 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 31 32 import org.openstreetmap.josm.data.osm.Node; … … 364 365 @Override 365 366 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)) { 367 369 setEnabled(false); 368 370 return; -
trunk/src/org/openstreetmap/josm/actions/MergeSelectionAction.java
r11848 r13434 76 76 @Override 77 77 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 78 setEnabled(selection != null && !selection.isEmpty());78 updateEnabledStateOnModifiableSelection(selection); 79 79 } 80 80 -
trunk/src/org/openstreetmap/josm/actions/MirrorAction.java
r12641 r13434 90 90 @Override 91 91 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 92 setEnabled(selection != null && !selection.isEmpty());92 updateEnabledStateOnModifiableSelection(selection); 93 93 } 94 94 } -
trunk/src/org/openstreetmap/josm/actions/MoveAction.java
r13308 r13434 175 175 @Override 176 176 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 177 setEnabled(selection != null && !selection.isEmpty());177 updateEnabledStateOnModifiableSelection(selection); 178 178 } 179 179 } -
trunk/src/org/openstreetmap/josm/actions/MoveNodeAction.java
r12641 r13434 11 11 import org.openstreetmap.josm.command.MoveCommand; 12 12 import org.openstreetmap.josm.data.coor.LatLon; 13 import org.openstreetmap.josm.data.osm.DataSet; 13 14 import org.openstreetmap.josm.data.osm.Node; 14 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 61 62 @Override 62 63 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)) { 64 66 setEnabled(false); 65 67 return; -
trunk/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
r13123 r13434 139 139 @Override 140 140 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 141 setEnabled(selection != null && !selection.isEmpty());141 updateEnabledStateOnModifiableSelection(selection); 142 142 } 143 143 } … … 646 646 @Override 647 647 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 648 setEnabled(selection != null && !selection.isEmpty());648 updateEnabledStateOnModifiableSelection(selection); 649 649 } 650 650 } -
trunk/src/org/openstreetmap/josm/actions/PasteTagsAction.java
r12537 r13434 9 9 import java.util.Collection; 10 10 11 import org.openstreetmap.josm.data.osm.DataSet;12 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; 13 12 import org.openstreetmap.josm.gui.datatransfer.OsmTransferHandler; … … 50 49 @Override 51 50 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(); 59 52 } 60 53 61 54 @Override 62 55 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 63 setEnabled(selection != null && !selection.isEmpty());56 updateEnabledStateOnModifiableSelection(selection); 64 57 } 65 58 } -
trunk/src/org/openstreetmap/josm/actions/PurgeAction.java
r13206 r13434 196 196 @Override 197 197 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 198 setEnabled(selection != null && !selection.isEmpty());198 updateEnabledStateOnModifiableSelection(selection); 199 199 } 200 200 } -
trunk/src/org/openstreetmap/josm/actions/ReverseWayAction.java
r13123 r13434 168 168 @Override 169 169 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())); 171 172 } 172 173 } -
trunk/src/org/openstreetmap/josm/actions/SelectAllAction.java
r12581 r13434 30 30 if (!isEnabled()) 31 31 return; 32 DataSet ds = getLayerManager().get EditDataSet();32 DataSet ds = getLayerManager().getActiveDataSet(); 33 33 ds.setSelected(ds.getPrimitives(OsmPrimitive::isSelectable)); 34 34 } … … 36 36 /** 37 37 * Refreshes the enabled state 38 *39 38 */ 40 39 @Override 41 40 protected void updateEnabledState() { 42 setEnabled(getLayerManager().get EditLayer() != null);41 setEnabled(getLayerManager().getActiveDataSet() != null); 43 42 } 44 43 } -
trunk/src/org/openstreetmap/josm/actions/SelectByInternalPointAction.java
r12636 r13434 38 38 */ 39 39 public static Collection<OsmPrimitive> getSurroundingObjects(EastNorth internalPoint) { 40 return getSurroundingObjects(MainApplication.getLayerManager().get EditDataSet(), internalPoint, false);40 return getSurroundingObjects(MainApplication.getLayerManager().getActiveDataSet(), internalPoint, false); 41 41 } 42 42 … … 103 103 public static void performSelection(EastNorth internalPoint, boolean doAdd, boolean doRemove) { 104 104 final Collection<OsmPrimitive> surroundingObjects = getSurroundingObjects(internalPoint); 105 final DataSet ds = MainApplication.getLayerManager().get EditDataSet();105 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 106 106 if (surroundingObjects.isEmpty()) { 107 107 return; -
trunk/src/org/openstreetmap/josm/actions/SelectNonBranchingWaySequencesAction.java
r12636 r13434 30 30 @Override 31 31 public void actionPerformed(ActionEvent ev) { 32 DataSet ds = getLayerManager().get EditDataSet();32 DataSet ds = getLayerManager().getActiveDataSet(); 33 33 SelectNonBranchingWaySequences ws = new SelectNonBranchingWaySequences(ds.getSelectedWays()); 34 34 ws.extend(ds); … … 41 41 @Override 42 42 protected void updateEnabledState() { 43 setEnabled(getLayerManager().get EditDataSet() != null);43 setEnabled(getLayerManager().getActiveDataSet() != null); 44 44 } 45 45 } -
trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
r12881 r13434 27 27 import org.openstreetmap.josm.data.osm.DataSet; 28 28 import org.openstreetmap.josm.data.osm.DatasetConsistencyTest; 29 import org.openstreetmap.josm.spi.preferences.Setting;30 29 import org.openstreetmap.josm.data.preferences.sources.MapPaintPrefHelper; 31 30 import org.openstreetmap.josm.data.preferences.sources.PresetPrefHelper; … … 39 38 import org.openstreetmap.josm.plugins.PluginHandler; 40 39 import org.openstreetmap.josm.spi.preferences.Config; 40 import org.openstreetmap.josm.spi.preferences.Setting; 41 41 import org.openstreetmap.josm.tools.Logging; 42 42 import org.openstreetmap.josm.tools.PlatformHookUnixoid; … … 178 178 } 179 179 if (Main.main != null) { 180 DataSet dataset = MainApplication.getLayerManager().get EditDataSet();180 DataSet dataset = MainApplication.getLayerManager().getActiveDataSet(); 181 181 if (dataset != null) { 182 182 String result = DatasetConsistencyTest.runTests(dataset); -
trunk/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
r12846 r13434 301 301 @Override 302 302 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 303 setEnabled(selection != null && !selection.isEmpty());303 updateEnabledStateOnModifiableSelection(selection); 304 304 } 305 305 } -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r13206 r13434 26 26 import org.openstreetmap.josm.Main; 27 27 import org.openstreetmap.josm.command.SplitWayCommand; 28 import org.openstreetmap.josm.data.osm.DataSet; 28 29 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 29 30 import org.openstreetmap.josm.data.osm.Node; … … 294 295 @Override 295 296 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())); 307 301 } 308 302 } -
trunk/src/org/openstreetmap/josm/actions/TaggingPresetSearchAction.java
r12834 r13434 31 31 public void actionPerformed(ActionEvent e) { 32 32 33 if (MainApplication.getLayerManager().get EditLayer() == null)33 if (MainApplication.getLayerManager().getActiveDataSet() == null) 34 34 return; 35 35 -
trunk/src/org/openstreetmap/josm/actions/UnGlueAction.java
r12749 r13434 654 654 @Override 655 655 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 656 setEnabled(selection != null && !selection.isEmpty());656 updateEnabledStateOnModifiableSelection(selection); 657 657 } 658 658 -
trunk/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java
r13329 r13434 177 177 @Override 178 178 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 179 setEnabled(selection != null && !selection.isEmpty());179 updateEnabledStateOnModifiableSelection(selection); 180 180 } 181 181 } -
trunk/src/org/openstreetmap/josm/actions/UnselectAllAction.java
r12581 r13434 30 30 if (!isEnabled()) 31 31 return; 32 getLayerManager().get EditDataSet().setSelected();32 getLayerManager().getActiveDataSet().setSelected(); 33 33 } 34 34 … … 38 38 @Override 39 39 protected void updateEnabledState() { 40 setEnabled(getLayerManager().get EditLayer() != null);40 setEnabled(getLayerManager().getActiveDataSet() != null); 41 41 } 42 42 } -
trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java
r12809 r13434 63 63 @Override 64 64 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 65 setEnabled(selection != null && !selection.isEmpty());65 updateEnabledStateOnModifiableSelection(selection); 66 66 } 67 67 -
trunk/src/org/openstreetmap/josm/actions/ValidateAction.java
r12649 r13434 76 76 Collection<OsmPrimitive> selection; 77 77 if (getSelectedItems) { 78 selection = getLayerManager().get EditDataSet().getAllSelected();78 selection = getLayerManager().getActiveDataSet().getAllSelected(); 79 79 if (selection.isEmpty()) { 80 selection = getLayerManager().get EditDataSet().allNonDeletedPrimitives();80 selection = getLayerManager().getActiveDataSet().allNonDeletedPrimitives(); 81 81 lastSelection = null; 82 82 } else { … … 87 87 } else { 88 88 selection = Optional.ofNullable(lastSelection).orElseGet( 89 () -> getLayerManager().get EditDataSet().allNonDeletedPrimitives());89 () -> getLayerManager().getActiveDataSet().allNonDeletedPrimitives()); 90 90 } 91 91 … … 95 95 @Override 96 96 public void updateEnabledState() { 97 setEnabled(getLayerManager().get EditLayer() != null);97 setEnabled(getLayerManager().getActiveDataSet() != null); 98 98 } 99 99 … … 105 105 106 106 /** 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 110 108 */ 111 109 static class ValidationTask extends PleaseWaitRunnable { … … 117 115 118 116 /** 119 * 117 * Constructs a new {@code ValidationTask} 120 118 * @param tests the tests to run 121 119 * @param validatedPrimitives the collection of primitives to validate. -
trunk/src/org/openstreetmap/josm/actions/WireframeToggleAction.java
r12637 r13434 38 38 @Override 39 39 protected void updateEnabledState() { 40 setEnabled(getLayerManager().get EditLayer() != null);40 setEnabled(getLayerManager().getActiveDataSet() != null); 41 41 } 42 42 -
trunk/src/org/openstreetmap/josm/actions/ZoomToAction.java
r12636 r13434 105 105 106 106 protected final void updateEnabledState() { 107 if (Main.main == null || MainApplication.getLayerManager().get EditLayer() != this.table.getLayer()) {107 if (Main.main == null || MainApplication.getLayerManager().getActiveDataLayer() != this.table.getLayer()) { 108 108 setEnabled(false); 109 109 putValue(SHORT_DESCRIPTION, descriptionInactiveLayer); -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r12679 r13434 16 16 import java.util.regex.Matcher; 17 17 import java.util.regex.Pattern; 18 import java.util.stream.Stream; 18 19 19 20 import org.openstreetmap.josm.data.Bounds; … … 227 228 } 228 229 230 /** 231 * Returns the number of modifiable data layers 232 * @return number of modifiable data layers 233 * @deprecated Use {@link #getNumModifiableDataLayers} 234 */ 235 @Deprecated 229 236 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); 235 261 } 236 262 … … 257 283 258 284 protected OsmDataLayer addNewLayerIfRequired(String newLayerName) { 259 int numDataLayers = getNumDataLayers();285 long numDataLayers = getNumModifiableDataLayers(); 260 286 if (newLayer || numDataLayers == 0 || (numDataLayers > 1 && getEditLayer() == null)) { 261 287 // the user explicitly wants a new layer, we don't have any layer at all … … 272 298 OsmDataLayer layer = addNewLayerIfRequired(newLayerName); 273 299 if (layer == null) { 274 layer = Optional.ofNullable(getEditLayer()).orElseGet(this::getFirst DataLayer);300 layer = Optional.ofNullable(getEditLayer()).orElseGet(this::getFirstModifiableDataLayer); 275 301 Collection<OsmPrimitive> primitivesToUpdate = searchPrimitivesToUpdate(bounds, layer.data); 276 302 layer.mergeFrom(dataSet); -
trunk/src/org/openstreetmap/josm/actions/mapmode/AddNoteAction.java
r12630 r13434 17 17 import org.openstreetmap.josm.gui.NoteInputDialog; 18 18 import org.openstreetmap.josm.gui.Notification; 19 import org.openstreetmap.josm.gui.layer.Layer; 20 import org.openstreetmap.josm.gui.layer.NoteLayer; 19 21 import org.openstreetmap.josm.gui.util.KeyPressReleaseListener; 20 22 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 100 102 // Do nothing 101 103 } 104 105 @Override 106 public boolean layerIsSupported(Layer l) { 107 return l instanceof NoteLayer; 108 } 102 109 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r12846 r13434 320 320 @Override 321 321 public boolean layerIsSupported(Layer l) { 322 return l instanceof OsmDataLayer;322 return isEditableDataLayer(l); 323 323 } 324 324 -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
r13334 r13434 1373 1373 @Override 1374 1374 public boolean layerIsSupported(Layer l) { 1375 return l instanceof OsmDataLayer;1375 return isEditableDataLayer(l); 1376 1376 } 1377 1377 -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawSnapHelper.java
r12846 r13434 448 448 projectionSource = null; 449 449 if (DrawAction.SNAP_TO_PROJECTIONS.get()) { 450 DataSet ds = drawAction.getLayerManager().get EditDataSet();450 DataSet ds = drawAction.getLayerManager().getActiveDataSet(); 451 451 Collection<Way> selectedWays = ds.getSelectedWays(); 452 452 if (selectedWays.size() == 1) { -
trunk/src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java
r13135 r13434 54 54 import org.openstreetmap.josm.gui.layer.Layer; 55 55 import org.openstreetmap.josm.gui.layer.MapViewPaintable; 56 import org.openstreetmap.josm.gui.layer.OsmDataLayer;57 56 import org.openstreetmap.josm.gui.util.GuiHelper; 58 57 import org.openstreetmap.josm.gui.util.KeyPressReleaseListener; … … 292 291 @Override 293 292 public boolean layerIsSupported(Layer l) { 294 return l instanceof OsmDataLayer;293 return isEditableDataLayer(l); 295 294 } 296 295 -
trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyAction.java
r13277 r13434 47 47 import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; 48 48 import org.openstreetmap.josm.gui.layer.Layer; 49 import org.openstreetmap.josm.gui.layer.OsmDataLayer;50 49 import org.openstreetmap.josm.gui.util.ModifierExListener; 51 50 import org.openstreetmap.josm.tools.ImageProvider; … … 210 209 @Override 211 210 public boolean layerIsSupported(Layer l) { 212 return l instanceof OsmDataLayer;211 return isEditableDataLayer(l); 213 212 } 214 213 -
trunk/src/org/openstreetmap/josm/actions/mapmode/MapMode.java
r13309 r13434 16 16 import org.openstreetmap.josm.gui.MapFrame; 17 17 import org.openstreetmap.josm.gui.layer.Layer; 18 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 19 import org.openstreetmap.josm.spi.preferences.Config; 19 20 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent; … … 240 241 return Collections.emptySet(); 241 242 } 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 } 242 254 } -
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
r12987 r13434 35 35 import org.openstreetmap.josm.data.preferences.BooleanProperty; 36 36 import org.openstreetmap.josm.data.preferences.CachingProperty; 37 import org.openstreetmap.josm.data.preferences.NamedColorProperty;38 37 import org.openstreetmap.josm.data.preferences.DoubleProperty; 39 38 import org.openstreetmap.josm.data.preferences.IntegerProperty; 39 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 40 40 import org.openstreetmap.josm.data.preferences.StrokeProperty; 41 41 import org.openstreetmap.josm.gui.MainApplication; … … 46 46 import org.openstreetmap.josm.gui.layer.AbstractMapViewPaintable; 47 47 import org.openstreetmap.josm.gui.layer.Layer; 48 import org.openstreetmap.josm.gui.layer.OsmDataLayer;49 48 import org.openstreetmap.josm.gui.util.ModifierExListener; 50 49 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 212 211 213 212 @Override 214 public boolean layerIsSupported(Layer l ayer) {215 return layer instanceof OsmDataLayer;213 public boolean layerIsSupported(Layer l) { 214 return isEditableDataLayer(l); 216 215 } 217 216 -
trunk/src/org/openstreetmap/josm/actions/mapmode/SelectAction.java
r13277 r13434 92 92 enum SelectActionCursor { 93 93 94 rect(NORMAL, /* ICON(cursor/modifier/)*/ "selection"), 94 rect(NORMAL, /* ICON(cursor/modifier/)*/ "selection"), 95 95 rect_add(NORMAL, /* ICON(cursor/modifier/)*/ "select_add"), 96 96 rect_rm(NORMAL, /* ICON(cursor/modifier/)*/ "select_remove"), … … 102 102 node_rm(NORMAL, /* ICON(cursor/modifier/)*/ "select_node_remove"), 103 103 virtual_node(NORMAL, /* ICON(cursor/modifier/)*/ "addnode"), 104 scale(/* ICON(cursor/)*/ "scale", null), 104 scale(/* ICON(cursor/)*/ "scale", null), 105 105 rotate(/* ICON(cursor/)*/ "rotate", null), 106 106 merge(/* ICON(cursor/)*/ "crosshair", null), 107 lasso(NORMAL, /* ICON(cursor/modifier/)*/ "rope"), 107 lasso(NORMAL, /* ICON(cursor/modifier/)*/ "rope"), 108 108 merge_to_node(/* ICON(cursor/)*/ "crosshair", /* ICON(cursor/modifier/)*/"joinnode"), 109 109 move(Cursor.MOVE_CURSOR); … … 265 265 266 266 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(); 269 270 if (ds != null && drawTargetHighlight) { 270 271 ds.setHighlightedVirtualNodes(virtualManager.virtualWays); … … 278 279 279 280 // 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()) 281 282 return repaintIfRequired(newHighlight); 282 283 … … 354 355 private boolean removeHighlighting() { 355 356 boolean needsRepaint = false; 356 DataSet ds = getLayerManager().get EditDataSet();357 DataSet ds = getLayerManager().getActiveDataSet(); 357 358 if (ds != null && !ds.getHighlightedVirtualNodes().isEmpty()) { 358 359 needsRepaint = true; … … 583 584 584 585 // Select Draw Tool if no selection has been made 585 if (!cancelDrawMode && getLayerManager().get EditDataSet().selectionEmpty()) {586 if (!cancelDrawMode && getLayerManager().getActiveDataSet().selectionEmpty()) { 586 587 map.selectDrawTool(true); 587 588 updateStatusLine(); … … 662 663 */ 663 664 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; 673 675 } 674 676 … … 956 958 957 959 private void selectPrims(Collection<OsmPrimitive> prims, boolean released, boolean area) { 958 DataSet ds = getLayerManager().get EditDataSet();960 DataSet ds = getLayerManager().getActiveDataSet(); 959 961 960 962 // not allowed together: do not change dataset selection, return early … … 1120 1122 // updateKeyModifiers() already called before! 1121 1123 1122 DataSet ds = getLayerManager().get EditDataSet();1124 DataSet ds = getLayerManager().getActiveDataSet(); 1123 1125 OsmPrimitive first = cycleList.iterator().next(), foundInDS = null; 1124 1126 OsmPrimitive nxt = first; -
trunk/src/org/openstreetmap/josm/actions/relation/AddSelectionToRelations.java
r13130 r13434 14 14 import org.openstreetmap.josm.command.SequenceCommand; 15 15 import org.openstreetmap.josm.data.SelectionChangedListener; 16 import org.openstreetmap.josm.data.osm.DataSet; 16 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 18 import org.openstreetmap.josm.data.osm.Relation; … … 39 40 Collection<Command> cmds = new LinkedList<>(); 40 41 for (Relation orig : relations) { 41 Command c = GenericRelationEditor.addPrimitivesToRelation(orig, MainApplication.getLayerManager().get EditDataSet().getSelected());42 Command c = GenericRelationEditor.addPrimitivesToRelation(orig, MainApplication.getLayerManager().getActiveDataSet().getSelected()); 42 43 if (c != null) { 43 44 cmds.add(c); … … 57 58 @Override 58 59 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 } 61 68 } 62 69 63 70 @Override 64 71 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))); 66 74 } 67 75 } -
trunk/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java
r12636 r13434 8 8 9 9 import org.openstreetmap.josm.actions.mapmode.DeleteAction; 10 import org.openstreetmap.josm.data.osm.DataSet; 10 11 import org.openstreetmap.josm.data.osm.Relation; 11 12 import org.openstreetmap.josm.gui.MainApplication; … … 47 48 deleteRelation(relations); 48 49 } 50 51 @Override 52 protected void updateEnabledState() { 53 setEnabled(!relations.isEmpty() && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isReadOnly)); 54 } 49 55 } -
trunk/src/org/openstreetmap/josm/actions/relation/DuplicateRelationAction.java
r12636 r13434 52 52 protected void updateEnabledState() { 53 53 // only one selected relation can be edited 54 setEnabled(relations.size() == 1 );54 setEnabled(relations.size() == 1 && !relations.iterator().next().getDataSet().isReadOnly()); 55 55 } 56 56 } -
trunk/src/org/openstreetmap/josm/actions/relation/EditRelationAction.java
r12846 r13434 13 13 14 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.data.osm.DataSet; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 17 import org.openstreetmap.josm.data.osm.Relation; … … 88 89 protected void updateEnabledState() { 89 90 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 } 94 97 } 95 98 } -
trunk/src/org/openstreetmap/josm/actions/relation/SelectMembersAction.java
r13130 r13434 43 43 } 44 44 if (add) { 45 MainApplication.getLayerManager().get EditLayer().data.addSelected(members);45 MainApplication.getLayerManager().getActiveDataSet().addSelected(members); 46 46 } else { 47 MainApplication.getLayerManager().get EditLayer().data.setSelected(members);47 MainApplication.getLayerManager().getActiveDataSet().setSelected(members); 48 48 } 49 49 } -
trunk/src/org/openstreetmap/josm/actions/relation/SelectRelationAction.java
r12636 r13434 6 6 import java.awt.event.ActionEvent; 7 7 8 import org.openstreetmap.josm.data.osm.DataSet; 8 9 import org.openstreetmap.josm.gui.MainApplication; 9 import org.openstreetmap.josm.gui.layer.OsmDataLayer;10 10 import org.openstreetmap.josm.tools.ImageProvider; 11 11 … … 34 34 public void actionPerformed(ActionEvent e) { 35 35 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; 38 38 if (add) { 39 editLayer.data.addSelected(relations);39 ds.addSelected(relations); 40 40 } else { 41 editLayer.data.setSelected(relations);41 ds.setSelected(relations); 42 42 } 43 43 } -
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r13432 r13434 761 761 762 762 static SearchTask newSearchTask(SearchSetting setting, SearchReceiver resultReceiver) { 763 final DataSet ds = MainApplication.getLayerManager().get EditDataSet();763 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 764 764 return newSearchTask(setting, ds, resultReceiver); 765 765 } … … 879 879 /** 880 880 * Refreshes the enabled state 881 *882 881 */ 883 882 @Override 884 883 protected void updateEnabledState() { 885 setEnabled(getLayerManager().get EditLayer() != null);884 setEnabled(getLayerManager().getActiveDataSet() != null); 886 885 } 887 886 -
trunk/src/org/openstreetmap/josm/command/conflict/ConflictResolveCommand.java
r13173 r13434 72 72 } 73 73 74 Main.main.set EditDataSet(ds);74 Main.main.setActiveDataSet(ds); 75 75 } 76 76 reconstituteConflicts(); -
trunk/src/org/openstreetmap/josm/command/conflict/RelationMemberConflictResolverCommand.java
r12726 r13434 72 72 @Override 73 73 public void undoCommand() { 74 DataSet editDs = getAffectedDataSet();75 if (!Main.main.containsDataSet( editDs)) {74 DataSet ds = getAffectedDataSet(); 75 if (!Main.main.containsDataSet(ds)) { 76 76 Logging.warn(tr("Cannot undo command ''{0}'' because layer ''{1}'' is not present any more", 77 77 this.toString(), 78 editDs.getName()78 ds.getName() 79 79 )); 80 80 return; 81 81 } 82 82 83 Main.main.set EditDataSet(editDs);83 Main.main.setActiveDataSet(ds); 84 84 85 85 // restore the former state … … 89 89 // restore a conflict if necessary 90 90 // 91 if (! editDs.getConflicts().hasConflictForMy(conflict.getMy())) {92 editDs.getConflicts().add(conflict);91 if (!ds.getConflicts().hasConflictForMy(conflict.getMy())) { 92 ds.getConflicts().add(conflict); 93 93 } 94 94 } -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r13420 r13434 17 17 import java.util.Set; 18 18 import java.util.concurrent.CopyOnWriteArrayList; 19 import java.util.concurrent.atomic.AtomicBoolean; 19 20 import java.util.concurrent.locks.Lock; 20 21 import java.util.concurrent.locks.ReadWriteLock; … … 103 104 * @author imi 104 105 */ 105 public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener {106 public final class DataSet extends QuadBucketPrimitiveStore implements Data, ProjectionChangeListener, ReadOnly { 106 107 107 108 /** … … 143 144 return xmlFlag; 144 145 } 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 } 145 162 } 146 163 … … 171 188 private String name; 172 189 private UploadPolicy uploadPolicy; 190 /** Flag used to know if the dataset should not be editable */ 191 private final AtomicBoolean isReadOnly = new AtomicBoolean(false); 173 192 174 193 private final ReadWriteLock lock = new ReentrantReadWriteLock(); … … 259 278 version = copyFrom.version; 260 279 uploadPolicy = copyFrom.uploadPolicy; 280 isReadOnly.set(copyFrom.isReadOnly.get()); 261 281 } finally { 262 282 copyFrom.getReadLock().unlock(); … … 353 373 * 354 374 * @param version the API version, i.e. "0.6" 375 * @throws IllegalStateException if the dataset is read-only 355 376 */ 356 377 public void setVersion(String version) { 378 checkModifiable(); 357 379 this.version = version; 358 380 } … … 533 555 * 534 556 * @param primitive the primitive. 557 * @throws IllegalStateException if the dataset is read-only 535 558 */ 536 559 @Override 537 560 public void addPrimitive(OsmPrimitive primitive) { 538 561 Objects.requireNonNull(primitive, "primitive"); 562 checkModifiable(); 539 563 beginUpdate(); 540 564 try { … … 561 585 * 562 586 * @param primitiveId the id of the primitive 587 * @throws IllegalStateException if the dataset is read-only 563 588 */ 564 589 public void removePrimitive(PrimitiveId primitiveId) { 590 checkModifiable(); 565 591 beginUpdate(); 566 592 try { … … 587 613 @Override 588 614 protected void removePrimitive(OsmPrimitive primitive) { 615 checkModifiable(); 589 616 beginUpdate(); 590 617 try { … … 998 1025 * @param node the node 999 1026 * @return The set of ways that have been modified 1027 * @throws IllegalStateException if the dataset is read-only 1000 1028 */ 1001 1029 public Set<Way> unlinkNodeFromWays(Node node) { 1030 checkModifiable(); 1002 1031 Set<Way> result = new HashSet<>(); 1003 1032 beginUpdate(); … … 1025 1054 * @param primitive the primitive 1026 1055 * @return The set of relations that have been modified 1056 * @throws IllegalStateException if the dataset is read-only 1027 1057 */ 1028 1058 public Set<Relation> unlinkPrimitiveFromRelations(OsmPrimitive primitive) { 1059 checkModifiable(); 1029 1060 Set<Relation> result = new HashSet<>(); 1030 1061 beginUpdate(); … … 1059 1090 * @param referencedPrimitive the referenced primitive 1060 1091 * @return The set of primitives that have been modified 1092 * @throws IllegalStateException if the dataset is read-only 1061 1093 */ 1062 1094 public Set<OsmPrimitive> unlinkReferencesToPrimitive(OsmPrimitive referencedPrimitive) { 1095 checkModifiable(); 1063 1096 Set<OsmPrimitive> result = new HashSet<>(); 1064 1097 beginUpdate(); … … 1131 1164 * } 1132 1165 * </pre> 1166 * @see #endUpdate() 1133 1167 */ 1134 1168 public void beginUpdate() { … … 1138 1172 1139 1173 /** 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> 1140 1185 * @see DataSet#beginUpdate() 1141 1186 */ … … 1273 1318 * Removes all primitives from the dataset and resets the currently selected primitives 1274 1319 * to the empty collection. Also notifies selection change listeners if necessary. 1320 * @throws IllegalStateException if the dataset is read-only 1275 1321 */ 1276 1322 @Override 1277 1323 public void clear() { 1324 checkModifiable(); 1278 1325 beginUpdate(); 1279 1326 try { … … 1292 1339 * Marks all "invisible" objects as deleted. These objects should be always marked as 1293 1340 * deleted when downloaded from the server. They can be undeleted later if necessary. 1294 * 1341 * @throws IllegalStateException if the dataset is read-only 1295 1342 */ 1296 1343 public void deleteInvisible() { 1344 checkModifiable(); 1297 1345 for (OsmPrimitive primitive:allPrimitives) { 1298 1346 if (!primitive.isVisible()) { … … 1314 1362 * @param from The source DataSet 1315 1363 * @param progressMonitor The progress monitor 1364 * @throws IllegalStateException if the dataset is read-only 1316 1365 */ 1317 1366 public synchronized void mergeFrom(DataSet from, ProgressMonitor progressMonitor) { 1318 1367 if (from != null) { 1368 checkModifiable(); 1319 1369 new DataSetMerger(this, from).merge(progressMonitor); 1320 1370 synchronized (from) { … … 1402 1452 mappaintCacheIdx++; 1403 1453 } 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 } 1404 1483 } -
trunk/src/org/openstreetmap/josm/data/osm/FilterModel.java
r13208 r13434 98 98 */ 99 99 public void executeFilters() { 100 DataSet ds = Main.main.get EditDataSet();100 DataSet ds = Main.main.getActiveDataSet(); 101 101 changed = false; 102 102 if (ds == null) { -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r13420 r13434 275 275 } 276 276 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 277 285 protected boolean writeLock() { 278 286 if (dataSet != null) { … … 305 313 @Override 306 314 public void setOsmId(long id, int version) { 315 checkDatasetNotReadOnly(); 307 316 boolean locked = writeLock(); 308 317 try { … … 343 352 @Override 344 353 public void setUser(User user) { 354 checkDatasetNotReadOnly(); 345 355 boolean locked = writeLock(); 346 356 try { … … 353 363 @Override 354 364 public void setChangesetId(int changesetId) { 365 checkDatasetNotReadOnly(); 355 366 boolean locked = writeLock(); 356 367 try { … … 367 378 @Override 368 379 public void setTimestamp(Date timestamp) { 380 checkDatasetNotReadOnly(); 369 381 boolean locked = writeLock(); 370 382 try { … … 534 546 @Override 535 547 public void setModified(boolean modified) { 548 checkDatasetNotReadOnly(); 536 549 boolean locked = writeLock(); 537 550 try { … … 548 561 @Override 549 562 public void setVisible(boolean visible) { 563 checkDatasetNotReadOnly(); 550 564 boolean locked = writeLock(); 551 565 try { … … 559 573 @Override 560 574 public void setDeleted(boolean deleted) { 575 checkDatasetNotReadOnly(); 561 576 boolean locked = writeLock(); 562 577 try { … … 577 592 @Override 578 593 protected final void setIncomplete(boolean incomplete) { 594 checkDatasetNotReadOnly(); 579 595 boolean locked = writeLock(); 580 596 try { … … 891 907 @Override 892 908 public final void setKeys(TagMap keys) { 909 checkDatasetNotReadOnly(); 893 910 boolean locked = writeLock(); 894 911 try { … … 901 918 @Override 902 919 public final void setKeys(Map<String, String> keys) { 920 checkDatasetNotReadOnly(); 903 921 boolean locked = writeLock(); 904 922 try { … … 911 929 @Override 912 930 public final void put(String key, String value) { 931 checkDatasetNotReadOnly(); 913 932 boolean locked = writeLock(); 914 933 try { … … 921 940 @Override 922 941 public final void remove(String key) { 942 checkDatasetNotReadOnly(); 923 943 boolean locked = writeLock(); 924 944 try { … … 931 951 @Override 932 952 public final void removeAll() { 953 checkDatasetNotReadOnly(); 933 954 boolean locked = writeLock(); 934 955 try { … … 966 987 */ 967 988 protected void addReferrer(OsmPrimitive referrer) { 989 checkDatasetNotReadOnly(); 968 990 if (referrers == null) { 969 991 referrers = referrer; … … 986 1008 */ 987 1009 protected void removeReferrer(OsmPrimitive referrer) { 1010 checkDatasetNotReadOnly(); 988 1011 if (referrers instanceof OsmPrimitive) { 989 1012 if (referrers == referrer) { … … 1148 1171 */ 1149 1172 public void mergeFrom(OsmPrimitive other) { 1173 checkDatasetNotReadOnly(); 1150 1174 boolean locked = writeLock(); 1151 1175 try { … … 1239 1263 */ 1240 1264 public void load(PrimitiveData data) { 1265 checkDatasetNotReadOnly(); 1241 1266 // Write lock is provided by subclasses 1242 1267 setKeys(data.hasKeys() ? data.getKeys() : null); -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r13206 r13434 46 46 */ 47 47 public void setMembers(List<RelationMember> members) { 48 checkDatasetNotReadOnly(); 48 49 boolean locked = writeLock(); 49 50 try { … … 88 89 */ 89 90 public void addMember(RelationMember member) { 91 checkDatasetNotReadOnly(); 90 92 boolean locked = writeLock(); 91 93 try { … … 105 107 */ 106 108 public void addMember(int index, RelationMember member) { 109 checkDatasetNotReadOnly(); 107 110 boolean locked = writeLock(); 108 111 try { … … 127 130 */ 128 131 public RelationMember setMember(int index, RelationMember member) { 132 checkDatasetNotReadOnly(); 129 133 boolean locked = writeLock(); 130 134 try { … … 150 154 */ 151 155 public RelationMember removeMember(int index) { 156 checkDatasetNotReadOnly(); 152 157 boolean locked = writeLock(); 153 158 try { … … 376 381 */ 377 382 public void removeMembersFor(Collection<? extends OsmPrimitive> primitives) { 383 checkDatasetNotReadOnly(); 378 384 if (primitives == null || primitives.isEmpty()) 379 385 return; -
trunk/src/org/openstreetmap/josm/data/osm/Way.java
r13206 r13434 53 53 */ 54 54 public void setNodes(List<Node> nodes) { 55 checkDatasetNotReadOnly(); 55 56 boolean locked = writeLock(); 56 57 try { … … 361 362 */ 362 363 public void removeNode(Node n) { 364 checkDatasetNotReadOnly(); 363 365 if (n == null || isIncomplete()) return; 364 366 boolean locked = writeLock(); … … 389 391 */ 390 392 public void removeNodes(Set<? extends Node> selection) { 393 checkDatasetNotReadOnly(); 391 394 if (selection == null || isIncomplete()) return; 392 395 boolean locked = writeLock(); … … 425 428 */ 426 429 public void addNode(Node n) { 430 checkDatasetNotReadOnly(); 427 431 if (n == null) return; 428 432 … … 452 456 */ 453 457 public void addNode(int offs, Node n) { 458 checkDatasetNotReadOnly(); 454 459 if (n == null) return; 455 460 -
trunk/src/org/openstreetmap/josm/data/osm/event/DatasetEventManager.java
r12636 r13434 182 182 @Override 183 183 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 184 DataSet oldData = e.getPrevious EditDataSet();184 DataSet oldData = e.getPreviousDataSet(); 185 185 if (oldData != null) { 186 186 oldData.removeDataSetListener(myListener); 187 187 } 188 188 189 DataSet newData = e.getSource().get EditDataSet();189 DataSet newData = e.getSource().getActiveDataSet(); 190 190 if (newData != null) { 191 191 newData.addDataSetListener(myListener); -
trunk/src/org/openstreetmap/josm/data/osm/event/SelectionEventManager.java
r13223 r13434 184 184 @Override 185 185 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 186 DataSet oldDataSet = e.getPrevious EditDataSet();186 DataSet oldDataSet = e.getPreviousDataSet(); 187 187 if (oldDataSet != null) { 188 188 // Fake a selection removal … … 194 194 oldDataSet.removeSelectionListener(this); 195 195 } 196 DataSet newDataSet = e.getSource().get EditDataSet();196 DataSet newDataSet = e.getSource().getActiveDataSet(); 197 197 if (newDataSet != null) { 198 198 newDataSet.addSelectionListener(this); -
trunk/src/org/openstreetmap/josm/data/projection/Projections.java
r13423 r13434 320 320 cproj.update(pd.definition); 321 321 } catch (ProjectionConfigurationException ex) { 322 throw new RuntimeException("Error loading " + code, ex);322 throw new JosmRuntimeException("Error loading " + code, ex); 323 323 } 324 324 proj = cproj; -
trunk/src/org/openstreetmap/josm/data/validation/TestError.java
r12390 r13434 12 12 13 13 import org.openstreetmap.josm.command.Command; 14 import org.openstreetmap.josm.data.osm.DataSet; 14 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 358 359 */ 359 360 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); 361 363 } 362 364 -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r13402 r13434 527 527 return ((DrawAction) map.mapMode).getInProgressSelection(); 528 528 } else { 529 DataSet ds = layerManager.get EditDataSet();529 DataSet ds = layerManager.getActiveDataSet(); 530 530 if (ds == null) return null; 531 531 return ds.getSelected(); … … 539 539 540 540 @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) { 542 547 Optional<OsmDataLayer> layer = getLayerManager().getLayersOfType(OsmDataLayer.class).stream() 543 548 .filter(l -> l.data.equals(ds)).findFirst(); -
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r13178 r13434 327 327 boolean middleMouseDown = (ms.modifiers & MouseEvent.BUTTON2_DOWN_MASK) != 0; 328 328 329 ds = mv.getLayerManager().get EditDataSet();329 ds = mv.getLayerManager().getActiveDataSet(); 330 330 if (ds != null) { 331 331 // This is not perfect, if current dataset was changed during execution, the lock would be useless … … 512 512 */ 513 513 private void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) { 514 DataSet ds = MainApplication.getLayerManager().get EditDataSet();514 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 515 515 // Find some items that are required for cycling through 516 516 OsmPrimitive firstItem = null; … … 603 603 */ 604 604 private void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) { 605 DataSet ds = MainApplication.getLayerManager().get EditDataSet();605 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 606 606 if (ds.isSelected(osm)) { 607 607 lbl.setBackground(SystemColor.textHighlight); … … 676 676 @Override 677 677 public void mouseClicked(MouseEvent e) { 678 DataSet ds = MainApplication.getLayerManager().get EditDataSet();678 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 679 679 // Let the user toggle the selection 680 680 ds.toggleSelected(osm); -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r13400 r13434 381 381 382 382 /** 383 * Replies true if the active data layer (edit layer)is visible.383 * Replies true if the active data layer is visible. 384 384 * 385 * @return true if the active data layer (edit layer)is visible, false otherwise385 * @return true if the active data layer is visible, false otherwise 386 386 */ 387 387 public boolean isActiveLayerVisible() { 388 OsmDataLayer e = layerManager.get EditLayer();388 OsmDataLayer e = layerManager.getActiveDataLayer(); 389 389 return e != null && e.isVisible(); 390 390 } -
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r13200 r13434 939 939 private Map<Double, List<Node>> getNearestNodesImpl(Point p, Predicate<OsmPrimitive> predicate) { 940 940 Map<Double, List<Node>> nearestMap = new TreeMap<>(); 941 DataSet ds = MainApplication.getLayerManager().get EditDataSet();941 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 942 942 943 943 if (ds != null) { … … 1148 1148 private Map<Double, List<WaySegment>> getNearestWaySegmentsImpl(Point p, Predicate<OsmPrimitive> predicate) { 1149 1149 Map<Double, List<WaySegment>> nearestMap = new TreeMap<>(); 1150 DataSet ds = MainApplication.getLayerManager().get EditDataSet();1150 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 1151 1151 1152 1152 if (ds != null) { … … 1509 1509 public final OsmPrimitive getNearestNodeOrWay(Point p, Predicate<OsmPrimitive> predicate, boolean useSelected) { 1510 1510 Collection<OsmPrimitive> sel; 1511 DataSet ds = MainApplication.getLayerManager().get EditDataSet();1511 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 1512 1512 if (useSelected && ds != null) { 1513 1513 sel = ds.getSelected(); -
trunk/src/org/openstreetmap/josm/gui/SelectionManager.java
r12961 r13434 183 183 @Override 184 184 public void mousePressed(MouseEvent e) { 185 if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1 && MainApplication.getLayerManager().get EditDataSet() != null) {185 if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1 && MainApplication.getLayerManager().getActiveDataSet() != null) { 186 186 SelectByInternalPointAction.performSelection(MainApplication.getMap().mapView.getEastNorth(e.getX(), e.getY()), 187 187 (e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0, … … 374 374 } 375 375 376 DataSet ds = MainApplication.getLayerManager().get EditDataSet();376 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 377 377 if (clicked) { 378 378 Point center = new Point(selectionResult.xpoints[0], selectionResult.ypoints[0]); -
trunk/src/org/openstreetmap/josm/gui/autofilter/AutoFilterManager.java
r12881 r13434 22 22 23 23 import org.openstreetmap.josm.actions.mapmode.MapMode; 24 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent;25 import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;26 24 import org.openstreetmap.josm.data.osm.BBox; 27 25 import org.openstreetmap.josm.data.osm.DataSet; … … 56 54 import org.openstreetmap.josm.gui.widgets.OSDLabel; 57 55 import org.openstreetmap.josm.spi.preferences.Config; 56 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent; 57 import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener; 58 58 import org.openstreetmap.josm.tools.Logging; 59 59 … … 194 194 195 195 private static Set<String> getTagValues(String key) { 196 DataSet ds = MainApplication.getLayerManager().get EditDataSet();196 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 197 197 Set<String> values = new TreeSet<>(); 198 198 if (ds != null) { … … 371 371 model.executeFilters(); 372 372 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(); 376 376 } 377 377 } … … 422 422 @Override 423 423 public void layerRemoving(LayerRemoveEvent e) { 424 if (MainApplication.getLayerManager().get EditLayer() == null) {424 if (MainApplication.getLayerManager().getActiveDataLayer() == null) { 425 425 resetCurrentAutoFilter(); 426 426 } -
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
r13426 r13434 48 48 import org.openstreetmap.josm.data.imagery.TileLoaderFactory; 49 49 import org.openstreetmap.josm.data.osm.BBox; 50 import org.openstreetmap.josm.data.osm.DataSet; 50 51 import org.openstreetmap.josm.data.preferences.BooleanProperty; 51 52 import org.openstreetmap.josm.data.preferences.StringProperty; … … 53 54 import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer; 54 55 import org.openstreetmap.josm.gui.layer.MainLayerManager; 55 import org.openstreetmap.josm.gui.layer.OsmDataLayer;56 56 import org.openstreetmap.josm.gui.layer.TMSLayer; 57 57 import org.openstreetmap.josm.spi.preferences.Config; … … 237 237 Graphics2D g2d = (Graphics2D) g; 238 238 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, 240 240 // and it has defined bounds. Routine is analogous to that in OsmDataLayer's paint routine (but just different 241 241 // 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()) { 244 244 // initialize area with current viewport 245 245 Rectangle b = this.getBounds(); … … 249 249 250 250 // combine successively downloaded areas after converting to screen-space 251 for (Bounds bounds : editLayer.data.getDataSourceBounds()) {251 for (Bounds bounds : ds.getDataSourceBounds()) { 252 252 if (bounds.isCollapsed()) { 253 253 continue; -
trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java
r12846 r13434 53 53 import org.openstreetmap.josm.gui.help.HelpUtil; 54 54 import org.openstreetmap.josm.gui.io.CloseChangesetTask; 55 import org.openstreetmap.josm.gui.layer.OsmDataLayer;56 55 import org.openstreetmap.josm.gui.util.GuiHelper; 57 56 import org.openstreetmap.josm.gui.widgets.ListPopupMenu; … … 123 122 ChangesetCache.getInstance().addChangesetCacheListener(inActiveDataLayerModel); 124 123 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()); 130 129 } 131 130 } … … 133 132 protected void unregisterAsListener() { 134 133 // remove the list model for the current edit layer as listener 135 //136 134 ChangesetCache.getInstance().removeChangesetCacheListener(inActiveDataLayerModel); 137 135 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 145 142 SelectionEventManager.getInstance().removeSelectionListener(inSelectionModel); 146 143 ChangesetCache.getInstance().removeChangesetCacheListener(inSelectionModel); … … 235 232 236 233 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); 241 238 } 242 239 } … … 266 263 if (sel.isEmpty()) 267 264 return; 268 if (MainApplication.getLayerManager().get EditDataSet() == null)269 return; 270 new SelectObjectsAction().selectObjectsByChangesetIds(MainApplication.getLayerManager().get EditDataSet(), sel);265 if (MainApplication.getLayerManager().getActiveDataSet() == null) 266 return; 267 new SelectObjectsAction().selectObjectsByChangesetIds(MainApplication.getLayerManager().getActiveDataSet(), sel); 271 268 } 272 269 … … 314 311 @Override 315 312 public void actionPerformed(ActionEvent e) { 316 if (MainApplication.getLayerManager().getEditLayer() == null) 313 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 314 if (ds == null) 317 315 return; 318 316 ChangesetListModel model = getCurrentChangesetListModel(); … … 321 319 return; 322 320 323 DataSet ds = MainApplication.getLayerManager().getEditLayer().data;324 321 selectObjectsByChangesetIds(ds, sel); 325 322 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r13367 r13434 160 160 public void hideNotify() { 161 161 MainApplication.getLayerManager().removeActiveLayerChangeListener(this); 162 remove EditLayerListeners(MainApplication.getLayerManager().getEditLayer());162 removeDataLayerListeners(MainApplication.getLayerManager().getEditLayer()); 163 163 } 164 164 … … 269 269 @Override 270 270 public void activeOrEditLayerChanged(ActiveLayerChangeEvent e) { 271 remove EditLayerListeners(e.getPreviousEditLayer());272 add EditLayerListeners(e.getSource().getEditLayer());271 removeDataLayerListeners(e.getPreviousDataLayer()); 272 addDataLayerListeners(e.getSource().getActiveDataLayer()); 273 273 refreshView(); 274 274 } 275 275 276 private void add EditLayerListeners(OsmDataLayer newLayer) {276 private void addDataLayerListeners(OsmDataLayer newLayer) { 277 277 if (newLayer != null) { 278 278 newLayer.getConflicts().addConflictListener(this); … … 281 281 } 282 282 283 private void remove EditLayerListeners(OsmDataLayer oldLayer) {283 private void removeDataLayerListeners(OsmDataLayer oldLayer) { 284 284 if (oldLayer != null) { 285 285 oldLayer.getConflicts().removeConflictListener(this); -
trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
r12678 r13434 114 114 115 115 protected static String buildMapPaintText() { 116 final Collection<OsmPrimitive> sel = MainApplication.getLayerManager().get EditDataSet().getAllSelected();116 final Collection<OsmPrimitive> sel = MainApplication.getLayerManager().getActiveDataSet().getAllSelected(); 117 117 ElemStyles elemstyles = MapPaintStyles.getStyles(); 118 118 NavigatableComponent nc = MainApplication.getMap().mapView; -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r13210 r13434 342 342 343 343 protected void setCurrentRelationAsSelection() { 344 MainApplication.getLayerManager().get EditDataSet().setSelected(displaylist.getSelectedValue());344 MainApplication.getLayerManager().getActiveDataSet().setSelected(displaylist.getSelectedValue()); 345 345 } 346 346 … … 351 351 @Override 352 352 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()) { 356 356 editCurrentRelation(); 357 357 } else { … … 733 733 return; 734 734 // trigger a sort of the relation list because the display name may have changed 735 //736 735 List<Relation> sel = model.getSelectedRelations(); 737 736 model.sort(); … … 742 741 @Override 743 742 public void dataChanged(DataChangedEvent event) { 744 initFromLayer(MainApplication.getLayerManager().get EditLayer());743 initFromLayer(MainApplication.getLayerManager().getActiveDataLayer()); 745 744 } 746 745 -
trunk/src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r13141 r13434 73 73 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 74 74 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 75 import org.openstreetmap.josm.gui.layer.OsmDataLayer;76 75 import org.openstreetmap.josm.gui.util.GuiHelper; 77 76 import org.openstreetmap.josm.gui.util.HighlightHelper; … … 200 199 if (idx < 0) return; 201 200 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; 204 203 OsmPrimitive osm = model.getElementAt(idx); 205 Collection<OsmPrimitive> sel = layer.data.getSelected();204 Collection<OsmPrimitive> sel = ds.getSelected(); 206 205 if (sel.size() != 1 || !sel.iterator().next().equals(osm)) { 207 206 // Select primitive if it's not the whole current selection 208 layer.data.setSelected(Collections.singleton(osm));207 ds.setSelected(Collections.singleton(osm)); 209 208 } else if (osm instanceof Relation) { 210 209 // else open relation editor if applicable … … 296 295 297 296 protected void updateEnabledState() { 298 setEnabled(MainApplication.getLayerManager().get EditLayer() != null);297 setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null); 299 298 } 300 299 … … 321 320 Collection<OsmPrimitive> sel = model.getSelected(); 322 321 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); 326 325 model.selectionModel.setSelectionInterval(0, sel.size()-1); 327 326 } … … 830 829 @Override 831 830 public void actionPerformed(ActionEvent e) { 832 MainApplication.getLayerManager().get EditDataSet().setSelected(sel);831 MainApplication.getLayerManager().getActiveDataSet().setSelected(sel); 833 832 } 834 833 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java
r12636 r13434 32 32 import org.openstreetmap.josm.actions.AbstractInfoAction; 33 33 import org.openstreetmap.josm.data.osm.DataSelectionListener; 34 import org.openstreetmap.josm.data.osm.DataSet; 34 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; 35 36 import org.openstreetmap.josm.data.osm.User; … … 347 348 users.add(data.get(index).user); 348 349 } 349 Collection<OsmPrimitive> selected = MainApplication.getLayerManager().getEditDataSet().getAllSelected(); 350 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 351 Collection<OsmPrimitive> selected = ds.getAllSelected(); 350 352 Collection<OsmPrimitive> byUser = new LinkedList<>(); 351 353 for (OsmPrimitive p : selected) { … … 354 356 } 355 357 } 356 MainApplication.getLayerManager().getEditDataSet().setSelected(byUser);358 ds.setSelected(byUser); 357 359 } 358 360 -
trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java
r13149 r13434 132 132 @Override 133 133 public void actionPerformed(ActionEvent e) { 134 final DataSet ds = MainApplication.getLayerManager().get EditDataSet();134 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 135 135 if (ds == null) { 136 136 return; … … 181 181 public void showNotify() { 182 182 DataSet.addSelectionListener(this); 183 DataSet ds = MainApplication.getLayerManager().get EditDataSet();183 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 184 184 if (ds != null) { 185 185 updateSelection(ds.getAllSelected()); … … 350 350 } 351 351 } 352 DataSet ds = MainApplication.getLayerManager().get EditDataSet();352 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 353 353 if (ds != null) { 354 354 ds.setSelected(sel); … … 494 494 495 495 if (isDblClick) { 496 DataSet ds = MainApplication.getLayerManager().get EditDataSet();496 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 497 497 if (ds != null) { 498 498 ds.setSelected(sel); … … 630 630 try { 631 631 monitor.setTicksCount(testErrors.size()); 632 final DataSet ds = MainApplication.getLayerManager().get EditDataSet();632 final DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 633 633 int i = 0; 634 634 SwingUtilities.invokeAndWait(ds::beginUpdate); -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentPanel.java
r13130 r13434 36 36 import org.openstreetmap.josm.actions.downloadtasks.ChangesetContentDownloadTask; 37 37 import org.openstreetmap.josm.data.osm.Changeset; 38 import org.openstreetmap.josm.data.osm.DataSet; 38 39 import org.openstreetmap.josm.data.osm.OsmPrimitive; 39 40 import org.openstreetmap.josm.data.osm.PrimitiveId; … … 49 50 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 50 51 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 51 import org.openstreetmap.josm.gui.layer.OsmDataLayer;52 52 import org.openstreetmap.josm.gui.util.GuiHelper; 53 53 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; … … 279 279 280 280 @Override 281 public void actionPerformed(ActionEvent arg0) {281 public void actionPerformed(ActionEvent e) { 282 282 Set<HistoryOsmPrimitive> selected = model.getSelectedPrimitives(); 283 283 if (selected.isEmpty()) return; … … 301 301 302 302 @Override 303 public void actionPerformed(ActionEvent arg0) {303 public void actionPerformed(ActionEvent e) { 304 304 final List<PrimitiveId> primitiveIds = model.getSelectedPrimitives().stream().map(HistoryOsmPrimitive::getPrimitiveId) 305 305 .collect(Collectors.toList()); … … 323 323 return null; 324 324 } 325 OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();326 if ( layer== null) {325 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 326 if (ds == null) { 327 327 return null; 328 328 } 329 329 Set<OsmPrimitive> target = new HashSet<>(); 330 330 for (HistoryOsmPrimitive p : model.getSelectedPrimitives()) { 331 OsmPrimitive op = layer.data.getPrimitiveById(p.getPrimitiveId());331 OsmPrimitive op = ds.getPrimitiveById(p.getPrimitiveId()); 332 332 if (op != null) { 333 333 target.add(op); … … 338 338 339 339 public final void updateEnabledState() { 340 setEnabled(MainApplication.getLayerManager().get EditLayer() != null && model.hasSelectedPrimitives());340 setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null && model.hasSelectedPrimitives()); 341 341 } 342 342 … … 350 350 updateEnabledState(); 351 351 } 352 353 352 } 354 353 … … 363 362 364 363 @Override 365 public void actionPerformed(ActionEvent arg0) {364 public void actionPerformed(ActionEvent e) { 366 365 final Set<OsmPrimitive> target = getTarget(); 367 366 if (target == null) { … … 372 371 return; 373 372 } 374 MainApplication.getLayerManager().get EditLayer().data.setSelected(target);373 MainApplication.getLayerManager().getActiveDataSet().setSelected(target); 375 374 } 376 375 } … … 386 385 387 386 @Override 388 public void actionPerformed(ActionEvent arg0) {387 public void actionPerformed(ActionEvent e) { 389 388 final Set<OsmPrimitive> target = getTarget(); 390 389 if (target == null) { … … 395 394 return; 396 395 } 397 MainApplication.getLayerManager().get EditLayer().data.setSelected(target);396 MainApplication.getLayerManager().getActiveDataSet().setSelected(target); 398 397 AutoScaleAction.zoomToSelection(); 399 398 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java
r12871 r13434 35 35 import org.openstreetmap.josm.data.osm.Changeset; 36 36 import org.openstreetmap.josm.data.osm.ChangesetCache; 37 import org.openstreetmap.josm.data.osm.DataSet; 37 38 import org.openstreetmap.josm.data.osm.OsmPrimitive; 38 39 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 42 43 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 43 44 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 44 import org.openstreetmap.josm.gui.layer.OsmDataLayer;45 45 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 46 46 import org.openstreetmap.josm.gui.widgets.JosmTextField; … … 72 72 private final ZoomInCurrentLayerAction actZoomInCurrentLayerAction = new ZoomInCurrentLayerAction(); 73 73 // CHECKSTYLE.ON: SingleSpaceSeparator 74 74 75 75 private JButton btnOpenChangesetPopupMenu; 76 76 … … 374 374 + "edit layer ''{1}''.</html>", 375 375 currentChangeset.getId(), 376 Utils.escapeReservedCharactersHTML(MainApplication.getLayerManager().get EditLayer().getName())376 Utils.escapeReservedCharactersHTML(MainApplication.getLayerManager().getActiveDataSet().getName()) 377 377 ), 378 378 tr("Nothing to select"), … … 383 383 384 384 @Override 385 public void actionPerformed(ActionEvent arg0) {385 public void actionPerformed(ActionEvent e) { 386 386 if (!isEnabled()) 387 387 return; 388 OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();389 if ( layer== null) {388 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 389 if (ds == null) { 390 390 return; 391 391 } 392 392 Set<OsmPrimitive> target = new HashSet<>(); 393 for (OsmPrimitive p: layer.data.allPrimitives()) {393 for (OsmPrimitive p: ds.allPrimitives()) { 394 394 if (p.isUsable() && p.getChangesetId() == currentChangeset.getId()) { 395 395 target.add(p); … … 400 400 return; 401 401 } 402 layer.data.setSelected(target);402 ds.setSelected(target); 403 403 } 404 404 405 405 public void updateEnabledState() { 406 setEnabled(MainApplication.getLayerManager().get EditLayer() != null && currentChangeset != null);406 setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null && currentChangeset != null); 407 407 } 408 408 … … 433 433 + "edit layer ''{1}''.</html>", 434 434 currentChangeset.getId(), 435 MainApplication.getLayerManager().get EditLayer().getName()435 MainApplication.getLayerManager().getActiveDataSet().getName() 436 436 ), 437 437 tr("Nothing to zoom to"), … … 442 442 443 443 @Override 444 public void actionPerformed(ActionEvent arg0) {444 public void actionPerformed(ActionEvent e) { 445 445 if (!isEnabled()) 446 446 return; 447 OsmDataLayer layer = MainApplication.getLayerManager().getEditLayer();448 if ( layer== null) {447 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 448 if (ds == null) { 449 449 return; 450 450 } 451 451 Set<OsmPrimitive> target = new HashSet<>(); 452 for (OsmPrimitive p: layer.data.allPrimitives()) {452 for (OsmPrimitive p: ds.allPrimitives()) { 453 453 if (p.isUsable() && p.getChangesetId() == currentChangeset.getId()) { 454 454 target.add(p); … … 459 459 return; 460 460 } 461 layer.data.setSelected(target);461 ds.setSelected(target); 462 462 AutoScaleAction.zoomToSelection(); 463 463 } 464 464 465 465 public void updateEnabledState() { 466 setEnabled(MainApplication.getLayerManager().get EditLayer() != null && currentChangeset != null);466 setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null && currentChangeset != null); 467 467 } 468 468 -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetsInActiveDataLayerListModel.java
r12372 r13434 4 4 import javax.swing.DefaultListSelectionModel; 5 5 6 import org.openstreetmap.josm.data.osm.DataSet; 6 7 import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent; 7 8 import org.openstreetmap.josm.data.osm.event.DataChangedEvent; … … 15 16 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 16 17 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 17 import org.openstreetmap.josm.gui.layer.OsmDataLayer;18 18 19 19 /** … … 81 81 // just init the model content. Don't register as DataSetListener. The mode 82 82 // 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); 86 86 } else { 87 87 initFromDataSet(null); -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r13130 r13434 64 64 import org.openstreetmap.josm.command.Command; 65 65 import org.openstreetmap.josm.data.SelectionChangedListener; 66 import org.openstreetmap.josm.data.osm.DataSet; 66 67 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 67 68 import org.openstreetmap.josm.data.osm.IRelation; … … 91 92 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent; 92 93 import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener; 94 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 93 95 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 94 96 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetHandler; … … 231 233 232 234 private final PreferenceChangedListener preferenceListener = e -> { 233 if (MainApplication.getLayerManager().get EditDataSet() != null) {235 if (MainApplication.getLayerManager().getActiveDataSet() != null) { 234 236 // Re-load data when display preference change 235 237 updateSelection(); … … 487 489 Relation relation = (Relation) membershipData.getValueAt(row, 0); 488 490 MainApplication.getMap().relationListDialog.selectRelation(relation); 489 RelationEditor.getEditor(490 MainApplication.getLayerManager().getEditLayer(),491 relation,492 ((MemberInfo) membershipData.getValueAt(row, 1)).role493 ).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 } 494 496 } 495 497 … … 534 536 public void setVisible(boolean b) { 535 537 super.setVisible(b); 536 if (b && MainApplication.getLayerManager().get EditDataSet() != null) {538 if (b && MainApplication.getLayerManager().getActiveDataSet() != null) { 537 539 updateSelection(); 538 540 } … … 644 646 membershipTable.setVisible(membershipData.getRowCount() > 0); 645 647 648 DataSet ds = Main.main.getActiveDataSet(); 649 boolean isReadOnly = ds != null && ds.isReadOnly(); 646 650 boolean hasSelection = !newSel.isEmpty(); 647 651 boolean hasTags = hasSelection && tagData.getRowCount() > 0; 648 652 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)); 652 656 tagTable.setVisible(hasTags); 653 657 tagTable.getTableHeader().setVisible(hasTags); … … 1055 1059 @Override 1056 1060 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) 1059 1064 || (membershipTable != null && membershipTable.getSelectedRowCount() > 0) 1060 ) ;1065 )); 1061 1066 } 1062 1067 … … 1110 1115 @Override 1111 1116 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) 1114 1120 ^ (membershipTable != null && membershipTable.getSelectedRowCount() == 1) 1115 ) ;1121 )); 1116 1122 } 1117 1123 -
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r13190 r13434 447 447 mainPanel.add(p, BorderLayout.CENTER); 448 448 449 AutoCompletionManager autocomplete = AutoCompletionManager.of(Main Application.getLayerManager().getEditLayer().data);449 AutoCompletionManager autocomplete = AutoCompletionManager.of(Main.main.getActiveDataSet()); 450 450 List<AutoCompletionItem> keyList = autocomplete.getTagKeys(DEFAULT_AC_ITEM_COMPARATOR); 451 451 … … 564 564 public void setupDialog() { 565 565 super.setupDialog(); 566 buttons.get(0).setEnabled(!Main.main.getActiveDataSet().isReadOnly()); 566 567 final Dimension size = getSize(); 567 568 // Set resizable only in width … … 699 700 700 701 cacheRecentTags(); 701 AutoCompletionManager autocomplete = AutoCompletionManager.of(Main.main.get EditDataSet());702 AutoCompletionManager autocomplete = AutoCompletionManager.of(Main.main.getActiveDataSet()); 702 703 List<AutoCompletionItem> keyList = autocomplete.getTagKeys(DEFAULT_AC_ITEM_COMPARATOR); 703 704 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r12657 r13434 114 114 @Override 115 115 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 116 if (MainApplication.getLayerManager().get EditLayer() != this.layer) return;116 if (MainApplication.getLayerManager().getActiveDataLayer() != this.layer) return; 117 117 // just trigger a repaint 118 118 Collection<RelationMember> sel = getSelectedMembers(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java
r12657 r13434 107 107 @Override 108 108 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 109 if (layer == MainApplication.getLayerManager().get EditLayer()) {109 if (layer == MainApplication.getLayerManager().getActiveDataLayer()) { 110 110 cache.clear(); 111 111 cache.addAll(newSelection); -
trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java
r12951 r13434 416 416 @Override 417 417 public void destroy() { 418 DataSet ds = MainApplication.getLayerManager().get EditDataSet();418 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 419 419 if (ds != null) { 420 420 ds.removeDataSetListener(this); -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java
r13202 r13434 12 12 import org.openstreetmap.josm.Main; 13 13 import org.openstreetmap.josm.data.UserIdentityManager; 14 import org.openstreetmap.josm.data.osm.DataSet; 14 15 import org.openstreetmap.josm.data.osm.Node; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 102 103 103 104 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); 107 108 } 108 109 } … … 169 170 if (history.getNumVersions() > 0) { 170 171 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()); 174 175 if (canShowAsLatest(p)) { 175 176 newLatest = new HistoryPrimitiveBuilder().build(p); … … 530 531 */ 531 532 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); 535 536 } 536 537 MainApplication.getLayerManager().removeActiveLayerChangeListener(this); -
trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
r13130 r13434 22 22 23 23 import org.openstreetmap.josm.actions.AutoScaleAction; 24 import org.openstreetmap.josm.data.osm.DataSet; 24 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; 25 26 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; … … 29 30 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 30 31 import org.openstreetmap.josm.gui.MainApplication; 31 import org.openstreetmap.josm.gui.layer.OsmDataLayer;32 32 import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer; 33 33 import org.openstreetmap.josm.gui.util.GuiHelper; … … 249 249 OsmPrimitive p = getPrimitiveToZoom(); 250 250 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()); 254 254 AutoScaleAction.autoScale("selection"); 255 255 } … … 265 265 if (primitiveId == null) 266 266 return null; 267 OsmDataLayer editLayer = MainApplication.getLayerManager().getEditLayer();268 if ( editLayer== null)267 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 268 if (ds == null) 269 269 return null; 270 return editLayer.data.getPrimitiveById(primitiveId);270 return ds.getPrimitiveById(primitiveId); 271 271 } 272 272 273 273 public void updateEnabledState() { 274 setEnabled(MainApplication.getLayerManager().get EditLayer() != null && getPrimitiveToZoom() != null);274 setEnabled(MainApplication.getLayerManager().getActiveDataSet() != null && getPrimitiveToZoom() != null); 275 275 } 276 276 } -
trunk/src/org/openstreetmap/josm/gui/layer/AbstractModifiableLayer.java
r9751 r13434 2 2 package org.openstreetmap.josm.gui.layer; 3 3 4 import org.openstreetmap.josm.data.osm.ReadOnly; 4 5 import org.openstreetmap.josm.gui.io.AbstractIOTask; 5 6 import org.openstreetmap.josm.gui.io.AbstractUploadDialog; … … 10 11 * @since 7358 11 12 */ 12 public abstract class AbstractModifiableLayer extends Layer implements UploadToServer, SaveToFile {13 public abstract class AbstractModifiableLayer extends Layer implements UploadToServer, SaveToFile, ReadOnly { 13 14 14 15 /** … … 20 21 } 21 22 22 /**23 * Determines if the layer is able to upload data and implements the24 * {@code UploadToServer} interface.25 *26 * @return true if the layer is able to upload data; false, otherwise27 */28 23 @Override 29 24 public boolean isUploadable() { … … 32 27 } 33 28 34 /**35 * Determines if the data managed by this layer needs to be uploaded to36 * the server because it contains modified data.37 *38 * @return true if the data managed by this layer needs to be uploaded to39 * the server because it contains modified data; false, otherwise40 */41 29 @Override 42 30 public boolean requiresUploadToServer() { … … 45 33 } 46 34 47 /**48 * Determines if the data managed by this layer needs to be saved to49 * a file. Only replies true if a file is assigned to this layer and50 * if the data managed by this layer has been modified since the last51 * save operation to the file.52 *53 * @return true if the data managed by this layer needs to be saved to a file54 */55 35 @Override 56 36 public boolean requiresSaveToFile() { … … 59 39 } 60 40 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, otherwise66 */67 41 @Override 68 42 public boolean isUploadDiscouraged() { … … 77 51 public abstract boolean isModified(); 78 52 79 /**80 * Initializes the layer after a successful save of data to a file.81 */82 53 @Override 83 54 public void onPostSaveToFile() { … … 93 64 } 94 65 95 /**96 * Creates a new {@code AbstractIOTask} for uploading data.97 * @param monitor The progress monitor98 * @return a new {@code AbstractIOTask} for uploading data, or {@code null} if not applicable99 */100 66 @Override 101 67 public AbstractIOTask createUploadTask(ProgressMonitor monitor) { … … 104 70 } 105 71 106 /**107 * Returns the upload dialog for this layer.108 * @return the upload dialog for this layer, or {@code null} if not applicable109 */110 72 @Override 111 73 public AbstractUploadDialog getUploadDialog() { … … 113 75 return null; 114 76 } 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 } 115 99 } -
trunk/src/org/openstreetmap/josm/gui/layer/MainLayerManager.java
r13219 r13434 48 48 49 49 /** 50 * This event is fired whenever the active or the editlayer changes.50 * This event is fired whenever the active or the data layer changes. 51 51 * @author Michael Zangl 52 52 */ 53 53 public static class ActiveLayerChangeEvent extends LayerManagerEvent { 54 54 55 private final OsmDataLayer previous EditLayer;55 private final OsmDataLayer previousDataLayer; 56 56 57 57 private final Layer previousActiveLayer; … … 60 60 * Create a new {@link ActiveLayerChangeEvent} 61 61 * @param source The source 62 * @param previous EditLayer the previous editlayer62 * @param previousDataLayer the previous data layer 63 63 * @param previousActiveLayer the previous active layer 64 64 */ 65 ActiveLayerChangeEvent(MainLayerManager source, OsmDataLayer previous EditLayer,65 ActiveLayerChangeEvent(MainLayerManager source, OsmDataLayer previousDataLayer, 66 66 Layer previousActiveLayer) { 67 67 super(source); 68 this.previous EditLayer = previousEditLayer;68 this.previousDataLayer = previousDataLayer; 69 69 this.previousActiveLayer = previousActiveLayer; 70 70 } 71 71 72 72 /** 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 76 78 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; 78 89 } 79 90 … … 88 99 /** 89 100 * 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 92 105 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; 95 117 } else { 96 118 return null; … … 151 173 152 174 /** 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; 156 178 157 179 private final List<ActiveLayerChangeListener> activeLayerChangeListeners = new CopyOnWriteArrayList<>(); … … 214 236 215 237 /** 216 * Set the active layer, unless the layer is read-only.238 * Set the active layer, unless the layer is being uploaded. 217 239 * If the layer is an OsmDataLayer, the edit layer is also changed. 218 240 * @param layer The active layer. … … 221 243 // we force this on to the EDT Thread to make events fire from there. 222 244 // The synchronization lock needs to be held by the EDT. 223 if (layer instanceof OsmDataLayer && ((OsmDataLayer) layer).is ReadOnly()) {245 if (layer instanceof OsmDataLayer && ((OsmDataLayer) layer).isUploadInProgress()) { 224 246 GuiHelper.runInEDT(() -> 225 247 JOptionPane.showMessageDialog( … … 240 262 241 263 private void setActiveLayer(Layer layer, boolean forceEditLayerUpdate) { 242 ActiveLayerChangeEvent event = new ActiveLayerChangeEvent(this, editLayer, activeLayer);264 ActiveLayerChangeEvent event = new ActiveLayerChangeEvent(this, dataLayer, activeLayer); 243 265 activeLayer = layer; 244 266 if (activeLayer instanceof OsmDataLayer) { 245 editLayer = (OsmDataLayer) activeLayer;267 dataLayer = (OsmDataLayer) activeLayer; 246 268 } else if (forceEditLayerUpdate) { 247 editLayer = null;269 dataLayer = null; 248 270 } 249 271 fireActiveLayerChange(event); … … 252 274 private void fireActiveLayerChange(ActiveLayerChangeEvent event) { 253 275 GuiHelper.assertCallFromEdt(); 254 if (event.getPreviousActiveLayer() != activeLayer || event.getPrevious EditLayer() != editLayer) {276 if (event.getPreviousActiveLayer() != activeLayer || event.getPreviousDataLayer() != dataLayer) { 255 277 for (ActiveLayerChangeListener l : activeLayerChangeListeners) { 256 278 l.activeOrEditLayerChanged(event); … … 277 299 @Override 278 300 protected Collection<Layer> realRemoveSingleLayer(Layer layer) { 279 if ((layer instanceof OsmDataLayer) && (((OsmDataLayer) layer).is ReadOnly())) {301 if ((layer instanceof OsmDataLayer) && (((OsmDataLayer) layer).isUploadInProgress())) { 280 302 GuiHelper.runInEDT(() -> JOptionPane.showMessageDialog(MainApplication.parent, 281 303 tr("Trying to delete the layer with background upload. Please wait until the upload is finished."))); … … 285 307 } 286 308 287 if (layer == activeLayer || layer == editLayer) {309 if (layer == activeLayer || layer == dataLayer) { 288 310 Layer nextActive = suggestNextActiveLayer(layer); 289 311 setActiveLayer(nextActive, true); … … 337 359 public synchronized Layer getActiveLayer() { 338 360 if (activeLayer instanceof OsmDataLayer) { 339 if (!((OsmDataLayer) activeLayer).is ReadOnly()) {361 if (!((OsmDataLayer) activeLayer).isUploadInProgress()) { 340 362 return activeLayer; 341 363 } else { … … 351 373 * 352 374 * @return the current edit layer. May be null. 375 * @see #getActiveDataLayer 353 376 */ 354 377 public synchronized OsmDataLayer getEditLayer() { 355 if ( editLayer != null && !editLayer.isReadOnly())356 return editLayer;378 if (dataLayer != null && !dataLayer.isReadOnly()) 379 return dataLayer; 357 380 else 358 381 return null; … … 360 383 361 384 /** 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. 363 400 * @return That data set, <code>null</code> if there is no edit layer. 401 * @see #getActiveDataSet 364 402 */ 365 403 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; 368 420 } else { 369 421 return null; … … 413 465 */ 414 466 public void invalidateEditLayer() { 415 if ( editLayer != null) {416 editLayer.invalidate();467 if (dataLayer != null) { 468 dataLayer.invalidate(); 417 469 } 418 470 } … … 445 497 */ 446 498 public void prepareLayerForUpload(OsmDataLayer layer) { 447 448 499 GuiHelper.assertCallFromEdt(); 500 layer.setUploadInProgress(); 449 501 layer.setReadOnly(); 450 502 451 503 // 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; 455 507 fireActiveLayerChange(activeLayerChangeEvent); 456 508 } … … 467 519 GuiHelper.assertCallFromEdt(); 468 520 layer.unsetReadOnly(); 521 layer.unsetUploadInProgress(); 469 522 470 523 // 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; 474 527 fireActiveLayerChange(layerChangeEvent); 475 528 } -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r13210 r13434 131 131 private boolean requiresSaveToFile; 132 132 private boolean requiresUploadToServer; 133 /** Flag used to know if the layer should not be editable*/134 private final AtomicBoolean is ReadOnly= new AtomicBoolean(false);133 /** Flag used to know if the layer is being uploaded */ 134 private final AtomicBoolean isUploadInProgress = new AtomicBoolean(false); 135 135 136 136 /** … … 425 425 } 426 426 427 if (is ReadOnly()) {428 // If the layer is read onlythen change the default icon to a clock427 if (isUploadInProgress()) { 428 // If the layer is being uploaded then change the default icon to a clock 429 429 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); 430 433 } 431 434 return base.get(); … … 1170 1173 } 1171 1174 1172 /** 1173 * Sets the isReadOnly flag for the OsmDataLayer as true 1174 */ 1175 @Override 1175 1176 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 1184 1181 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 1194 1186 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(); 1196 1205 } 1197 1206 } -
trunk/src/org/openstreetmap/josm/gui/layer/UploadToServer.java
r9751 r13434 40 40 41 41 /** 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 /** 42 50 * Initializes the layer after a successful upload to the server. 43 51 */ -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java
r12636 r13434 67 67 public void updateEnabledState() { 68 68 setEnabled(MainApplication.isDisplayingMapView() 69 && (MainApplication.getLayerManager().get EditLayer() != null || mapHasGpxorMarkerLayer()));69 && (MainApplication.getLayerManager().getActiveDataSet() != null || mapHasGpxorMarkerLayer())); 70 70 } 71 71 -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletionManager.java
r13173 r13434 145 145 * Constructs a new {@code AutoCompletionManager}. 146 146 * @param ds data set 147 * @throws NullPointerException if ds is null 147 148 */ 148 149 public AutoCompletionManager(DataSet ds) { 149 this.ds = ds;150 this.ds = Objects.requireNonNull(ds); 150 151 this.dirty = true; 151 152 } -
trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchPrimitiveDialog.java
r13069 r13434 7 7 import java.awt.event.KeyEvent; 8 8 import java.util.HashSet; 9 import java.util.Set;10 9 11 10 import org.openstreetmap.josm.Main; 12 11 import org.openstreetmap.josm.actions.JosmAction; 13 import org.openstreetmap.josm.data.osm. OsmPrimitive;12 import org.openstreetmap.josm.data.osm.DataSet; 14 13 import org.openstreetmap.josm.gui.ExtendedDialog; 15 14 import org.openstreetmap.josm.gui.MainApplication; … … 44 43 @Override 45 44 public void actionPerformed(ActionEvent e) { 46 if (MainApplication.getLayerManager().get EditLayer() != null) {45 if (MainApplication.getLayerManager().getActiveDataSet() != null) { 47 46 TaggingPresetSearchPrimitiveDialog.getInstance().showDialog(); 48 47 } … … 51 50 @Override 52 51 protected void updateEnabledState() { 53 setEnabled(getLayerManager().get EditLayer() != null);52 setEnabled(getLayerManager().getActiveDataSet() != null); 54 53 } 55 54 } … … 87 86 TaggingPreset preset = selector.getSelectedPresetAndUpdateClassification(); 88 87 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))); 91 90 } 92 91 } -
trunk/src/org/openstreetmap/josm/gui/util/HighlightHelper.java
r12636 r13434 132 132 */ 133 133 public static void clearAllHighlighted() { 134 DataSet ds = MainApplication.getLayerManager().get EditDataSet();134 DataSet ds = MainApplication.getLayerManager().getActiveDataSet(); 135 135 if (ds != null) { 136 136 for (OsmPrimitive p: ds.allNonDeletedPrimitives()) { -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r13196 r13434 141 141 String upload = parser.getAttributeValue(null, "upload"); 142 142 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(); 149 151 } 150 152 String generator = parser.getAttributeValue(null, "generator"); … … 181 183 parseUnknown(); 182 184 } 183 } else if (event == XMLStreamConstants.END_ELEMENT) 185 } else if (event == XMLStreamConstants.END_ELEMENT) { 184 186 return; 187 } 185 188 } 186 189 } … … 618 621 progressMonitor.worked(1); 619 622 623 boolean readOnly = getDataSet().isReadOnly(); 624 620 625 progressMonitor.indeterminateSubTask(tr("Preparing data set...")); 626 if (readOnly) { 627 getDataSet().unsetReadOnly(); 628 } 621 629 prepareDataSet(); 630 if (readOnly) { 631 getDataSet().setReadOnly(); 632 } 622 633 progressMonitor.worked(1); 623 634 … … 628 639 pp.postprocessDataSet(getDataSet(), progressMonitor); 629 640 } 641 } 642 // Make sure postprocessors did not change the read-only state 643 if (readOnly && !getDataSet().isReadOnly()) { 644 getDataSet().setReadOnly(); 630 645 } 631 646 return getDataSet();
Note:
See TracChangeset
for help on using the changeset viewer.