Package org.openstreetmap.josm.command
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 tosetDeletionCallback(DeletionCallback)to allow interactive confirmation actions.- Since:
- 23
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classDeleteCommand.DeleteChildCommandstatic interfaceDeleteCommand.DeletionCallbackCalled when a deletion operation must be checked and confirmed by user.-
Nested classes/interfaces inherited from class org.openstreetmap.josm.command.Command
Command.OldNodeState
-
-
Field Summary
Fields Modifier and Type Field Description private static DeleteCommand.DeletionCallbackcallbackprivate java.util.Map<OsmPrimitive,PrimitiveData>clonedPrimitivesprivate java.util.Collection<? extends OsmPrimitive>toDeleteThe primitives that get deleted.-
Fields inherited from class org.openstreetmap.josm.command.Command
IS_INCOMPLETE, IS_OK, IS_OUTSIDE
-
-
Constructor Summary
Constructors Constructor Description DeleteCommand(java.util.Collection<? extends OsmPrimitive> data)Constructor.DeleteCommand(DataSet dataset, java.util.Collection<? extends OsmPrimitive> data)Constructor for a collection of data to be deleted in the context of a specific data setDeleteCommand(DataSet dataset, OsmPrimitive data)Constructor for a single data item.DeleteCommand(OsmPrimitive data)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckConsistency()protected static java.util.Collection<Node>computeNodesToDelete(java.util.Collection<OsmPrimitive> primitivesToDelete)Replies the collection of nodes referred to by primitives inprimitivesToDeletewhich can be deleted too.static Commanddelete(java.util.Collection<? extends OsmPrimitive> selection)Try to delete all given primitives.static Commanddelete(java.util.Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay)Try to delete all given primitives.static Commanddelete(java.util.Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay, boolean silent)Try to delete all given primitives.static CommanddeleteWaySegment(WaySegment ws)Create a command that deletes a single way segment.static CommanddeleteWithReferences(java.util.Collection<? extends OsmPrimitive> selection)Delete the primitives and everything they reference.static CommanddeleteWithReferences(java.util.Collection<? extends OsmPrimitive> selection, boolean silent)Delete the primitives and everything they reference.booleanequals(java.lang.Object obj)booleanexecuteCommand()Executes the command on the dataset.voidfillModifiedData(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.IcongetDescriptionIcon()Provides a descriptive icon of this command.java.lang.StringgetDescriptionText()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()inthashCode()static voidsetDeletionCallback(DeleteCommand.DeletionCallback deletionCallback)Sets the globalDeleteCommand.DeletionCallback.voidundoCommand()Undoes the command.-
Methods inherited from class org.openstreetmap.josm.command.Command
checkOutlyingOrIncompleteOperation, ensurePrimitivesAreInDataset, getAffectedDataSet, getOrig
-
-
-
-
Field Detail
-
callback
private static volatile DeleteCommand.DeletionCallback callback
-
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)
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:
java.lang.IllegalArgumentException- if data is null or empty
-
DeleteCommand
public DeleteCommand(OsmPrimitive data)
Constructor. Deletes a single primitive in the current edit layer.- Parameters:
data- the primitive to delete. Must not be null.- Throws:
java.lang.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:
java.lang.IllegalArgumentException- if data is nulljava.lang.IllegalArgumentException- if layer is null- Since:
- 12718
-
DeleteCommand
public DeleteCommand(DataSet dataset, java.util.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:
java.lang.IllegalArgumentException- if dataset is nulljava.lang.IllegalArgumentException- if data is null or empty- Since:
- 11240
-
-
Method Detail
-
setDeletionCallback
public static void setDeletionCallback(DeleteCommand.DeletionCallback deletionCallback)
Sets the globalDeleteCommand.DeletionCallback.- Parameters:
deletionCallback- the newDeletionCallback. Must not be null- Throws:
java.lang.NullPointerException- ifdeletionCallbackis null- Since:
- 12749
-
checkConsistency
private void checkConsistency()
-
executeCommand
public boolean executeCommand()
Description copied from class:CommandExecutes 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:
executeCommandin classCommand- Returns:
- true
-
undoCommand
public void undoCommand()
Description copied from class:CommandUndoes 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:
undoCommandin classCommand
-
fillModifiedData
public void fillModifiedData(java.util.Collection<OsmPrimitive> modified, java.util.Collection<OsmPrimitive> deleted, java.util.Collection<OsmPrimitive> added)
Description copied from class:CommandFill in the changed data this command operates on. Add to the lists, don't clear them.- Specified by:
fillModifiedDatain classCommand- Parameters:
modified- The modified primitivesdeleted- The deleted primitivesadded- The added primitives
-
getTypesToDelete
private java.util.Set<OsmPrimitiveType> getTypesToDelete()
-
getDescriptionText
public java.lang.String getDescriptionText()
Description copied from interface:PseudoCommandProvides a description text representing this command.- Returns:
- description text representing this command
-
getDescriptionIcon
public javax.swing.Icon getDescriptionIcon()
Description copied from interface:PseudoCommandProvides a descriptive icon of this command.- Returns:
- descriptive icon of this command
-
getChildren
public java.util.Collection<PseudoCommand> getChildren()
Description copied from interface:PseudoCommandReturns the subcommands of this command. Override for subclasses that have child commands.- Returns:
- the subcommands, null if there are no child commands
-
getParticipatingPrimitives
public java.util.Collection<? extends OsmPrimitive> getParticipatingPrimitives()
Description copied from class:CommandReturn the primitives that take part in this command. The collection is computed during execution.- Specified by:
getParticipatingPrimitivesin interfacePseudoCommand- Overrides:
getParticipatingPrimitivesin classCommand- Returns:
- primitives that take part in this command
-
deleteWithReferences
public static Command deleteWithReferences(java.util.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:
java.lang.IllegalArgumentException- if layer is null- Since:
- 12718
-
deleteWithReferences
public static Command deleteWithReferences(java.util.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:
java.lang.IllegalArgumentException- if layer is null- Since:
- 12718
-
delete
public static Command delete(java.util.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 java.util.Collection<Node> computeNodesToDelete(java.util.Collection<OsmPrimitive> primitivesToDelete)
Replies the collection of nodes referred to by primitives inprimitivesToDeletewhich can be deleted too. A node can be deleted if- it is untagged (see
AbstractPrimitive.isTagged() - it is not referred to by other non-deleted primitives outside of
primitivesToDelete
- Parameters:
primitivesToDelete- the primitives to delete- Returns:
- the collection of nodes referred to by primitives in
primitivesToDeletewhich can be deleted too
- it is untagged (see
-
delete
public static Command delete(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:
selection- the objects to delete.alsoDeleteNodesInWay-trueif 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(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:
selection- the objects to delete.alsoDeleteNodesInWay-trueif nodes should be deleted as wellsilent- 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
-
-