org.openstreetmap.josm.command
Class DeleteCommand

java.lang.Object
  extended by org.openstreetmap.josm.command.PseudoCommand
      extended by org.openstreetmap.josm.command.Command
          extended by org.openstreetmap.josm.command.DeleteCommand

public class DeleteCommand
extends Command

A command to delete a number of primitives from the dataset.


Field Summary
private  java.util.Map<OsmPrimitive,PrimitiveData> clonedPrimitives
           
private  java.util.Collection<? extends OsmPrimitive> toDelete
          The primitives that get deleted.
 
Constructor Summary
DeleteCommand(java.util.Collection<? extends OsmPrimitive> data)
          Constructor.
DeleteCommand(OsmDataLayer layer, java.util.Collection<? extends OsmPrimitive> data)
          Constructor for a collection of data to be deleted in the context of a specific layer
DeleteCommand(OsmDataLayer layer, OsmPrimitive data)
          Constructor for a single data item.
DeleteCommand(OsmPrimitive data)
          Constructor.
 
Method Summary
static boolean checkAndConfirmOutlyingDelete(java.awt.geom.Area area, java.util.Collection<? extends OsmPrimitive> primitives, java.util.Collection<? extends OsmPrimitive> ignore)
           
static boolean checkAndConfirmOutlyingDelete(OsmDataLayer layer, java.util.Collection<? extends OsmPrimitive> primitives, java.util.Collection<? extends OsmPrimitive> ignore)
           
protected static java.util.Collection<Node> computeNodesToDelete(OsmDataLayer layer, java.util.Collection<OsmPrimitive> primitivesToDelete)
          Replies the collection of nodes referred to by primitives in primitivesToDelete which can be deleted too.
private static boolean confirmRelationDeletion(java.util.Collection<Relation> relations)
           
static Command delete(OsmDataLayer layer, java.util.Collection<? extends OsmPrimitive> selection)
           
static Command delete(OsmDataLayer layer, java.util.Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay)
          Try to delete all given primitives.
static Command delete(OsmDataLayer layer, java.util.Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay, boolean silent)
          Try to delete all given primitives.
static Command deleteWaySegment(OsmDataLayer layer, WaySegment ws)
           
static Command deleteWithReferences(OsmDataLayer layer, java.util.Collection<? extends OsmPrimitive> selection)
           
static Command deleteWithReferences(OsmDataLayer layer, java.util.Collection<? extends OsmPrimitive> selection, boolean silent)
          Delete the primitives and everything they reference.
 boolean executeCommand()
          Executes the command on the dataset.
 void fillModifiedData(java.util.Collection<OsmPrimitive> modified, java.util.Collection<OsmPrimitive> deleted, java.util.Collection<OsmPrimitive> added)
          Fill in the changed data this command operates on.
 java.util.Collection<PseudoCommand> getChildren()
          Returns the subcommands of this command.
 javax.swing.Icon getDescriptionIcon()
          Provides a descriptive icon of this command.
 java.lang.String getDescriptionText()
          Provides a description text representing this command.
 java.util.Collection<? extends OsmPrimitive> getParticipatingPrimitives()
          Return the primitives that take part in this command.
private  java.util.Set<OsmPrimitiveType> getTypesToDelete()
           
 void undoCommand()
          Undoes the command.
 
Methods inherited from class org.openstreetmap.josm.command.Command
checkAndConfirmOutlyingOperation, getLayer, getOrig, invalidBecauselayerRemoved
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toDelete

private final java.util.Collection<? extends OsmPrimitive> toDelete
The primitives that get deleted.


clonedPrimitives

private final java.util.Map<OsmPrimitive,PrimitiveData> clonedPrimitives
Constructor Detail

DeleteCommand

public DeleteCommand(java.util.Collection<? extends OsmPrimitive> data)
              throws java.lang.IllegalArgumentException
Constructor. Deletes a collection of primitives in the current edit layer.

Parameters:
data - the primitives to delete. Must neither be null nor empty.
Throws:
java.lang.IllegalArgumentException - thrown if data is null or empty

DeleteCommand

public DeleteCommand(OsmPrimitive data)
              throws java.lang.IllegalArgumentException
Constructor. Deletes a single primitive in the current edit layer.

Parameters:
data - the primitive to delete. Must not be null.
Throws:
java.lang.IllegalArgumentException - thrown if data is null

DeleteCommand

public DeleteCommand(OsmDataLayer layer,
                     OsmPrimitive data)
              throws java.lang.IllegalArgumentException
Constructor for a single data item. Use the collection constructor to delete multiple objects.

Parameters:
layer - the layer context for deleting this primitive. Must not be null.
data - the primitive to delete. Must not be null.
Throws:
java.lang.IllegalArgumentException - thrown if data is null
java.lang.IllegalArgumentException - thrown if layer is null

DeleteCommand

public DeleteCommand(OsmDataLayer layer,
                     java.util.Collection<? extends OsmPrimitive> data)
              throws java.lang.IllegalArgumentException
Constructor for a collection of data to be deleted in the context of a specific layer

Parameters:
layer - the layer context for deleting these primitives. Must not be null.
data - the primitives to delete. Must neither be null nor empty.
Throws:
java.lang.IllegalArgumentException - thrown if layer is null
java.lang.IllegalArgumentException - thrown if data is null or empty
Method Detail

executeCommand

