Class DeleteCommand

java.lang.Object
org.openstreetmap.josm.command.Command
org.openstreetmap.josm.command.DeleteCommand
All Implemented Interfaces:
PseudoCommand

public class DeleteCommand extends Command
A command to delete a number of primitives from the dataset. To be used correctly, this class requires an initial call to setDeletionCallback(DeletionCallback) to allow interactive confirmation actions.
Since:
23
  • Field Details

  • Constructor Details

    • DeleteCommand

      public DeleteCommand(Collection<? extends OsmPrimitive> data)
      Constructor. Deletes a collection of primitives in the current edit layer.
      Parameters:
      data - the primitives to delete. Must neither be null nor empty, and belong to a data set
      Throws:
      IllegalArgumentException - if data is null or empty
    • DeleteCommand

      Constructor. Deletes a single primitive in the current edit layer.
      Parameters:
      data - the primitive to delete. Must not be null.
      Throws:
      IllegalArgumentException - if data is null
    • DeleteCommand

      public DeleteCommand(DataSet dataset, OsmPrimitive data)
      Constructor for a single data item. Use the collection constructor to delete multiple objects.
      Parameters:
      dataset - the data set context for deleting this primitive. Must not be null.
      data - the primitive to delete. Must not be null.
      Throws:
      IllegalArgumentException - if data is null
      IllegalArgumentException - if layer is null
      Since:
      12718
    • DeleteCommand

      public DeleteCommand(DataSet dataset, Collection<? extends OsmPrimitive> data)
      Constructor for a collection of data to be deleted in the context of a specific data set
      Parameters:
      dataset - the dataset context for deleting these primitives. Must not be null.
      data - the primitives to delete. Must neither be null nor empty.
      Throws:
      IllegalArgumentException - if dataset is null
      IllegalArgumentException - if data is null or empty
      Since:
      11240
  • Method Details

    • setDeletionCallback

      public static void setDeletionCallback(DeleteCommand.DeletionCallback deletionCallback)
      Parameters:
      deletionCallback - the new DeletionCallback. Must not be null
      Throws:
      NullPointerException - if deletionCallback is null
      Since:
      12749
    • checkConsistency

      private void checkConsistency()
    • 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.

      The layer should be invalidated after execution so that it can be re-painted.

      Overrides:
      executeCommand in class Command
      Returns:
      true
    • 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

      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

    • getDescriptionText

      Description copied from interface: PseudoCommand
      Provides a description text representing this command.
      Returns:
      description text representing this command
    • getDescriptionIcon

      Description copied from interface: PseudoCommand
      Provides a descriptive icon of this command.
      Returns:
      descriptive icon of this command
    • getChildren

      Description copied from interface: PseudoCommand
      Returns the subcommands of this command. Override for subclasses that have child commands.
      Returns:
      the subcommands, null if there are no child commands
    • getParticipatingPrimitives

      Description copied from class: Command
      Return the primitives that take part in this command. The collection is computed during execution.
      Specified by:
      getParticipatingPrimitives in interface PseudoCommand
      Overrides:
      getParticipatingPrimitives in class Command
      Returns:
      primitives that take part in this command
    • deleteWithReferences

      public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection, boolean silent)
      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:
      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:
      IllegalArgumentException - if layer is null
      Since:
      12718
    • deleteWithReferences

      public static Command deleteWithReferences(Collection<? extends OsmPrimitive> selection)
      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:
      selection - The list of all object to be deleted.
      Returns:
      command A command to perform the deletions, or null of there is nothing to delete.
      Throws:
      IllegalArgumentException - if layer is null
      Since:
      12718
    • delete

      public static Command delete(Collection<? extends OsmPrimitive> selection)
      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:
      selection - the objects to delete.
      Returns:
      command a command to perform the deletions, or null if there is nothing to delete.
      Since:
      12718
    • computeNodesToDelete

      protected static Collection<Node> computeNodesToDelete(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
      Parameters:
      primitivesToDelete - the primitives to delete
      Returns:
      the collection of nodes referred to by primitives in primitivesToDelete which can be deleted too
    • delete

      public static Command delete(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:
      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.
      Since:
      12718
    • delete

      public static Command delete(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:
      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.
      Since:
      12718
    • deleteWaySegment

      public static Command deleteWaySegment(WaySegment ws)
      Create a command that deletes a single way segment. The way may be split by this.
      Parameters:
      ws - The way segment that should be deleted
      Returns:
      A matching command to safely delete that segment.
      Since:
      12718
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Command
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Command