Changeset 15137 in josm
- Timestamp:
- 2019-05-29T09:21:54+02:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CreateMultipolygonAction.java
r14654 r15137 179 179 } 180 180 181 private Relation getSelectedMultipolygonRelation() {182 DataSet ds = getLayerManager().getEditDataSet();183 return getSelectedMultipolygonRelation(ds.getSelectedWays(), ds.getSelectedRelations());184 }185 186 181 private static Relation getSelectedMultipolygonRelation(Collection<Way> selectedWays, Collection<Relation> selectedRelations) { 187 if (selectedRelations.size() == 1 && "multipolygon".equals(selectedRelations.iterator().next().get("type"))) { 188 return selectedRelations.iterator().next(); 189 } else { 190 final Set<Relation> relatedRelations = new HashSet<>(); 182 Relation candidate = null; 183 if (selectedRelations.size() == 1) { 184 candidate = selectedRelations.iterator().next(); 185 if (!candidate.hasTag("type", "multipolygon")) 186 candidate = null; 187 } else if (!selectedWays.isEmpty()) { 191 188 for (final Way w : selectedWays) { 192 w.referrers(Relation.class).forEach(relatedRelations::add); 193 } 194 return relatedRelations.size() == 1 ? relatedRelations.iterator().next() : null; 195 } 189 for (OsmPrimitive r : w.getReferrers()) { 190 if (r != candidate && r instanceof Relation && r.hasTag("type", "multipolygon")) { 191 if (candidate != null) 192 return null; // found another multipolygon relation 193 candidate = (Relation) r; 194 } 195 } 196 } 197 } 198 return candidate; 196 199 } 197 200 … … 271 274 * Enable this action only if something is selected 272 275 * 273 * @param selection the current selection, gets tested for empt yness276 * @param selection the current selection, gets tested for emptiness 274 277 */ 275 278 @Override 276 279 protected void updateEnabledState(Collection<? extends OsmPrimitive> selection) { 277 280 DataSet ds = getLayerManager().getEditDataSet(); 278 if (ds == null ) {281 if (ds == null || selection.isEmpty()) { 279 282 setEnabled(false); 280 283 } else if (update) { 281 setEnabled(getSelectedMultipolygonRelation( ) != null);284 setEnabled(getSelectedMultipolygonRelation(ds.getSelectedWays(), ds.getSelectedRelations()) != null); 282 285 } else { 283 setEnabled(! getLayerManager().getEditDataSet().getSelectedWays().isEmpty());286 setEnabled(!ds.getSelectedWays().isEmpty()); 284 287 } 285 288 }
Note:
See TracChangeset
for help on using the changeset viewer.