Changeset 1856 in josm
- Timestamp:
- 2009-07-26T17:03:00+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
r1821 r1856 13 13 import org.openstreetmap.josm.command.Command; 14 14 import org.openstreetmap.josm.command.DeleteCommand; 15 import org.openstreetmap.josm.data.osm.DataSet; 15 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 17 import org.openstreetmap.josm.data.osm.Relation; 16 18 import org.openstreetmap.josm.data.osm.WaySegment; 17 19 import org.openstreetmap.josm.gui.MapFrame; 20 import org.openstreetmap.josm.gui.dialogs.relation.RelationDialogManager; 18 21 import org.openstreetmap.josm.gui.layer.Layer; 19 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 79 82 Command c; 80 83 if (ctrl) { 81 c = DeleteCommand.deleteWithReferences(getCurrentDataSet().getSelected()); 84 c = DeleteCommand.deleteWithReferences(getEditLayer(),getCurrentDataSet().getSelected()); 82 85 } else { 83 c = DeleteCommand.delete(getCurrentDataSet().getSelected(), !alt); 86 c = DeleteCommand.delete(getEditLayer(),getCurrentDataSet().getSelected(), !alt); 84 87 } 85 88 if (c != null) { … … 110 113 if (ws != null) { 111 114 if (shift) { 112 c = DeleteCommand.deleteWaySegment(ws); 115 c = DeleteCommand.deleteWaySegment(getEditLayer(),ws); 113 116 } else if (ctrl) { 114 c = DeleteCommand.deleteWithReferences(Collections.singleton((OsmPrimitive)ws.way)); 117 c = DeleteCommand.deleteWithReferences(getEditLayer(),Collections.singleton((OsmPrimitive)ws.way)); 115 118 } else { 116 c = DeleteCommand.delete(Collections.singleton((OsmPrimitive)ws.way), !alt); 119 c = DeleteCommand.delete(getEditLayer(),Collections.singleton((OsmPrimitive)ws.way), !alt); 117 120 } 118 121 } 119 122 } else if (ctrl) { 120 c = DeleteCommand.deleteWithReferences(Collections.singleton(sel)); 123 c = DeleteCommand.deleteWithReferences(getEditLayer(),Collections.singleton(sel)); 121 124 } else { 122 c = DeleteCommand.delete(Collections.singleton(sel), !alt); 125 c = DeleteCommand.delete(getEditLayer(),Collections.singleton(sel), !alt); 123 126 } 124 127 if (c != null) { … … 142 145 setEnabled(Main.map != null && Main.map.mapView != null && Main.map.mapView.isActiveLayerDrawable()); 143 146 } 147 148 /** 149 * Deletes the relation in the context of the given layer. Also notifies 150 * {@see RelationDialogManager} and {@see OsmDataLayer#fireDataChange()} events. 151 * 152 * @param layer the layer in whose context the relation is deleted. Must not be null. 153 * @param toDelete the relation to be deleted. Must not be null. 154 * @exception IllegalArgumentException thrown if layer is null 155 * @exception IllegalArgumentException thrown if toDelete is nul 156 */ 157 public static void deleteRelation(OsmDataLayer layer, Relation toDelete) { 158 if (layer == null) 159 throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "layer")); 160 if (toDelete == null) 161 throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "toDelete")); 162 if (toDelete == null) 163 return; 164 Command cmd = DeleteCommand.delete(layer, Collections.singleton(toDelete)); 165 if (cmd != null) { 166 // cmd can be null if the user cancels dialogs DialogCommand displays 167 // 168 Main.main.undoRedo.add(cmd); 169 RelationDialogManager.getRelationDialogManager().close(layer, toDelete); 170 layer.fireDataChange(); 171 } 172 } 144 173 } -
trunk/src/org/openstreetmap/josm/command/Command.java
r1814 r1856 53 53 this.layer = Main.map.mapView.getEditLayer(); 54 54 } 55 56 /** 57 * Creates a new command in the context of a specific data layer 58 * 59 * @param layer the data layer 60 */ 61 public Command(OsmDataLayer layer) { 62 this.layer = layer; 63 } 64 55 65 /** 56 66 * Executes the command on the dataset. This implementation will remember all -
trunk/src/org/openstreetmap/josm/command/DeleteCommand.java
r1838 r1856 34 34 import org.openstreetmap.josm.gui.ExtendedDialog; 35 35 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 36 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 36 37 import org.openstreetmap.josm.tools.ImageProvider; 37 38 … … 63 64 } 64 65 65 @Override public boolean executeCommand() { 66 /** 67 * Constructor for a single data item. Use the collection constructor to delete multiple 68 * objects. 69 * 70 * @param layer the layer context for deleting this primitive 71 * @param data the primitive to delete 72 */ 73 public DeleteCommand(OsmDataLayer layer, OsmPrimitive data) { 74 super(layer); 75 this.toDelete = Collections.singleton(data); 76 } 77 78 /** 79 * Constructor for a collection of data to be deleted in the context of 80 * a specific layer 81 * 82 * @param layer the layer context for deleting these primitives 83 * @param data the primitives to delete 84 */ 85 public DeleteCommand(OsmDataLayer layer, Collection<? extends OsmPrimitive> data) { 86 super(layer); 87 this.toDelete = data; 88 } 89 90 @Override 91 public boolean executeCommand() { 66 92 super.executeCommand(); 67 93 for (OsmPrimitive osm : toDelete) { … … 71 97 } 72 98 73 @Override public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 99 @Override 100 public void fillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 74 101 Collection<OsmPrimitive> added) { 75 102 deleted.addAll(toDelete); 76 103 } 77 104 78 @Override public MutableTreeNode description() { 105 @Override 106 public MutableTreeNode description() { 79 107 if (toDelete.size() == 1) { 80 108 OsmPrimitive primitive = toDelete.iterator().next(); 81 return new DefaultMutableTreeNode( 82 new JLabel( 83 tr("Delete {1} {0}", 84 new PrimitiveNameFormatter().getName(primitive), 85 OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular() 86 ), 87 ImageProvider.get(OsmPrimitiveType.from(primitive)), 88 JLabel.HORIZONTAL)); 109 return new DefaultMutableTreeNode(new JLabel(tr("Delete {1} {0}", new PrimitiveNameFormatter() 110 .getName(primitive), OsmPrimitiveType.from(primitive).getLocalizedDisplayNameSingular()), 111 ImageProvider.get(OsmPrimitiveType.from(primitive)), JLabel.HORIZONTAL)); 89 112 } 90 113 … … 106 129 cname, cnamem, toDelete.size())), ImageProvider.get("data", apiname), JLabel.HORIZONTAL)); 107 130 for (OsmPrimitive osm : toDelete) { 108 root.add(new DefaultMutableTreeNode( 109 new JLabel( 110 new PrimitiveNameFormatter().getName(osm), 111 ImageProvider.get(OsmPrimitiveType.from(osm)), 112 JLabel.HORIZONTAL) 113 ) 114 ); 131 root.add(new DefaultMutableTreeNode(new JLabel(new PrimitiveNameFormatter().getName(osm), ImageProvider 132 .get(OsmPrimitiveType.from(osm)), JLabel.HORIZONTAL))); 115 133 } 116 134 return root; … … 119 137 /** 120 138 * Delete the primitives and everything they reference. 121 * 139 * 122 140 * If a node is deleted, the node and all ways and relations the node is part of are deleted as 123 141 * well. 124 * 142 * 125 143 * If a way is deleted, all relations the way is member of are also deleted. 126 * 144 * 127 145 * If a way is deleted, only the way and no nodes are deleted. 128 * 146 * 129 147 * @param selection The list of all object to be deleted. 130 148 * @return command A command to perform the deletions, or null of there is nothing to delete. 131 149 */ 132 public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection) { 133 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor( Main.main.getCurrentDataSet());150 public static Command deleteWithReferences(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) { 151 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data); 134 152 for (OsmPrimitive osm : selection) { 135 153 osm.visit(v); … … 138 156 if (v.data.isEmpty()) 139 157 return null; 140 if (!checkAndConfirmOutlyingDeletes(v.data)) 158 if (!checkAndConfirmOutlyingDeletes(layer,v.data)) 141 159 return null; 142 return new DeleteCommand(v.data); 160 return new DeleteCommand(layer,v.data); 143 161 } 144 162 … … 153 171 } 154 172 if (role.length() > 0) 155 return new ExtendedDialog( 156 Main.parent, 157 tr("Conflicting relation"), 158 tr("Selection \"{0}\" is used by relation \"{1}\" with role {2}.\nDelete from relation?", 159 formatter.getName(osm), formatter.getName(ref), role), 160 new String[] {tr("Delete from relation"), tr("Cancel")}, 161 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 173 return new ExtendedDialog(Main.parent, tr("Conflicting relation"), tr( 174 "Selection \"{0}\" is used by relation \"{1}\" with role {2}.\nDelete from relation?", formatter 175 .getName(osm), formatter.getName(ref), role), new String[] { tr("Delete from relation"), 176 tr("Cancel") }, new String[] { "dialogs/delete.png", "cancel.png" }).getValue(); 162 177 else 163 return new ExtendedDialog(Main.parent, 164 tr("Conflicting relation"), 165 tr("Selection \"{0}\" is used by relation \"{1}\".\nDelete from relation?", 166 formatter.getName(osm), formatter.getName(ref)), 167 new String[] {tr("Delete from relation"), tr("Cancel")}, 168 new String[] {"dialogs/delete.png", "cancel.png"}).getValue(); 169 } 170 171 public static Command delete(Collection<? extends OsmPrimitive> selection) { 172 return delete(selection, true); 178 return new ExtendedDialog(Main.parent, tr("Conflicting relation"), tr( 179 "Selection \"{0}\" is used by relation \"{1}\".\nDelete from relation?", formatter.getName(osm), 180 formatter.getName(ref)), new String[] { tr("Delete from relation"), tr("Cancel") }, new String[] { 181 "dialogs/delete.png", "cancel.png" }).getValue(); 182 } 183 184 public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection) { 185 return delete(layer, selection, true); 186 } 187 188 /** 189 * Replies the collection of nodes referred to by primitives in <code>primitivesToDelete</code> which 190 * can be deleted too. A node can be deleted if 191 * <ul> 192 * <li>it is untagged (see {@see Node#isTagged()}</li> 193 * <li>it is not referred to by other primitives outside of <code>primitivesToDelete</code></li> 194 * <ul> 195 * @param layer the layer in whose context primitives are deleted 196 * @param primitivesToDelete the primitives to delete 197 * @return the collection of nodes referred to by primitives in <code>primitivesToDelete</code> which 198 * can be deleted too 199 */ 200 protected static Collection<Node> computeNodesToDelete(OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) { 201 Collection<Node> nodesToDelete = new HashSet<Node>(); 202 for (OsmPrimitive osm : primitivesToDelete) { 203 if (! (osm instanceof Way) ) { 204 continue; 205 } 206 for (Node n : ((Way) osm).nodes) { 207 if (n.isTagged()) { 208 continue; 209 } 210 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false); 211 n.visit(v); 212 v.data.removeAll(primitivesToDelete); 213 if (v.data.isEmpty()) { 214 nodesToDelete.add(n); 215 } 216 } 217 } 218 return nodesToDelete; 173 219 } 174 220 175 221 /** 176 222 * Try to delete all given primitives. 177 * 223 * 178 224 * If a node is used by a way, it's removed from that way. If a node or a way is used by a 179 225 * relation, inform the user and do not delete. 180 * 226 * 181 227 * If this would cause ways with less than 2 nodes to be created, delete these ways instead. If 182 228 * they are part of a relation, inform the user and do not delete. 183 * 229 * 230 * @param layer the {@see OsmDataLayer} in whose context a primitive the primitives are deleted 184 231 * @param selection The objects to delete. 185 232 * @param alsoDeleteNodesInWay <code>true</code> if nodes should be deleted as well 186 * @return command Acommand to perform the deletions, or nullof there is nothing to delete.187 */ 188 public static Command delete(Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay) { 233 * @return command a command to perform the deletions, or null if there is nothing to delete. 234 */ 235 public static Command delete(OsmDataLayer layer, Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay) { 189 236 if (selection.isEmpty()) 190 237 return null; 191 238 192 Collection<OsmPrimitive> del= new HashSet<OsmPrimitive>(selection);239 Collection<OsmPrimitive> primitivesToDelete = new HashSet<OsmPrimitive>(selection); 193 240 Collection<Way> waysToBeChanged = new HashSet<Way>(); 194 241 HashMap<OsmPrimitive, Collection<OsmPrimitive>> relationsToBeChanged = new HashMap<OsmPrimitive, Collection<OsmPrimitive>>(); 195 242 196 243 if (alsoDeleteNodesInWay) { 197 // Delete untagged nodes that are to be unreferenced. 198 Collection<OsmPrimitive> delNodes = new HashSet<OsmPrimitive>(); 199 for (OsmPrimitive osm : del) { 200 if (osm instanceof Way) { 201 for (Node n : ((Way) osm).nodes) { 202 if (!n.isTagged()) { 203 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(Main.main.getCurrentDataSet(), false); 204 n.visit(v); 205 v.data.removeAll(del); 206 if (v.data.isEmpty()) { 207 delNodes.add(n); 208 } 209 } 210 } 211 } 212 } 213 del.addAll(delNodes); 214 } 215 216 if (!checkAndConfirmOutlyingDeletes(del)) 244 // delete untagged nodes only referenced by primitives in primitivesToDelete, 245 // too 246 Collection<Node> nodesToDelete = computeNodesToDelete(layer, primitivesToDelete); 247 primitivesToDelete.addAll(nodesToDelete); 248 } 249 250 if (!checkAndConfirmOutlyingDeletes(layer,primitivesToDelete)) 217 251 return null; 218 252 219 for (OsmPrimitive osm : del) {220 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor( Main.main.getCurrentDataSet(), false);253 for (OsmPrimitive osm : primitivesToDelete) { 254 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false); 221 255 osm.visit(v); 222 256 for (OsmPrimitive ref : v.data) { 223 if ( del.contains(ref)) {257 if (primitivesToDelete.contains(ref)) { 224 258 continue; 225 259 } … … 244 278 for (Way w : waysToBeChanged) { 245 279 Way wnew = new Way(w); 246 wnew.removeNodes( del);280 wnew.removeNodes(primitivesToDelete); 247 281 if (wnew.nodes.size() < 2) { 248 del.add(w);249 250 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor( Main.main.getCurrentDataSet(), false);282 primitivesToDelete.add(w); 283 284 CollectBackReferencesVisitor v = new CollectBackReferencesVisitor(layer.data, false); 251 285 w.visit(v); 252 286 for (OsmPrimitive ref : v.data) { 253 if ( del.contains(ref)) {287 if (primitivesToDelete.contains(ref)) { 254 288 continue; 255 289 } … … 296 330 // deleted way is saved (or sent to the API) with a dangling reference to a node 297 331 // Example: 298 // 299 // 300 // 301 // 302 // 303 // 304 // 305 // 306 for (OsmPrimitive primitive : del) {307 if (! 332 // <node id='2' action='delete' visible='true' version='1' ... /> 333 // <node id='1' action='delete' visible='true' version='1' ... /> 334 // <!-- missing node with id -1 because new deleted nodes are not persisted --> 335 // <way id='3' action='delete' visible='true' version='1'> 336 // <nd ref='1' /> 337 // <nd ref='-1' /> <!-- heres the problem --> 338 // <nd ref='2' /> 339 // </way> 340 for (OsmPrimitive primitive : primitivesToDelete) { 341 if (!(primitive instanceof Way)) { 308 342 continue; 309 343 } 310 Way w = (Way)primitive; 344 Way w = (Way) primitive; 311 345 if (w.id == 0) { // new ways with id == 0 are fine, 312 continue; 346 continue; // process existing ways only 313 347 } 314 348 Way wnew = new Way(w); … … 317 351 // nodes ... 318 352 for (Node n : wnew.nodes) { 319 if (n.id == 0 && del.contains(n)) {353 if (n.id == 0 && primitivesToDelete.contains(n)) { 320 354 nodesToStrip.add(n); 321 355 } … … 325 359 wnew.nodes.removeAll(nodesToStrip); 326 360 if (!nodesToStrip.isEmpty()) { 327 cmds.add(new ChangeCommand(w,wnew)); 328 } 329 } 330 331 if (! del.isEmpty()) {332 cmds.add(new DeleteCommand( del));361 cmds.add(new ChangeCommand(w, wnew)); 362 } 363 } 364 365 if (!primitivesToDelete.isEmpty()) { 366 cmds.add(new DeleteCommand(layer,primitivesToDelete)); 333 367 } 334 368 … … 336 370 } 337 371 338 public static Command deleteWaySegment(WaySegment ws) { 372 public static Command deleteWaySegment(OsmDataLayer layer, WaySegment ws) { 339 373 List<Node> n1 = new ArrayList<Node>(), n2 = new ArrayList<Node>(); 340 374 … … 343 377 344 378 if (n1.size() < 2 && n2.size() < 2) 345 return new DeleteCommand(Collections.singleton(ws.way)); 379 return new DeleteCommand(layer, Collections.singleton(ws.way)); 346 380 347 381 Way wnew = new Way(ws.way); … … 372 406 373 407 /** 374 * Check whether user is about to delete data outside of the download area. 375 * Request confirmation if he is. 376 */ 377 private static boolean checkAndConfirmOutlyingDeletes(Collection<OsmPrimitive> del) { 378 Area a = Main.main.getCurrentDataSet().getDataSourceArea(); 408 * Check whether user is about to delete data outside of the download area. Request confirmation 409 * if he is. 410 * 411 * @param layer the layer in whose context data is deleted 412 * @param primitivesToDelete the primitives to delete 413 * @return true, if deleting outlying primitives is OK; false, otherwise 414 */ 415 private static boolean checkAndConfirmOutlyingDeletes(OsmDataLayer layer, Collection<OsmPrimitive> primitivesToDelete) { 416 Area a = layer.data.getDataSourceArea(); 379 417 if (a != null) { 380 for (OsmPrimitive osm : del) {418 for (OsmPrimitive osm : primitivesToDelete) { 381 419 if (osm instanceof Node && osm.id != 0) { 382 420 Node n = (Node) osm; … … 385 423 msg.add(new JLabel( 386 424 "<html>" + 387 // leave message in one tr() as there is a grammatical connection.388 tr("You are about to delete nodes outside of the area you have downloaded." +389 "<br>" +390 "This can cause problems because other objects (that you don't see) might use them." +391 "<br>" +392 "Do you really want to delete?") + "</html>")); 425 // leave message in one tr() as there is a grammatical 426 // connection. 427 tr("You are about to delete nodes outside of the area you have downloaded." 428 + "<br>" 429 + "This can cause problems because other objects (that you don't see) might use them." 430 + "<br>" + "Do you really want to delete?") + "</html>")); 393 431 return ConditionalOptionPaneUtil.showConfirmationDialog( 394 432 "delete_outside_nodes", -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r1814 r1856 3 3 4 4 import java.awt.geom.Area; 5 import java.util.ArrayList; 5 6 import java.util.Arrays; 6 7 import java.util.Collection; … … 422 423 } 423 424 424 425 /** 426 * Replies a list of parent relations which refer to the relation 427 * <code>child</code>. Replies an empty list if child is null. 428 * 429 * @param child the child relation 430 * @return a list of parent relations which refer to the relation 431 * <code>child</code> 432 */ 433 public List<Relation> getParentRelations(Relation child) { 434 ArrayList<Relation> parents = new ArrayList<Relation>(); 435 if (child == null) 436 return parents; 437 for (Relation parent : relations) { 438 if (parent == child) { 439 continue; 440 } 441 for (RelationMember member: parent.members) { 442 if (member.refersTo(child)) { 443 parents.add(parent); 444 break; 445 } 446 } 447 } 448 return parents; 449 } 425 450 } -
trunk/src/org/openstreetmap/josm/data/osm/RelationMember.java
r1790 r1856 36 36 } 37 37 38 /** 39 * Replies true, if this relation member refers to the primitive 40 * 41 * @param primitive the primitive to check 42 * @return true, if this relation member refers to the primitive 43 */ 44 public boolean refersTo(OsmPrimitive primitive) { 45 if (primitive == null) return false; 46 if (member == null) return false; 47 return member == primitive; 48 } 49 38 50 @Override 39 51 public int hashCode() { -
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r1811 r1856 65 65 bTexts = buttonTexts; 66 66 setupDialog(lbl, buttonIcons); 67 setAlwaysOnTop(true); 67 68 setVisible(true); 68 69 } … … 195 196 rootPane.getActionMap().put("ESCAPE", actionListener); 196 197 } 198 199 @Override 200 public void setVisible(boolean visible) { 201 super.setVisible(visible); 202 if (visible) { 203 toFront(); 204 } 205 } 197 206 } -
trunk/src/org/openstreetmap/josm/gui/PleaseWaitDialog.java
r1811 r1856 47 47 public void componentShown(ComponentEvent e) {} 48 48 public void componentResized(ComponentEvent ev) { 49 int w = getWidth(); 50 if(w > 200) 51 Main.pref.putInteger("progressdialog.size",w); 49 int w = getWidth(); 50 if(w > 200) { 51 Main.pref.putInteger("progressdialog.size",w); 52 } 52 53 } 53 54 }); 55 // make sure this dialog is always on top of the main JOSM window 56 // and all the other windows (relation editors, detached dialogs, etc.) 57 // 58 setAlwaysOnTop(true); 54 59 } 55 60 … … 84 89 setSize(Main.pref.getInteger("progressdialog.size", 600), 120); 85 90 } 91 92 @Override 93 public void setVisible(boolean visible) { 94 super.setVisible(visible); 95 if (visible) { 96 // make sure this dialog is always on top of the main JOSM window 97 // and all the other windows (relation editors, detached dialogs, etc.) 98 // 99 toFront(); 100 } 101 } 86 102 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java
r1847 r1856 11 11 import java.awt.event.MouseAdapter; 12 12 import java.awt.event.MouseEvent; 13 import java.util.ArrayList; 13 14 import java.util.Collections; 15 import java.util.List; 14 16 15 17 import javax.swing.AbstractAction; 16 18 import javax.swing.DefaultListModel; 17 19 import javax.swing.JList; 20 import javax.swing.JOptionPane; 18 21 import javax.swing.JPanel; 19 22 import javax.swing.JScrollPane; … … 23 26 24 27 import org.openstreetmap.josm.Main; 28 import org.openstreetmap.josm.command.ChangeCommand; 29 import org.openstreetmap.josm.command.Command; 25 30 import org.openstreetmap.josm.command.DeleteCommand; 31 import org.openstreetmap.josm.command.SequenceCommand; 26 32 import org.openstreetmap.josm.data.osm.DataSet; 27 33 import org.openstreetmap.josm.data.osm.OsmPrimitive; 28 34 import org.openstreetmap.josm.data.osm.Relation; 35 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 36 import org.openstreetmap.josm.gui.OptionPaneUtil; 29 37 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 38 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 30 39 import org.openstreetmap.josm.gui.SideButton; 40 import org.openstreetmap.josm.gui.dialogs.relation.ParentRelationLoadingTask; 41 import org.openstreetmap.josm.gui.dialogs.relation.RelationDialogManager; 31 42 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 32 43 import org.openstreetmap.josm.gui.layer.DataChangeListener; … … 34 45 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 35 46 import org.openstreetmap.josm.gui.layer.Layer.LayerChangeListener; 47 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 36 48 import org.openstreetmap.josm.tools.GBC; 37 49 import org.openstreetmap.josm.tools.ImageProvider; 38 50 import org.openstreetmap.josm.tools.Shortcut; 51 52 import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException; 39 53 40 54 /** … … 46 60 */ 47 61 public class RelationListDialog extends ToggleDialog implements LayerChangeListener, DataChangeListener { 62 static private final PrimitiveNameFormatter NAME_FORMATTER = new PrimitiveNameFormatter(); 48 63 49 64 /** … … 270 285 */ 271 286 class DeleteAction extends AbstractAction implements ListSelectionListener, Runnable { 287 class AbortException extends Exception {} 288 272 289 public DeleteAction() { 273 290 putValue(SHORT_DESCRIPTION,tr("Delete the selected relation")); … … 282 299 if (toDelete == null) 283 300 return; 284 Main.main.undoRedo.add( 285 new DeleteCommand(Collections.singleton(toDelete))); 301 org.openstreetmap.josm.actions.mapmode.DeleteAction.deleteRelation( 302 Main.main.getEditLayer(), 303 toDelete 304 ); 286 305 } 287 306 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1855 r1856 24 24 import java.util.Collection; 25 25 import java.util.Collections; 26 import java.util.HashSet;27 26 import java.util.Iterator; 28 27 import java.util.List; … … 33 32 import javax.swing.JButton; 34 33 import javax.swing.JComponent; 35 import javax.swing.JDialog;36 34 import javax.swing.JLabel; 37 35 import javax.swing.JOptionPane; … … 54 52 55 53 import org.openstreetmap.josm.Main; 54 import org.openstreetmap.josm.actions.DeleteAction; 56 55 import org.openstreetmap.josm.command.AddCommand; 57 56 import org.openstreetmap.josm.command.ChangeCommand; … … 492 491 pnl.add(new JButton(moveDownAction), gc); 493 492 493 // -- edit action 494 gc.gridy = 2; 495 EditAction editAction = new EditAction(); 496 memberTableModel.getSelectionModel().addListSelectionListener(editAction); 497 pnl.add(new JButton(editAction),gc); 498 494 499 // ------ 495 gc.gridy = 2;500 gc.gridy = 3; 496 501 RemoveAction removeSelectedAction = new RemoveAction(); 497 502 memberTable.getSelectionModel().addListSelectionListener(removeSelectedAction); … … 499 504 500 505 // ------ 501 gc.gridy = 3;506 gc.gridy = 4; 502 507 SortAction sortAction = new SortAction(); 503 508 pnl.add(new JButton(sortAction), gc); … … 505 510 // ------ 506 511 // just grab the remaining space 507 gc.gridy = 4;512 gc.gridy = 5; 508 513 gc.weighty = 1.0; 509 514 gc.fill = GridBagConstraints.BOTH; … … 578 583 protected JPanel buildButtonPanel() { 579 584 JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); 585 586 // --- download members 580 587 buttonPanel.add(new SideButton(new DownlaodAction())); 588 589 // --- role editing 581 590 buttonPanel.add(new JLabel(tr("Role:"))); 582 591 tfRole = new JTextField(10); … … 596 605 buttonPanel.add(new SideButton(new DuplicateRelationAction())); 597 606 598 // -- edit action 599 EditAction editAction = new EditAction(); 600 memberTableModel.getSelectionModel().addListSelectionListener(editAction); 601 buttonPanel.add(new SideButton(editAction)); 607 // --- delete relation action 608 buttonPanel.add(new SideButton(new DeleteCurrentRelationAction())); 602 609 return buttonPanel; 603 610 } … … 866 873 class RemoveSelectedAction extends AbstractAction implements TableModelListener { 867 874 public RemoveSelectedAction() { 868 putValue(SHORT_DESCRIPTION, tr("Remove all currentlyselectedobjects from relation"));875 putValue(SHORT_DESCRIPTION, tr("Remove all members referring to one of the selected primitives")); 869 876 putValue(SMALL_ICON, ImageProvider.get("dialogs", "removeselected")); 870 877 // putValue(NAME, tr("Remove Selected")); … … 951 958 class RemoveAction extends AbstractAction implements ListSelectionListener { 952 959 public RemoveAction() { 953 putValue(SHORT_DESCRIPTION, tr("Remove the member in thecurrenttable rowfrom this relation"));960 putValue(SHORT_DESCRIPTION, tr("Remove the currently selected members from this relation")); 954 961 putValue(SMALL_ICON, ImageProvider.get("dialogs", "remove")); 955 962 // putValue(NAME, tr("Remove")); … … 965 972 public void valueChanged(ListSelectionEvent e) { 966 973 setEnabled(memberTableModel.canRemove(memberTable.getSelectedRows())); 974 } 975 } 976 977 class DeleteCurrentRelationAction extends AbstractAction { 978 public DeleteCurrentRelationAction() { 979 putValue(SHORT_DESCRIPTION, tr("Delete the currently edited relation")); 980 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 981 putValue(NAME, tr("Delete")); 982 updateEnabledState(); 983 } 984 985 public void run() { 986 Relation toDelete = getRelation(); 987 if (toDelete == null) 988 return; 989 org.openstreetmap.josm.actions.mapmode.DeleteAction.deleteRelation( 990 getLayer(), 991 toDelete 992 ); 993 } 994 995 public void actionPerformed(ActionEvent e) { 996 run(); 997 } 998 999 protected void updateEnabledState() { 1000 setEnabled(getRelation() != null); 967 1001 } 968 1002 } … … 1211 1245 putValue(SHORT_DESCRIPTION, tr("Edit the relation the currently selected relation member refers to")); 1212 1246 putValue(SMALL_ICON, ImageProvider.get("dialogs", "edit")); 1213 putValue(NAME, tr("Edit")); 1247 //putValue(NAME, tr("Edit")); 1214 1248 refreshEnabled(); 1215 1249 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowser.java
r1847 r1856 118 118 public void actionPerformed(ActionEvent e) { 119 119 boolean full = cbReadFull.isSelected(); 120 ReloadTask task = new ReloadTask(full, relationEditor); 120 final ParentRelationLoadingTask task = new ParentRelationLoadingTask( 121 model.getRelation(), 122 getLayer(), 123 full, 124 new PleaseWaitProgressMonitor() 125 ); 126 task.setContinuation( 127 new Runnable() { 128 public void run() { 129 if (task.isCancelled() || task.hasError()) 130 return; 131 model.populate(task.getParents()); 132 } 133 } 134 ); 121 135 Main.worker.submit(task); 122 136 } … … 177 191 } 178 192 } 179 180 /**181 * Asynchronous task for loading the parent relations182 *183 */184 class ReloadTask extends PleaseWaitRunnable {185 private boolean cancelled;186 private Exception lastException;187 private DataSet referrers;188 private boolean full;189 190 public ReloadTask(boolean full, Dialog parent) {191 super(tr("Download referring relations"), new PleaseWaitProgressMonitor(parent), false /* don't ignore exception */);192 referrers = null;193 }194 @Override195 protected void cancel() {196 cancelled = true;197 OsmApi.getOsmApi().cancel();198 }199 200 protected void showLastException() {201 String msg = lastException.getMessage();202 if (msg == null) {203 msg = lastException.toString();204 }205 OptionPaneUtil.showMessageDialog(206 Main.parent,207 msg,208 tr("Error"),209 JOptionPane.ERROR_MESSAGE210 );211 }212 213 @Override214 protected void finish() {215 if (cancelled) return;216 if (lastException != null) {217 showLastException();218 return;219 }220 final ArrayList<Relation> parents = new ArrayList<Relation>();221 for (Relation parent : referrers.relations) {222 parents.add((Relation)getLayer().data.getPrimitiveById(parent.id));223 }224 SwingUtilities.invokeLater(225 new Runnable() {226 public void run() {227 model.populate(parents);228 }229 }230 );231 }232 233 @Override234 protected void realRun() throws SAXException, IOException, OsmTransferException {235 try {236 progressMonitor.indeterminateSubTask(null);237 OsmServerBackreferenceReader reader = new OsmServerBackreferenceReader(model.getRelation(), full);238 referrers = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false));239 if (referrers != null) {240 final MergeVisitor visitor = new MergeVisitor(getLayer().data, referrers);241 visitor.merge();242 243 // copy the merged layer's data source info244 for (DataSource src : referrers.dataSources) {245 getLayer().data.dataSources.add(src);246 }247 // FIXME: this is necessary because there are dialogs listening248 // for DataChangeEvents which manipulate Swing components on this249 // thread.250 //251 SwingUtilities.invokeLater(252 new Runnable() {253 public void run() {254 getLayer().fireDataChange();255 }256 }257 );258 259 if (visitor.getConflicts().isEmpty())260 return;261 getLayer().getConflicts().add(visitor.getConflicts());262 OptionPaneUtil.showMessageDialog(263 Main.parent,264 tr("There were {0} conflicts during import.",265 visitor.getConflicts().size()),266 tr("Warning"),267 JOptionPane.WARNING_MESSAGE268 );269 }270 } catch(Exception e) {271 if (cancelled) {272 System.out.println(tr("Warning: ignoring exception because task is cancelled. Exception: {0}", e.toString()));273 return;274 }275 lastException = e;276 }277 }278 }279 193 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ReferringRelationsBrowserModel.java
r1836 r1856 3 3 4 4 import java.util.ArrayList; 5 import java.util.List; 5 6 6 7 import javax.swing.AbstractListModel; … … 55 56 } 56 57 57 public void populate( ArrayList<Relation> parents) {58 public void populate(List<Relation> parents) { 58 59 referrers.clear(); 59 60 if (parents != null) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationDialogManager.java
r1828 r1856 119 119 openDialogs.put(context, editor); 120 120 editor.addWindowListener(this); 121 } 122 123 /** 124 * Closes the editor open for a specific layer and a specific relation. 125 * 126 * @param layer the layer 127 * @param relation the relation 128 */ 129 public void close(OsmDataLayer layer, Relation relation) { 130 DialogContext context = new DialogContext(layer, relation); 131 RelationEditor editor = openDialogs.get(context); 132 if (editor != null) { 133 editor.setVisible(false); 134 } 121 135 } 122 136
Note:
See TracChangeset
for help on using the changeset viewer.