|
Eclipse JDT Release 3.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.ltk.core.refactoring.Change
An abstract base implementation for object representing a generic change
to the workbench. A Change
object is typically created by
calling Refactoring.createChange()
. This class should be
subclassed by clients wishing to provide new changes.
Changes are best executed by using a PerformChangeOperation
. If clients
execute a change directly then the following life cycle has to be honored:
initializeValidationState
has to be called.isValid
can be used to determine if a change
can still be applied to the workspace. If the method returns a RefactoringStatus
with a severity of FATAL then the change has to be
treated as invalid. Performing an invalid change isn't allowed and
results in an unspecified result. This method can be called multiple
times.
dispose
must be called.initializeValidationState
. There is no guarantee
that initializeValidationState
, isValid
or perform
has been called, before dispose
is called.
Change change= createChange(); try { change.initializeValidationState(pm); .... if (!change.isEnabled()) return; RefactoringStatus valid= change.isValid(new SubProgressMonitor(pm, 1)); if (valid.hasFatalError()) return; Change undo= change.perform(new SubProgressMonitor(pm, 1)); if (undo != null) { undo.initializeValidationState(new SubProgressMonitor(pm, 1)); // do something with the undo object } } finally { change.dispose(); }
It is important that implementors of this abstract class provide an adequate
implementation of isValid
and that they provide an undo change
via the return value of the method perform
. If no undo can be
provided then the perform method is allowed to return null
. But
implementors should be aware that not providing an undo object for a change
object that is part of a larger change tree will result in the fact that for
the whole change tree no undo object will be present.
Clients may subclass this class.
Constructor Summary | |
protected |
Change()
Constructs a new change object. |
Method Summary | |
void |
dispose()
Disposes this change. |
Object |
getAdapter(Class adapter)
|
abstract Object |
getModifiedElement()
Returns the element modified by this Change . |
abstract String |
getName()
Returns the human readable name of this change. |
Change |
getParent()
Returns the parent change. |
abstract void |
initializeValidationData(org.eclipse.core.runtime.IProgressMonitor pm)
Hook method to initialize some internal state to provide an adequate answer for the isValid method. |
boolean |
isEnabled()
Returns whether this change is enabled or not. |
abstract RefactoringStatus |
isValid(org.eclipse.core.runtime.IProgressMonitor pm)
Verifies that this change object is still valid and can be executed by calling perform . |
abstract Change |
perform(org.eclipse.core.runtime.IProgressMonitor pm)
Performs this change. |
void |
setEnabled(boolean enabled)
Sets whether this change is enabled or not. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected Change()
Method Detail |
public abstract String getName()
null
.
public boolean isEnabled()
true
if the change is enabled; false
otherwise.public void setEnabled(boolean enabled)
enabled
- true
to enable this change;
false
otherwisepublic Change getParent()
null
if no
parent exists.
public abstract void initializeValidationData(org.eclipse.core.runtime.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.
pm
- a progress monitorpublic abstract RefactoringStatus isValid(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException, org.eclipse.core.runtime.OperationCanceledException
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.
pm
- a progress monitor.
org.eclipse.core.runtime.CoreException
- if an error occurred during validation check. The change
is to be treated as invalid if an exception occurs
org.eclipse.core.runtime.OperationCanceledException
- if the validation check got cancelledpublic abstract Change perform(org.eclipse.core.runtime.IProgressMonitor pm) throws org.eclipse.core.runtime.CoreException
IProgressMonitor.isCanceled()
since canceling a change tree in the
middle of its execution leaves the workspace in a half changed state.
pm
- a progress monitor
null
if no
undo is provided
org.eclipse.core.runtime.CoreException
- if an error occurred during change executionpublic void dispose()
initializeValidationState
.
Subclasses may override this method.
public abstract Object getModifiedElement()
Change
. The method may return
null
if the change isn't related to an element.
public Object getAdapter(Class adapter)
getAdapter
in interface org.eclipse.core.runtime.IAdaptable
|
Eclipse JDT Release 3.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |