public class MultiStateTextFileChange extends TextEditBasedChange
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.
Constructor and Description |
---|
MultiStateTextFileChange(String name,
IFile file)
Creates a new composite text file change.
|
Modifier and Type | Method and Description |
---|---|
void |
addChange(TextChange change)
Adds a new text change to this composite change.
|
void |
dispose()
Disposes this change.
|
String |
getCurrentContent(IProgressMonitor monitor)
Returns the current content of the document this text
change is associated with.
|
String |
getCurrentContent(IRegion region,
boolean expand,
int surround,
IProgressMonitor monitor)
Returns the current content of the text edit change clipped to a specific
region.
|
IDocument |
getCurrentDocument(IProgressMonitor monitor)
Returns a document representing the current state of the buffer,
prior to the application of the change.
|
Object |
getModifiedElement()
Returns the element modified by this
Change . |
String |
getPreviewContent(IProgressMonitor monitor)
Returns the preview content as a string.
|
String |
getPreviewContent(TextEditBasedChangeGroup[] groups,
IRegion region,
boolean expand,
int surround,
IProgressMonitor monitor)
Returns a preview of the text edit change clipped to a specific region.
|
IDocument |
getPreviewDocument(IProgressMonitor monitor)
Returns a document representing the preview of the refactored buffer,
after the application of the change object.
|
int |
getSaveMode()
Returns the save mode of this change.
|
void |
initializeValidationData(IProgressMonitor monitor)
Hook method to initialize some internal state to provide an adequate answer
for the
isValid method. |
RefactoringStatus |
isValid(IProgressMonitor monitor)
Verifies that this change object is still valid and can be executed by calling
perform . |
boolean |
needsSaving()
Does the change need saving?
|
Change |
perform(IProgressMonitor monitor)
Performs this change.
|
void |
setKeepPreviewEdits(boolean keep)
Controls whether the text edit change should keep executed edits during
preview generation.
|
void |
setSaveMode(int mode)
Sets the save mode.
|
addChangeGroup, addTextEditGroup, getChangeGroups, getKeepPreviewEdits, getName, getTextType, hasOneGroupCategory, setEnabled, setTextType
getAdapter, getAffectedObjects, getDescriptor, getParent, isEnabled, setEnabledShallow
public final void addChange(TextChange 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.
change
- the text change to addpublic final void dispose()
Change
initializeValidationData
.
Subclasses may override this method.
public final String getCurrentContent(IProgressMonitor monitor) throws CoreException
TextEditBasedChange
getCurrentContent
in class TextEditBasedChange
monitor
- a progress monitor to report progress or null
if no progress reporting is desiredCoreException
- if the content can't be accessedpublic final String getCurrentContent(IRegion region, boolean expand, int surround, IProgressMonitor monitor) throws CoreException
TextEditBasedChange
expandRegionToFullLine
is false
then the parameter region
determines the clipping.
expandRegionToFullLine
is true
then the region determined by the parameter region
is extended to cover full lines.
surroundingLines
> 0 then the given number
of surrounding lines is added. The value of surroundingLines
is only considered if expandRegionToFullLine
is true
getCurrentContent
in class TextEditBasedChange
region
- the starting region for the text to be returnedexpand
- if true
is passed the region
is extended to cover full linessurround
- the number of surrounding lines to be added to
the clipping region. Is only considered if expandRegionToFullLine
is true
monitor
- a progress monitor to report progress or null
if no progress reporting is desiredCoreException
- if an exception occurs while accessing the current contentpublic final IDocument getCurrentDocument(IProgressMonitor monitor) throws CoreException
The returned document should not be modified.
monitor
- the progress monitor to use, or null
CoreException
- if no document could be acquiredpublic final Object getModifiedElement()
Change
Change
. The method may return
null
if the change isn't related to an element.getModifiedElement
in class Change
public final String getPreviewContent(TextEditBasedChangeGroup[] groups, IRegion region, boolean expand, int surround, IProgressMonitor monitor) throws CoreException
TextEditBasedChange
text edit change groups
.
The region is determined as follows:
expandRegionToFullLine
is false
then the parameter region
determines the clipping.
expandRegionToFullLine
is true
then the region determined by the parameter region
is extended to cover full lines.
surroundingLines
> 0 then the given number
of surrounding lines is added. The value of surroundingLines
is only considered if expandRegionToFullLine
is true
getPreviewContent
in class TextEditBasedChange
groups
- a set of change groups for which a preview is to be
generatedregion
- the starting region for the clippingexpand
- if true
is passed the region
is extended to cover full linessurround
- the number of surrounding lines to be added to
the clipping region. Is only considered if expandRegionToFullLine
is true
monitor
- a progress monitor to report progress or null
if no progress reporting is desiredCoreException
- if an exception occurs while generating the previewTextEditBasedChange.getCurrentContent(IRegion, boolean, int, IProgressMonitor)
public final String getPreviewContent(IProgressMonitor monitor) throws CoreException
TextEditBasedChange
getPreviewContent
in class TextEditBasedChange
monitor
- a progress monitor to report progress or null
if no progress reporting is desiredCoreException
- if the preview can't be createdpublic final IDocument getPreviewDocument(IProgressMonitor monitor) throws CoreException
monitor
- the progress monitor to use, or null
CoreException
- if no document could be acquiredpublic final int getSaveMode()
public final void initializeValidationData(IProgressMonitor monitor)
Change
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.
initializeValidationData
in class Change
monitor
- a progress monitorpublic final RefactoringStatus isValid(IProgressMonitor monitor) throws CoreException, OperationCanceledException
Change
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.
isValid
in class Change
monitor
- a progress monitor.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 canceledpublic final boolean needsSaving()
true
if it needs saving, false
otherwisepublic final Change perform(IProgressMonitor monitor) throws CoreException
Change
IProgressMonitor.isCanceled()
since canceling a change tree in the
middle of its execution leaves the workspace in a half changed state.perform
in class Change
monitor
- a progress monitornull
if no
undo is providedCoreException
- if an error occurred during change executionpublic final void setKeepPreviewEdits(boolean keep)
TextEditBasedChange
setKeepPreviewEdits
in class TextEditBasedChange
keep
- if true
executed preview edits are keptpublic final void setSaveMode(int mode)
mode
- The mode to set
Copyright (c) 2000, 2017 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.