Class MultiStateTextFileChange
- All Implemented Interfaces:
IAdaptable
text edit trees to a document. The multi state text file change manages the text edit trees.
A multi state text file change offers the ability to access the original content of
the document as well as creating a preview of the change. The edit
trees get copied when creating any kind of preview. Therefore no region
updating on the original edit trees takes place when requesting a preview
(for more information on region updating see class TextEdit.
If region tracking is required for a preview it can be enabled via a call
to the method setKeepPreviewEdits.
If enabled the multi state text file change keeps the copied edit trees executed for the
preview allowing clients to map an original edit to an executed edit. The
executed edit can then be used to determine its position in the preview.
- Since:
- 3.2
-
Constructor Summary
ConstructorsConstructorDescriptionMultiStateTextFileChange(String name, IFile file) Creates a new composite text file change. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddChange(TextChange change) Adds a new text change to this composite change.final voiddispose()Disposes this change.final StringgetCurrentContent(IProgressMonitor monitor) Returns the current content of the document this text change is associated with.final StringgetCurrentContent(IRegion region, boolean expand, int surround, IProgressMonitor monitor) Returns the current content of the text edit change clipped to a specific region.final IDocumentgetCurrentDocument(IProgressMonitor monitor) Returns a document representing the current state of the buffer, prior to the application of the change.final ObjectReturns the element modified by thisChange.final StringgetPreviewContent(IProgressMonitor monitor) Returns the preview content as a string.final StringgetPreviewContent(TextEditBasedChangeGroup[] groups, IRegion region, boolean expand, int surround, IProgressMonitor monitor) Returns a preview of the text edit change clipped to a specific region.final IDocumentgetPreviewDocument(IProgressMonitor monitor) Returns a document representing the preview of the refactored buffer, after the application of the change object.final intReturns the save mode of this change.final voidinitializeValidationData(IProgressMonitor monitor) Hook method to initialize some internal state to provide an adequate answer for theisValidmethod.final RefactoringStatusisValid(IProgressMonitor monitor) Verifies that this change object is still valid and can be executed by callingperform.final booleanDoes the change need saving?final Changeperform(IProgressMonitor monitor) Performs this change.final voidsetKeepPreviewEdits(boolean keep) Controls whether the text edit change should keep executed edits during preview generation.final voidsetSaveMode(int mode) Sets the save mode.Methods inherited from class org.eclipse.ltk.core.refactoring.TextEditBasedChange
addChangeGroup, addTextEditGroup, getChangeGroups, getKeepPreviewEdits, getName, getTextType, hasOneGroupCategory, setEnabled, setTextTypeMethods inherited from class org.eclipse.ltk.core.refactoring.Change
getAdapter, getAffectedObjects, getDescriptor, getParent, isEnabled, setEnabledShallow
-
Constructor Details
-
MultiStateTextFileChange
Creates a new composite text file change.The default text type is
txt.- Parameters:
name- the name of the composite text file changefile- the text file to apply the change to
-
-
Method Details
-
addChange
Adds a new text change to this composite change.The text change which is added is not changed in any way. Rather the contents of the text change are retrieved and stored internally in this composite text change.
- Parameters:
change- the text change to add
-
dispose
public final void dispose()Description copied from class:ChangeDisposes this change. Subclasses that override this method typically unregister listeners which got registered during the call toinitializeValidationData.Subclasses may override this method.
-
getCurrentContent
Description copied from class:TextEditBasedChangeReturns the current content of the document this text change is associated with.- Specified by:
getCurrentContentin classTextEditBasedChange- Parameters:
monitor- a progress monitor to report progress ornullif no progress reporting is desired- Returns:
- the current content of the text edit change
- Throws:
CoreException- if the content can't be accessed
-
getCurrentContent
public final String getCurrentContent(IRegion region, boolean expand, int surround, IProgressMonitor monitor) throws CoreException Description copied from class:TextEditBasedChangeReturns the current content of the text edit change clipped to a specific region. The region is determined as follows:- if
expandRegionToFullLineisfalsethen the parameterregiondetermines the clipping. - if
expandRegionToFullLineistruethen the region determined by the parameterregionis extended to cover full lines. - if
surroundingLines> 0 then the given number of surrounding lines is added. The value ofsurroundingLinesis only considered ifexpandRegionToFullLineistrue
- Specified by:
getCurrentContentin classTextEditBasedChange- Parameters:
region- the starting region for the text to be returnedexpand- iftrueis passed the region is extended to cover full linessurround- the number of surrounding lines to be added to the clipping region. Is only considered ifexpandRegionToFullLineistruemonitor- a progress monitor to report progress ornullif no progress reporting is desired- Returns:
- the current content of the text edit change clipped to a region determined by the given parameters.
- Throws:
CoreException- if an exception occurs while accessing the current content
- if
-
getCurrentDocument
Returns a document representing the current state of the buffer, prior to the application of the change.The returned document should not be modified.
- Parameters:
monitor- the progress monitor to use, ornull- Returns:
- the current document, or the empty document
- Throws:
CoreException- if no document could be acquired
-
getModifiedElement
Description copied from class:ChangeReturns the element modified by thisChange. The method may returnnullif the change isn't related to an element.- Specified by:
getModifiedElementin classChange- Returns:
- the element modified by this change
-
getPreviewContent
public final String getPreviewContent(TextEditBasedChangeGroup[] groups, IRegion region, boolean expand, int surround, IProgressMonitor monitor) throws CoreException Description copied from class:TextEditBasedChangeReturns a preview of the text edit change clipped to a specific region. The preview is created by applying the text edits managed by the given array oftext edit change groups. The region is determined as follows:- if
expandRegionToFullLineisfalsethen the parameterregiondetermines the clipping. - if
expandRegionToFullLineistruethen the region determined by the parameterregionis extended to cover full lines. - if
surroundingLines> 0 then the given number of surrounding lines is added. The value ofsurroundingLinesis only considered ifexpandRegionToFullLineistrue
- Specified by:
getPreviewContentin classTextEditBasedChange- Parameters:
groups- a set of change groups for which a preview is to be generatedregion- the starting region for the clippingexpand- iftrueis passed the region is extended to cover full linessurround- the number of surrounding lines to be added to the clipping region. Is only considered ifexpandRegionToFullLineistruemonitor- a progress monitor to report progress ornullif no progress reporting is desired- Returns:
- the current content of the text change clipped to a region determined by the given parameters.
- Throws:
CoreException- if an exception occurs while generating the preview- See Also:
- if
-
getPreviewContent
Description copied from class:TextEditBasedChangeReturns the preview content as a string.- Specified by:
getPreviewContentin classTextEditBasedChange- Parameters:
monitor- a progress monitor to report progress ornullif no progress reporting is desired- Returns:
- the preview
- Throws:
CoreException- if the preview can't be created
-
getPreviewDocument
Returns a document representing the preview of the refactored buffer, after the application of the change object.- Parameters:
monitor- the progress monitor to use, ornull- Returns:
- the preview document, or an empty document
- Throws:
CoreException- if no document could be acquired
-
getSaveMode
public final int getSaveMode()Returns the save mode of this change.- Returns:
- the save mode
-
initializeValidationData
Description copied from class:ChangeHook method to initialize some internal state to provide an adequate answer for theisValidmethod. 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
isValidis called.
For example, a change object that manipulates the content of an
IFilecould 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 whenisValidis called.- Specified by:
initializeValidationDatain classChange- Parameters:
monitor- 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
-
isValid
public final RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException, OperationCanceledException Description copied from class:ChangeVerifies that this change object is still valid and can be executed by callingperform. If a refactoring status with a severity ofRefactoringStatus.FATALis 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
UndoManagerto decide if an undo or redo change is still valid and therefore can be executed.- Specified by:
isValidin classChange- Parameters:
monitor- 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
-
needsSaving
public final boolean needsSaving()Does the change need saving?- Returns:
trueif it needs saving,falseotherwise
-
perform
Description copied from class:ChangePerforms this change. If this method is called on an invalid or disabled change object the result is unspecified. Changes should in general not respond toIProgressMonitor.isCanceled()since canceling a change tree in the middle of its execution leaves the workspace in a half changed state.- Specified by:
performin classChange- Parameters:
monitor- a progress monitor- Returns:
- the undo change for this change object or
nullif no undo is provided - Throws:
CoreException- if an error occurred during change execution
-
setKeepPreviewEdits
public final void setKeepPreviewEdits(boolean keep) Description copied from class:TextEditBasedChangeControls whether the text edit change should keep executed edits during preview generation.- Overrides:
setKeepPreviewEditsin classTextEditBasedChange- Parameters:
keep- iftrueexecuted preview edits are kept
-
setSaveMode
public final void setSaveMode(int mode) Sets the save mode.- Parameters:
mode- The mode to set
-