- Timestamp:
- 2009-06-08T21:30:19+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r1640 r1656 119 119 public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection) { 120 120 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.ds); 121 for (OsmPrimitive osm : selection) 121 for (OsmPrimitive osm : selection) { 122 122 osm.visit(v); 123 } 123 124 v.data.addAll(selection); 124 125 if (v.data.isEmpty()) … … 141 142 } 142 143 } 143 if (role.length() > 0) {144 return new ExtendedDialog(Main.parent, 145 tr("Conflicting relation"),146 144 if (role.length() > 0) 145 return new ExtendedDialog(Main.parent, 146 tr("Conflicting relation"), 147 tr("Selection \"{0}\" is used by relation \"{1}\" with role {2}.\nDelete from relation?", 147 148 s.name, n.name, role), 148 new String[] {tr("Delete from relation"), tr("Cancel")},149 new String[] {"dialogs/delete.png", "cancel.png"}).getValue();150 } else {151 return new ExtendedDialog(Main.parent, 152 tr("Conflicting relation"),153 149 new String[] {tr("Delete from relation"), tr("Cancel")}, 150 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 151 else 152 return new ExtendedDialog(Main.parent, 153 tr("Conflicting relation"), 154 tr("Selection \"{0}\" is used by relation \"{1}\".\nDelete from relation?", 154 155 s.name, n.name), 155 new String[] {tr("Delete from relation"), tr("Cancel")}, 156 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 157 } 156 new String[] {tr("Delete from relation"), tr("Cancel")}, 157 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 158 158 } 159 159 … … 210 210 osm.visit(v); 211 211 for (OsmPrimitive ref : v.data) { 212 if (del.contains(ref)) 212 if (del.contains(ref)) { 213 213 continue; 214 } 214 215 if (ref instanceof Way) { 215 216 waysToBeChanged.add((Way) ref); … … 217 218 if (testRelation((Relation) ref, osm) == 1) { 218 219 Collection<OsmPrimitive> relset = relationsToBeChanged.get(ref); 219 if (relset == null) 220 if (relset == null) { 220 221 relset = new HashSet<OsmPrimitive>(); 222 } 221 223 relset.add(osm); 222 224 relationsToBeChanged.put(ref, relset); 223 225 } else 224 226 return null; 225 } else {227 } else 226 228 return null; 227 }228 229 } 229 230 } … … 239 240 w.visit(v); 240 241 for (OsmPrimitive ref : v.data) { 241 if (del.contains(ref)) 242 if (del.contains(ref)) { 242 243 continue; 244 } 243 245 if (ref instanceof Relation) { 244 246 Boolean found = false; 245 247 Collection<OsmPrimitive> relset = relationsToBeChanged.get(ref); 246 if (relset == null) 248 if (relset == null) { 247 249 relset = new HashSet<OsmPrimitive>(); 248 else {250 } else { 249 251 for (OsmPrimitive m : relset) { 250 252 if (m == w) { … … 261 263 return null; 262 264 } 263 } else {265 } else 264 266 return null; 265 }266 267 } 267 268 } else { … … 288 289 } 289 290 290 if (!del.isEmpty()) 291 // #2707: ways to be deleted can include new nodes (with node.id == 0). 292 // Remove them from the way before the way is deleted. Otherwise the 293 // deleted way is saved (or sent to the API) with a dangling reference to a node 294 // Example: 295 // <node id='2' action='delete' visible='true' version='1' ... /> 296 // <node id='1' action='delete' visible='true' version='1' ... /> 297 // <!-- missing node with id -1 because new deleted nodes are not persisted --> 298 // <way id='3' action='delete' visible='true' version='1'> 299 // <nd ref='1' /> 300 // <nd ref='-1' /> <!-- heres the problem --> 301 // <nd ref='2' /> 302 // </way> 303 for (OsmPrimitive primitive : del) { 304 if (! (primitive instanceof Way)) { 305 continue; 306 } 307 Way w = (Way)primitive; 308 if (w.id == 0) { // new ways with id == 0 are fine, 309 continue; // process existing ways only 310 } 311 Way wnew = new Way(w); 312 ArrayList<Node> nodesToStrip = new ArrayList<Node>(); 313 // lookup new nodes which have been added to the set of deleted 314 // nodes ... 315 for (Node n : wnew.nodes) { 316 if (n.id == 0 && del.contains(n)) { 317 nodesToStrip.add(n); 318 } 319 } 320 // .. and remove them from the way 321 // 322 wnew.nodes.removeAll(nodesToStrip); 323 if (!nodesToStrip.isEmpty()) { 324 cmds.add(new ChangeCommand(w,wnew)); 325 } 326 } 327 328 if (!del.isEmpty()) { 291 329 cmds.add(new DeleteCommand(del)); 330 } 292 331 293 332 return new SequenceCommand(tr("Delete"), cmds); … … 300 339 n2.addAll(ws.way.nodes.subList(ws.lowerIndex + 1, ws.way.nodes.size())); 301 340 302 if (n1.size() < 2 && n2.size() < 2) {341 if (n1.size() < 2 && n2.size() < 2) 303 342 return new DeleteCommand(Collections.singleton(ws.way)); 304 }305 343 306 344 Way wnew = new Way(ws.way); … … 343 381 JPanel msg = new JPanel(new GridBagLayout()); 344 382 msg.add(new JLabel( 345 "<html>" +346 // leave message in one tr() as there is a grammatical connection.347 tr("You are about to delete nodes outside of the area you have downloaded." +348 "<br>" +349 "This can cause problems because other objects (that you don't see) might use them." +350 "<br>" +351 "Do you really want to delete?") + "</html>"));383 "<html>" + 384 // leave message in one tr() as there is a grammatical connection. 385 tr("You are about to delete nodes outside of the area you have downloaded." + 386 "<br>" + 387 "This can cause problems because other objects (that you don't see) might use them." + 388 "<br>" + 389 "Do you really want to delete?") + "</html>")); 352 390 return DontShowAgainInfo.show("delete_outside_nodes", msg, false, JOptionPane.YES_NO_OPTION, JOptionPane.YES_OPTION); 353 391 }
Note:
See TracChangeset
for help on using the changeset viewer.