Changeset 13611 in josm for trunk/src/org
- Timestamp:
- 2018-04-10T19:02:58+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CombineWayAction.java
r13453 r13611 14 14 import java.util.LinkedList; 15 15 import java.util.List; 16 import java.util.Objects; 16 17 import java.util.stream.Collectors; 17 18 … … 28 29 import org.openstreetmap.josm.data.osm.NodeGraph; 29 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 31 import org.openstreetmap.josm.data.osm.OsmUtils; 30 32 import org.openstreetmap.josm.data.osm.TagCollection; 31 33 import org.openstreetmap.josm.data.osm.Way; … … 115 117 return null; 116 118 117 List<DataSet> dataSets = ways.stream().map(Way::getDataSet). distinct().collect(Collectors.toList());119 List<DataSet> dataSets = ways.stream().map(Way::getDataSet).filter(Objects::nonNull).distinct().collect(Collectors.toList()); 118 120 if (dataSets.size() != 1) { 119 121 throw new IllegalArgumentException("Cannot combine ways of multiple data sets."); … … 251 253 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 252 254 int numWays = 0; 253 if ( selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isLocked)) {255 if (OsmUtils.isOsmCollectionEditable(selection)) { 254 256 for (OsmPrimitive osm : selection) { 255 257 if (osm instanceof Way && !osm.isIncomplete() && ++numWays >= 2) { -
trunk/src/org/openstreetmap/josm/actions/JosmAction.java
r13486 r13611 20 20 import org.openstreetmap.josm.data.osm.DataSet; 21 21 import org.openstreetmap.josm.data.osm.OsmPrimitive; 22 import org.openstreetmap.josm.data.osm.OsmUtils; 22 23 import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode; 23 24 import org.openstreetmap.josm.data.osm.event.SelectionEventManager; … … 365 366 */ 366 367 protected final void updateEnabledStateOnModifiableSelection(Collection<? extends OsmPrimitive> selection) { 367 setEnabled(selection != null && !selection.isEmpty() 368 && selection.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isLocked)); 368 setEnabled(OsmUtils.isOsmCollectionEditable(selection)); 369 369 } 370 370 -
trunk/src/org/openstreetmap/josm/actions/MergeNodesAction.java
r13453 r13611 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;31 30 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 32 31 import org.openstreetmap.josm.data.osm.Node; 33 32 import org.openstreetmap.josm.data.osm.OsmPrimitive; 33 import org.openstreetmap.josm.data.osm.OsmUtils; 34 34 import org.openstreetmap.josm.data.osm.TagCollection; 35 35 import org.openstreetmap.josm.data.osm.Way; … … 365 365 @Override 366 366 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 367 if (selection == null || selection.isEmpty() 368 || selection.stream().map(OsmPrimitive::getDataSet).anyMatch(DataSet::isLocked)) { 369 setEnabled(false); 370 return; 371 } 372 boolean ok = true; 373 for (OsmPrimitive osm : selection) { 374 if (!(osm instanceof Node)) { 375 ok = false; 376 break; 367 boolean ok = OsmUtils.isOsmCollectionEditable(selection); 368 if (ok) { 369 for (OsmPrimitive osm : selection) { 370 if (!(osm instanceof Node)) { 371 ok = false; 372 break; 373 } 377 374 } 378 375 } -
trunk/src/org/openstreetmap/josm/actions/MoveNodeAction.java
r13453 r13611 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;14 13 import org.openstreetmap.josm.data.osm.Node; 15 14 import org.openstreetmap.josm.data.osm.OsmPrimitive; 15 import org.openstreetmap.josm.data.osm.OsmUtils; 16 16 import org.openstreetmap.josm.gui.MainApplication; 17 17 import org.openstreetmap.josm.gui.dialogs.LatLonDialog; … … 62 62 @Override 63 63 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 64 if (selection == null || selection.isEmpty() 65 || selection.stream().map(OsmPrimitive::getDataSet).anyMatch(DataSet::isLocked)) { 66 setEnabled(false); 67 return; 68 } 69 if ((selection.size()) == 1 && (selection.toArray()[0] instanceof Node)) { 70 setEnabled(true); 71 } else { 72 setEnabled(false); 73 } 64 setEnabled(OsmUtils.isOsmCollectionEditable(selection) && selection.size() == 1 && selection.toArray()[0] instanceof Node); 74 65 } 75 66 } -
trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java
r13453 r13611 26 26 import org.openstreetmap.josm.Main; 27 27 import org.openstreetmap.josm.command.SplitWayCommand; 28 import org.openstreetmap.josm.data.osm.DataSet;29 28 import org.openstreetmap.josm.data.osm.DefaultNameFormatter; 30 29 import org.openstreetmap.josm.data.osm.Node; 31 30 import org.openstreetmap.josm.data.osm.OsmPrimitive; 31 import org.openstreetmap.josm.data.osm.OsmUtils; 32 32 import org.openstreetmap.josm.data.osm.PrimitiveId; 33 33 import org.openstreetmap.josm.data.osm.Relation; … … 296 296 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 297 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::isLocked) 298 setEnabled(OsmUtils.isOsmCollectionEditable(selection) 300 299 && selection.stream().anyMatch(o -> o instanceof Node && !o.isIncomplete())); 301 300 } -
trunk/src/org/openstreetmap/josm/actions/relation/AddSelectionToRelations.java
r13453 r13611 16 16 import org.openstreetmap.josm.data.osm.DataSet; 17 17 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 import org.openstreetmap.josm.data.osm.OsmUtils; 18 19 import org.openstreetmap.josm.data.osm.Relation; 19 20 import org.openstreetmap.josm.gui.MainApplication; … … 70 71 @Override 71 72 public void selectionChanged(final Collection<? extends OsmPrimitive> newSelection) { 72 GuiHelper.runInEDT(() -> setEnabled(newSelection != null && !newSelection.isEmpty() && !relations.isEmpty()73 && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isLocked)));73 GuiHelper.runInEDT(() -> setEnabled(newSelection != null && !newSelection.isEmpty() 74 && OsmUtils.isOsmCollectionEditable(relations))); 74 75 } 75 76 } -
trunk/src/org/openstreetmap/josm/actions/relation/DeleteRelationsAction.java
r13453 r13611 8 8 9 9 import org.openstreetmap.josm.actions.mapmode.DeleteAction; 10 import org.openstreetmap.josm.data.osm. DataSet;10 import org.openstreetmap.josm.data.osm.OsmUtils; 11 11 import org.openstreetmap.josm.data.osm.Relation; 12 12 import org.openstreetmap.josm.gui.MainApplication; … … 51 51 @Override 52 52 protected void updateEnabledState() { 53 setEnabled( !relations.isEmpty() && relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isLocked));53 setEnabled(OsmUtils.isOsmCollectionEditable(relations)); 54 54 } 55 55 } -
trunk/src/org/openstreetmap/josm/actions/relation/EditRelationAction.java
r13453 r13611 13 13 14 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.data.osm.DataSet;16 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.OsmUtils; 17 17 import org.openstreetmap.josm.data.osm.Relation; 18 18 import org.openstreetmap.josm.data.osm.RelationMember; … … 89 89 protected void updateEnabledState() { 90 90 boolean enabled = false; 91 if ( relations.stream().map(Relation::getDataSet).noneMatch(DataSet::isLocked)) {91 if (OsmUtils.isOsmCollectionEditable(relations)) { 92 92 for (Relation r : relations) { 93 93 if (!r.isDeleted()) { -
trunk/src/org/openstreetmap/josm/data/osm/OsmUtils.java
r12986 r13611 3 3 4 4 import java.util.Arrays; 5 import java.util.Collection; 5 6 import java.util.HashSet; 6 7 import java.util.Locale; 7 8 import java.util.Map; 9 import java.util.Objects; 8 10 import java.util.Set; 9 11 … … 153 155 return layer1; 154 156 } 157 158 /** 159 * Determines if the given collection contains primitives, and that none of them belong to a locked layer. 160 * @param collection collection of OSM primitives 161 * @return {@code true} if the given collection is not empty and does not contain any primitive in a locked layer. 162 * @since 13611 163 */ 164 public static boolean isOsmCollectionEditable(Collection<? extends OsmPrimitive> collection) { 165 return collection != null && !collection.isEmpty() 166 && collection.stream().map(OsmPrimitive::getDataSet).filter(Objects::nonNull).noneMatch(DataSet::isLocked); 167 } 155 168 } -
trunk/src/org/openstreetmap/josm/data/validation/TestError.java
r13489 r13611 12 12 13 13 import org.openstreetmap.josm.command.Command; 14 import org.openstreetmap.josm.data.osm.DataSet;15 14 import org.openstreetmap.josm.data.osm.Node; 16 15 import org.openstreetmap.josm.data.osm.OsmPrimitive; 16 import org.openstreetmap.josm.data.osm.OsmUtils; 17 17 import org.openstreetmap.josm.data.osm.Relation; 18 18 import org.openstreetmap.josm.data.osm.Way; … … 360 360 public boolean isFixable() { 361 361 return (fixingCommand != null || ((tester != null) && tester.isFixable(this))) 362 && primitives.stream().map(OsmPrimitive::getDataSet).noneMatch(DataSet::isLocked);362 && OsmUtils.isOsmCollectionEditable(primitives); 363 363 } 364 364
Note:
See TracChangeset
for help on using the changeset viewer.