Class ResourceChange
- java.lang.Object
-
- org.eclipse.ltk.core.refactoring.Change
-
- org.eclipse.ltk.core.refactoring.resource.ResourceChange
-
- All Implemented Interfaces:
IAdaptable
- Direct Known Subclasses:
DeleteResourceChange
,MoveRenameResourceChange
,MoveResourceChange
,RenameResourceChange
public abstract class ResourceChange extends Change
Abstract change for resource based changes. The change controls the resource time stamp and read only state of the resource and makes sure it is not changed before executing the change.- Since:
- 3.4
-
-
Field Summary
Fields Modifier and Type Field Description static int
SAVE_IF_DIRTY
The 'save if dirty' validation method performs the default validations (seeVALIDATE_DEFAULT
) and will save all unsaved modifications to the resource.static int
VALIDATE_DEFAULT
The default validation method.static int
VALIDATE_NOT_DIRTY
The 'not dirty' validation method performs the default validations (seeVALIDATE_DEFAULT
) and additionally ensures that the element does not contain unsaved modifications.static int
VALIDATE_NOT_READ_ONLY
The 'not read only' validation method performs the default validations (seeVALIDATE_DEFAULT
) and additionally ensures that the element is not read only.
-
Constructor Summary
Constructors Constructor Description ResourceChange()
Creates the resource change.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static void
checkIfModifiable(RefactoringStatus result, IResource resource, int validationMethod)
Utility method to validate a resource to be modified.Object
getModifiedElement()
Returns the element modified by thisChange
.protected abstract IResource
getModifiedResource()
Returns the resource of this change.void
initializeValidationData(IProgressMonitor pm)
Hook method to initialize some internal state to provide an adequate answer for theisValid
method.RefactoringStatus
isValid(IProgressMonitor pm)
This implementation ofChange.isValid(IProgressMonitor)
tests the modified resource using the validation method specified bysetValidationMethod(int)
.void
setValidationMethod(int validationMethod)
Sets the validation methods used when the current resource is validated inisValid(IProgressMonitor)
.String
toString()
-
Methods inherited from class org.eclipse.ltk.core.refactoring.Change
dispose, getAdapter, getAffectedObjects, getDescriptor, getName, getParent, isEnabled, perform, setEnabled, setEnabledShallow
-
-
-
-
Field Detail
-
VALIDATE_DEFAULT
public static final int VALIDATE_DEFAULT
The default validation method. It tests the modified element for existence and makes sure it has not been modified since the change has been created.- See Also:
- Constant Field Values
-
VALIDATE_NOT_READ_ONLY
public static final int VALIDATE_NOT_READ_ONLY
The 'not read only' validation method performs the default validations (seeVALIDATE_DEFAULT
) and additionally ensures that the element is not read only.- See Also:
- Constant Field Values
-
VALIDATE_NOT_DIRTY
public static final int VALIDATE_NOT_DIRTY
The 'not dirty' validation method performs the default validations (seeVALIDATE_DEFAULT
) and additionally ensures that the element does not contain unsaved modifications.- See Also:
- Constant Field Values
-
SAVE_IF_DIRTY
public static final int SAVE_IF_DIRTY
The 'save if dirty' validation method performs the default validations (seeVALIDATE_DEFAULT
) and will save all unsaved modifications to the resource.- See Also:
- Constant Field Values
-
-
Method Detail
-
getModifiedResource
protected abstract IResource getModifiedResource()
Returns the resource of this change.- Returns:
- the resource of this change
-
initializeValidationData
public void initializeValidationData(IProgressMonitor pm)
Description copied from class:Change
Hook method to initialize some internal state to provide an adequate answer for theisValid
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:
- the change hooks up a listener on some delta notification mechanism
and marks itself as invalid if it receives a certain delta. Is this
the case the implementor must take care of unhooking the listener
in
dispose
. - the change remembers some information allowing to decide if a change
object is still valid when
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 whenisValid
is called.- Specified by:
initializeValidationData
in classChange
- Parameters:
pm
- a progress monitor
- the change hooks up a listener on some delta notification mechanism
and marks itself as invalid if it receives a certain delta. Is this
the case the implementor must take care of unhooking the listener
in
-
setValidationMethod
public void setValidationMethod(int validationMethod)
Sets the validation methods used when the current resource is validated inisValid(IProgressMonitor)
.By default the validation method is
VALIDATE_DEFAULT
. Change implementors can addVALIDATE_NOT_DIRTY
,VALIDATE_NOT_READ_ONLY
orSAVE_IF_DIRTY
.- Parameters:
validationMethod
- the validation method used inisValid(IProgressMonitor)
. Supported validation methods currently are: or combinations of these variables.
-
isValid
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException
This implementation ofChange.isValid(IProgressMonitor)
tests the modified resource using the validation method specified bysetValidationMethod(int)
.- Specified by:
isValid
in classChange
- Parameters:
pm
- a progress monitor.- Returns:
- a refactoring status describing the outcome of the validation check
- Throws:
CoreException
- if an error occurred during validation check. The change is to be treated as invalid if an exception occursOperationCanceledException
- if the validation check got canceled
-
checkIfModifiable
protected static void checkIfModifiable(RefactoringStatus result, IResource resource, int validationMethod)
Utility method to validate a resource to be modified.- Parameters:
result
- the status where the result will be added toresource
- the resource to validatevalidationMethod
- the validation method used inisValid(IProgressMonitor)
. Supported validation methods currently are: or combinations of these methods.
-
getModifiedElement
public Object getModifiedElement()
Description copied from class:Change
Returns the element modified by thisChange
. The method may returnnull
if the change isn't related to an element.- Specified by:
getModifiedElement
in classChange
- Returns:
- the element modified by this change
-
-