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
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
Modifier and TypeFieldDescriptionstatic final int
The 'save if dirty' validation method performs the default validations (seeVALIDATE_DEFAULT
) and will save all unsaved modifications to the resource.static final int
The default validation method.static final int
The 'not dirty' validation method performs the default validations (seeVALIDATE_DEFAULT
) and additionally ensures that the element does not contain unsaved modifications.static final int
The 'not read only' validation method performs the default validations (seeVALIDATE_DEFAULT
) and additionally ensures that the element is not read only. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static void
checkIfModifiable
(RefactoringStatus result, IResource resource, int validationMethod) Utility method to validate a resource to be modified.Returns the element modified by thisChange
.protected abstract IResource
Returns the resource of this change.void
Hook method to initialize some internal state to provide an adequate answer for theisValid
method.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)
.toString()
Methods inherited from class org.eclipse.ltk.core.refactoring.Change
dispose, getAdapter, getAffectedObjects, getDescriptor, getName, getParent, isEnabled, perform, setEnabled, setEnabledShallow
-
Field Details
-
VALIDATE_DEFAULT
public static final int VALIDATE_DEFAULTThe 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:
-
VALIDATE_NOT_READ_ONLY
public static final int VALIDATE_NOT_READ_ONLYThe 'not read only' validation method performs the default validations (seeVALIDATE_DEFAULT
) and additionally ensures that the element is not read only.- See Also:
-
VALIDATE_NOT_DIRTY
public static final int VALIDATE_NOT_DIRTYThe 'not dirty' validation method performs the default validations (seeVALIDATE_DEFAULT
) and additionally ensures that the element does not contain unsaved modifications.- See Also:
-
SAVE_IF_DIRTY
public static final int SAVE_IF_DIRTYThe 'save if dirty' validation method performs the default validations (seeVALIDATE_DEFAULT
) and will save all unsaved modifications to the resource.- See Also:
-
-
Constructor Details
-
ResourceChange
public ResourceChange()Creates the resource change. The modification state will be
-
-
Method Details
-
getModifiedResource
Returns the resource of this change.- Returns:
- the resource of this change
-
initializeValidationData
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
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
-
toString
-