public class CompositeUndoUnit extends Object implements IUndoUnit
IUndoUnit
s that are undone/redone as a single unit.
Clients can use this class to build an IUndoUnit
that groups together multiple IUndoUnit
s. The
IUndoUnit
s added to this unit are undone/redone in the order in which they were added. This implementation
will try to merge
or replace
units
that are added
.
Constructor and Description |
---|
CompositeUndoUnit()
Creates a new instance with null names.
|
CompositeUndoUnit(String undoName,
String redoName)
Creates a new instance using the provided names.
|
Modifier and Type | Method and Description |
---|---|
void |
add(IUndoUnit unit)
Adds a new
IUndoUnit to the queue. |
boolean |
canRedo()
Determines whether a call to
redo() can be made. |
boolean |
canUndo()
Determines whether a call to
undo() can be made. |
void |
clear()
Clears the internal collection of units.
|
void |
dispose()
Disposes this unit and all of its contents.
|
String |
getRedoName()
Returns the current redo name.
|
String |
getUndoName()
Returns the current redo name.
|
boolean |
isDisposed()
Determines whether this instance has been
disposed. . |
void |
redo()
Redoes the next
IUndoUnit . |
boolean |
removeUnit(IUndoUnit unit)
Tries to remove a given unit from this compound unit.
|
void |
setRedoName(String value)
Returns the current redo name.
|
void |
setUndoName(String value)
Returns the current redo name.
|
int |
size()
Yields the number of units that are contained in this compound unit.
|
String |
toString() |
boolean |
tryMergeUnit(IUndoUnit unit)
Implements the
IUndoUnit interface. |
boolean |
tryReplaceUnit(IUndoUnit unit)
Implements the
IUndoUnit interface. |
void |
undo()
Undoes the next
IUndoUnit . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
close
public CompositeUndoUnit()
public void add(IUndoUnit unit)
IUndoUnit
to the queue.unit
- The unit of work to add.public boolean canRedo()
redo()
can be made.public boolean canUndo()
undo()
can be made.public void clear()
public final void dispose()
This unit cannot be used anymore after this has been invoked.
dispose
in interface IDisposable
public final String getRedoName()
getRedoName
in interface IUndoUnit
setRedoName(String)
public final String getUndoName()
getUndoName
in interface IUndoUnit
setUndoName(String)
public final boolean isDisposed()
disposed.
.
An instance that has been disposed cannot be undone
or redone
.
public void redo()
IUndoUnit
.redo
in interface IUndoUnit
UnsupportedOperationException
- If an undo operation is already in progress.RuntimeException
- If canRedo()
would yield false
.IUndoUnit.getRedoName()
public boolean removeUnit(IUndoUnit unit)
This method will throw an exception if this unit has been undone or an undo or redo is in progress or this unit has
already been disposed. This method will not automatically Dispose
removed units.
unit
- The unit to remove.true
iff the unit has been removed from this instance.public final void setRedoName(String value)
value
- The RedoName to set.getRedoName()
public final void setUndoName(String value)
value
- The UndoName to set.getUndoName()
public final int size()
public final boolean tryMergeUnit(IUndoUnit unit)
IUndoUnit
interface.
This implementation will always yield false
.
tryMergeUnit
in interface IUndoUnit
unit
- The unit to incorporate that happened after this unit.unit
has been incorporated into this unit and unit
can be disposed of.public final boolean tryReplaceUnit(IUndoUnit unit)
IUndoUnit
interface.
This implementation will always yield false
.
tryReplaceUnit
in interface IUndoUnit
unit
- The unit to incorporate that happened before this unit.this
unit has been incorporated into the given unit
and this
can be
disposed of.public void undo()
IUndoUnit
.undo
in interface IUndoUnit
UnsupportedOperationException
- If an undo operation is already in progress.RuntimeException
- If canUndo()
would yield false
.IUndoUnit.getUndoName()