public boolean executeCommand()
Description copied from class: Command
Executes the command on the dataset. This implementation will remember all primitives returned by fillModifiedData for restoring them on undo.

Overrides:
executeCommand in class Command

undoCommand

public void undoCommand()
Description copied from class: Command
Undoes the command. It can be assumed that all objects are in the same state they were before. It can also be assumed that executeCommand was called exactly once before. This implementation undoes all objects stored by a former call to executeCommand.

Overrides:
undoCommand in class Command

fillModifiedData

public void fillModifiedData(java.util.Collection<OsmPrimitive> modified,
                             java.util.Collection<OsmPrimitive> deleted,
                             java.util.Collection<OsmPrimitive> added)
Description copied from class: Command
Fill in the changed data this command operates on. Add to the lists, don't clear them.

Specified by:
fillModifiedData in class Command
Parameters:
modified - The modified primitives
deleted - The deleted primitives
added - The added primitives

getTypesToDelete

private java.util.Set<OsmPrimitiveType> getTypesToDelete()

getDescriptionText

public java.lang.String getDescriptionText()
Description copied from class: PseudoCommand
Provides a description text representing this command.

Specified by:
getDescriptionText in class PseudoCommand

getDescriptionIcon

public javax.swing.Icon getDescriptionIcon()
Description copied from class: PseudoCommand
Provides a descriptive icon of this command.

Overrides:
getDescriptionIcon in class PseudoCommand

getChildren

public java.util.Collection<PseudoCommand> getChildren()
Description copied from class: PseudoCommand
Returns the subcommands of this command. Override for subclasses that have child commands.

Overrides:
getChildren in class PseudoCommand
Returns:
the subcommands, null if there are no child commands

getParticipatingPrimitives

public java.util.Collection<? extends OsmPrimitive> getParticipatingPrimitives()
Description copied from class: Command
Return the primitives that take part in this command.

Overrides:
getParticipatingPrimitives in class Command

deleteWithReferences

public static Command deleteWithReferences(OsmDataLayer layer,
                                           java.util.Collection<? extends OsmPrimitive> selection,
                                           boolean silent)
                                    throws java.lang.IllegalArgumentException
Delete the primitives and everything they reference. If a node is deleted, the node and all ways and relations the node is part of are deleted as well. If a way is deleted, all relations the way is member of are also deleted. If a way is deleted, only the way and no nodes are deleted.

Parameters:
layer - the OsmDataLayer in whose context primitives are deleted. Must not be null.
selection - The list of all object to be deleted.
silent - Set to true if the user should not be bugged with additional dialogs
Returns:
command A command to perform the deletions, or null of there is nothing to delete.
Throws:
java.lang.IllegalArgumentException - thrown if layer is null

deleteWithReferences

public static Command deleteWithReferences(OsmDataLayer layer,
                                           java.util.Collection<? extends OsmPrimitive> selection)

delete

public static Command delete(OsmDataLayer layer,
                             java.util.Collection<? extends OsmPrimitive> selection)

computeNodesToDelete

protected static java.util.Collection<Node> computeNodesToDelete(OsmDataLayer layer,
                                                                 java.util.Collection<OsmPrimitive> primitivesToDelete)
Replies the collection of nodes referred to by primitives in primitivesToDelete which can be deleted too. A node can be deleted if

delete

public static Command delete(OsmDataLayer layer,
                             java.util.Collection<? extends OsmPrimitive> selection,
                             boolean alsoDeleteNodesInWay)
Try to delete all given primitives. If a node is used by a way, it's removed from that way. If a node or a way is used by a relation, inform the user and do not delete. If this would cause ways with less than 2 nodes to be created, delete these ways instead. If they are part of a relation, inform the user and do not delete.

Parameters:
layer - the OsmDataLayer in whose context the primitives are deleted
selection - the objects to delete.
alsoDeleteNodesInWay - true if nodes should be deleted as well
Returns:
command a command to perform the deletions, or null if there is nothing to delete.

delete

public static Command delete(OsmDataLayer layer,
                             java.util.Collection<? extends OsmPrimitive> selection,
                             boolean alsoDeleteNodesInWay,
                             boolean silent)
Try to delete all given primitives. If a node is used by a way, it's removed from that way. If a node or a way is used by a relation, inform the user and do not delete. If this would cause ways with less than 2 nodes to be created, delete these ways instead. If they are part of a relation, inform the user and do not delete.

Parameters:
layer - the OsmDataLayer in whose context the primitives are deleted
selection - the objects to delete.
alsoDeleteNodesInWay - true if nodes should be deleted as well
silent - set to true if the user should not be bugged with additional questions
Returns:
command a command to perform the deletions, or null if there is nothing to delete.

deleteWaySegment

public static Command deleteWaySegment(OsmDataLayer layer,
                                       WaySegment ws)

checkAndConfirmOutlyingDelete

public static boolean checkAndConfirmOutlyingDelete(OsmDataLayer layer,
                                                    java.util.Collection<? extends OsmPrimitive> primitives,
                                                    java.util.Collection<? extends OsmPrimitive> ignore)

checkAndConfirmOutlyingDelete

public static boolean checkAndConfirmOutlyingDelete(java.awt.geom.Area area,
                                                    java.util.Collection<? extends OsmPrimitive> primitives,
                                                    java.util.Collection<? extends OsmPrimitive> ignore)

confirmRelationDeletion

private static boolean confirmRelationDeletion(java.util.Collection<Relation> relations)


JOSM