Ticket #6836: 6836.patch
File 6836.patch, 2.6 KB (added by , 5 years ago) |
---|
-
src/org/openstreetmap/josm/gui/dialogs/PropertiesMembershipChoiceDialog.java
5 5 6 6 import java.awt.GridBagLayout; 7 7 import java.util.Collection; 8 import java.util. Objects;8 import java.util.Collections; 9 9 import java.util.Optional; 10 10 11 11 import javax.swing.AbstractButton; … … 15 15 import javax.swing.JToggleButton; 16 16 17 17 import org.openstreetmap.josm.data.osm.Node; 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; 18 19 import org.openstreetmap.josm.data.osm.Relation; 19 20 import org.openstreetmap.josm.gui.ExtendedDialog; 20 21 import org.openstreetmap.josm.gui.MainApplication; … … 137 138 public static PropertiesMembershipChoiceDialog showIfNecessary(Collection<Node> selectedNodes, boolean preselectNew) 138 139 throws UserCancelException { 139 140 final boolean queryTags = isTagged(selectedNodes); 140 final boolean queryMemberships = is UsedInRelations(selectedNodes);141 final boolean queryMemberships = isMembershipUsableByNew(selectedNodes); 141 142 if (queryTags || queryMemberships) { 142 143 final PropertiesMembershipChoiceDialog dialog = new PropertiesMembershipChoiceDialog(preselectNew, queryTags, queryMemberships); 143 144 dialog.showDialog(); … … 153 154 return existingNodes.stream().anyMatch(Node::hasKeys); 154 155 } 155 156 156 private static boolean isUsedInRelations(final Collection<Node> existingNodes) { 157 return existingNodes.stream().anyMatch( 158 selectedNode -> selectedNode.referrers(Relation.class).anyMatch(Objects::nonNull)); 157 /** 158 * If the node is member of a relation the membership might be wanted on the copy, but that is rarely useful. 159 * @param selectedNodes selected nodes 160 * @return true if it might be useful to copy/move the membership. 161 */ 162 private static boolean isMembershipUsableByNew(final Collection<Node> selectedNodes) { 163 final String[] noCopyRoles = {"via"}; 164 for (Relation r : OsmPrimitive.getParentRelations(selectedNodes)) { 165 if (r.hasTag("type", "restriction", "connectivity")) 166 continue; 167 for (Node n: selectedNodes) { 168 if (r.getMembersFor(Collections.singleton(n)).stream().anyMatch(rm -> !rm.hasRole(noCopyRoles))) 169 return true; 170 } 171 } 172 return false; 159 173 } 160 174 }