public class CompositeChange extends Change
Clients may subclass this class.
Change| Constructor and Description |
|---|
CompositeChange(String name)
Creates a new composite change with the given name.
|
CompositeChange(String name,
Change[] children)
Creates a new composite change with the given name and array
of children.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(Change change)
Adds the given change to the list of children.
|
void |
addAll(Change[] changes)
Adds all changes in the given array to the list of children.
|
Change[] |
clear()
Removes all changes from this composite change.
|
protected Change |
createUndoChange(Change[] childUndos)
Hook to create an undo change.
|
void |
dispose()
Disposes this change.
|
Object[] |
getAffectedObjects()
Returns the elements affected by this change or
null if
the affected elements cannot be determined. |
Change[] |
getChildren()
Returns the children managed by this composite change.
|
ChangeDescriptor |
getDescriptor()
Returns a descriptor of this change.
|
Object |
getModifiedElement()
Returns the element modified by this
Change. |
String |
getName()
Returns the human readable name of this change.
|
Change |
getUndoUntilException()
Returns the undo object containing all undo changes of those children
that got successfully executed while performing this change.
|
void |
initializeValidationData(IProgressMonitor pm)
Hook method to initialize some internal state to provide an adequate answer
for the
isValid method. |
protected boolean |
internalContinueOnCancel()
Note: this is an internal method and should not be overridden outside of
the refactoring framework.
|
protected void |
internalHandleException(Change change,
Throwable t)
Note: this is an internal method and should not be overridden outside of
the refactoring framework.
|
protected boolean |
internalProcessOnCancel(Change change)
Note: this is an internal method and should not be overridden outside of
the refactoring framework.
|
boolean |
isSynthetic()
Returns whether this change is synthetic or not.
|
RefactoringStatus |
isValid(IProgressMonitor pm)
Verifies that this change object is still valid and can be executed by calling
perform. |
void |
markAsSynthetic()
Marks this change as synthetic.
|
void |
merge(CompositeChange change)
Merges the children of the given composite change into this
change.
|
Change |
perform(IProgressMonitor pm)
Performs this change.
|
boolean |
remove(Change change)
Removes the given change from the list of children.
|
void |
setEnabled(boolean enabled)
Sets whether this change is enabled or not.
|
String |
toString() |
getAdapter, getParent, isEnabled, setEnabledShallowpublic CompositeChange(String name)
name - the human readable name of the change. Will
be used to display the change in the user interfacepublic boolean isSynthetic()
trueif this change is synthetic; otherwise
falsepublic void markAsSynthetic()
public String getName()
null.public void add(Change change)
null. Adding a "null" change does nothing.change - the change to addpublic void addAll(Change[] changes)
changes - the changes to addpublic void merge(CompositeChange change)
change - the change to mergepublic boolean remove(Change change)
change - the change to removetrue if the change contained the given
child; otherwise false is returnedpublic Change[] clear()
public Change[] getChildren()
public void setEnabled(boolean enabled)
The composite change sends setEnabled to all its children.
Client are allowed to extend this method.
setEnabled in class Changeenabled - true to enable this change;
false otherwisepublic void initializeValidationData(IProgressMonitor pm)
isValid method. This method gets called after a change
or a whole change tree has been created.
Typically this method is implemented in one of the following ways:
dispose.isValid is called.
For example, a change object that manipulates the content of an IFile
could either listen to resource changes and detect that the file got changed or
it could remember some content stamp and compare it with the actual content stamp
when isValid is called.
The composite change sends initializeValidationData to all its
children.
Client are allowed to extend this method.
initializeValidationData in class Changepm - a progress monitorpublic RefactoringStatus isValid(IProgressMonitor pm) throws CoreException
perform. If a refactoring status with a severity of RefactoringStatus.FATAL is returned then the change has to be treated as invalid
and can no longer be executed. Performing such a change produces an unspecified
result and will very likely throw an exception.
This method is also called by the UndoManager to decide if
an undo or redo change is still valid and therefore can be executed.
The composite change sends isValid to all its children
until the first one returns a status with a severity of FATAL
. If one of the children throws an exception the remaining children
will not receive the isValid call.
Client are allowed to extend this method.
isValid in class Changepm - a progress monitor.CoreException - if an error occurred during validation check. The change
is to be treated as invalid if an exception occurspublic Change perform(IProgressMonitor pm) throws CoreException
IProgressMonitor.isCanceled() since canceling a change tree in the
middle of its execution leaves the workspace in a half changed state.
The composite change sends perform to all its enabled
children. If one of the children throws an exception the remaining children
will not receive the perform call. In this case the method
getUndoUntilException can be used to get an undo object containing the
undo objects of all executed children.
Client are allowed to extend this method.
perform in class Changepm - a progress monitornull if no
undo is providedCoreException - if an error occurred during change executionprotected void internalHandleException(Change change, Throwable t)
The method gets called if one of the changes managed by this composite change generates an exception when performed.
change - the change that caused the exceptiont - the exception itselfprotected boolean internalContinueOnCancel()
The method gets called if one of the changes managed by this composite change generates an operation canceled exception when performed.
true if performing the change should
continue on cancel; otherwise falseprotected boolean internalProcessOnCancel(Change change)
The method gets called if the execution of this change got canceled,
but internalContinueOnCancel returned true.
change - the change to performtrue if the given change should be performed although
the execution got canceled; otherwise falsepublic void dispose()
initializeValidationState.
Subclasses may override this method.
The composite change sends dispose to all its children. It is guaranteed
that all children receive the dispose call.
public Change getUndoUntilException()
null if all changes were executed successfully.
This method is not intended to be overridden or extended.
protected Change createUndoChange(Change[] childUndos)
childUndos - the child undo. The undo edits appear in the
list in the reverse order of their execution. So the first
change in the array is the undo change of the last change
that got executed.public Object[] getAffectedObjects()
null if
the affected elements cannot be determined. Returns an empty array
if the change doesn't modify any elements.
This default implementation returns null to indicate that
the affected elements are unknown. Subclasses should reimplement this method
if they can compute the set of affected elements.
getAffectedObjects in class Changenull if
the affected elements cannot be determinedpublic Object getModifiedElement()
Change. The method may return
null if the change isn't related to an element.getModifiedElement in class Changepublic ChangeDescriptor getDescriptor()
Subclasses of changes created by
Refactoring.createChange(IProgressMonitor) should override this
method to return a RefactoringChangeDescriptor. A change tree
created by a particular refactoring is supposed to contain at most one
change which returns a refactoring descriptor. Refactorings usually
return an instance of CompositeChange in their
Refactoring.createChange(IProgressMonitor) method which
implements this method. The refactoring framework searches the change
tree top-down until a refactoring descriptor is found.
getDescriptor in class Changenull if this
change does not provide a change descriptor.Guidelines for using Eclipse APIs. Copyright (c) IBM Corp. and others 2000, 2006. All rights reserved.