Package org.openstreetmap.josm.command
Class DeleteCommand
java.lang.Object
org.openstreetmap.josm.command.Command
org.openstreetmap.josm.command.DeleteCommand
- All Implemented Interfaces:
PseudoCommand
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classstatic interfaceCalled 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
FieldsModifier and TypeFieldDescriptionprivate static DeleteCommand.DeletionCallbackprivate final Map<OsmPrimitive,PrimitiveData> private final Collection<? extends OsmPrimitive>The primitives that get deleted.Fields inherited from class org.openstreetmap.josm.command.Command
IS_INCOMPLETE, IS_OK, IS_OUTSIDE -
Constructor Summary
ConstructorsConstructorDescriptionDeleteCommand(Collection<? extends OsmPrimitive> data) Constructor.DeleteCommand(DataSet dataset, 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
Modifier and TypeMethodDescriptionprivate voidprotected static Collection<Node>computeNodesToDelete(Collection<OsmPrimitive> primitivesToDelete) Replies the collection of nodes referred to by primitives inprimitivesToDeletewhich can be deleted too.static Commanddelete(Collection<? extends OsmPrimitive> selection) Try to delete all given primitives.static Commanddelete(Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay) Try to delete all given primitives.static Commanddelete(Collection<? extends OsmPrimitive> selection, boolean alsoDeleteNodesInWay, boolean silent) Try to delete all given primitives.static CommandCreate a command that deletes a single way segment.static CommanddeleteWithReferences(Collection<? extends OsmPrimitive> selection) Delete the primitives and everything they reference.static CommanddeleteWithReferences(Collection<? extends OsmPrimitive> selection, boolean silent) Delete the primitives and everything they reference.booleanbooleanExecutes the command on the dataset.voidfillModifiedData(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, Collection<OsmPrimitive> added) Fill in the changed data this command operates on.Returns the subcommands of this command.Provides a descriptive icon of this command.Provides a description text representing this command.Collection<? extends OsmPrimitive>Return the primitives that take part in this command.private Set<OsmPrimitiveType>inthashCode()static voidsetDeletionCallback(DeleteCommand.DeletionCallback deletionCallback) Sets the globalDeleteCommand.DeletionCallback.voidUndoes the command.Methods inherited from class org.openstreetmap.josm.command.Command
checkOutlyingOrIncompleteOperation, ensurePrimitivesAreInDataset, getAffectedDataSet, getOrig
-
Field Details
-
callback
-
toDelete
The primitives that get deleted. -
clonedPrimitives
-
-
Constructor Details
-
DeleteCommand
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
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 nullIllegalArgumentException- if layer is null- Since:
- 12718
-
DeleteCommand
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 nullIllegalArgumentException- if data is null or empty- Since:
- 11240
-
-
Method Details
-
setDeletionCallback
Sets the globalDeleteCommand.DeletionCallback.- Parameters:
deletionCallback- the newDeletionCallback. Must not be null- Throws:
NullPointerException- ifdeletionCallbackis null- Since:
- 12749
-
checkConsistency
-
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
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(Collection<OsmPrimitive> modified, Collection<OsmPrimitive> deleted, 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
-
getDescriptionText
Description copied from interface:PseudoCommandProvides a description text representing this command.- Returns:
- description text representing this command
-
getDescriptionIcon
Description copied from interface:PseudoCommandProvides a descriptive icon of this command.- Returns:
- descriptive icon of this command
-
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
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(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
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
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
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(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(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
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
-
equals
-