org.eclipse.xtext.ui.refactoring.impl
Class DisplayChangeWrapper

java.lang.Object
  extended by org.eclipse.ltk.core.refactoring.Change
      extended by org.eclipse.ltk.core.refactoring.TextEditBasedChange
          extended by org.eclipse.xtext.ui.refactoring.impl.DisplayChangeWrapper
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable

public class DisplayChangeWrapper
extends org.eclipse.ltk.core.refactoring.TextEditBasedChange

Wraps a Change to be performed on the display thread. DocumentChanges are by default not executed on the display thread, causing thread access exceptions and leaving documents opened in editors in an inconsistent state.

Author:
Jan Koehnlein - Initial contribution and API

Constructor Summary
protected DisplayChangeWrapper(org.eclipse.ltk.core.refactoring.Change delegate)
           
  DisplayChangeWrapper(org.eclipse.ltk.core.refactoring.TextEditBasedChange delegate)
           
 
Method Summary
 void addChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup group)
          Adds a text edit change group.
 void addTextEditGroup(org.eclipse.text.edits.TextEditGroup group)
          Adds a text edit group.
 void dispose()
          Disposes this change.
 boolean equals(java.lang.Object obj)
           
 java.lang.Object getAdapter(java.lang.Class adapter)
          Returns an object which is an instance of the given class associated with this object.
 java.lang.Object[] getAffectedObjects()
          Returns the elements affected by this change or null if the affected elements cannot be determined.
 java.lang.String getCurrentContent(org.eclipse.core.runtime.IProgressMonitor pm)
          Returns the current content of the document this text change is associated with.
 java.lang.String getCurrentContent(org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines, org.eclipse.core.runtime.IProgressMonitor pm)
          Returns the current content of the text edit change clipped to a specific region.
 org.eclipse.ltk.core.refactoring.Change getDelegate()
           
 org.eclipse.ltk.core.refactoring.ChangeDescriptor getDescriptor()
          Returns a descriptor of this change.
 boolean getKeepPreviewEdits()
          Returns whether preview edits are remembered for further region tracking or not.
 java.lang.Object getModifiedElement()
          Returns the element modified by this Change.
 java.lang.String getName()
          Returns the human readable name of this change.
 org.eclipse.ltk.core.refactoring.Change getParent()
          Returns the parent change.
 java.lang.String getPreviewContent(org.eclipse.core.runtime.IProgressMonitor pm)
          Returns the preview content as a string.
 java.lang.String getPreviewContent(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup[] changeGroups, org.eclipse.jface.text.IRegion region, boolean expandRegionToFullLine, int surroundingLines, org.eclipse.core.runtime.IProgressMonitor pm)
          Returns a preview of the text edit change clipped to a specific region.
protected  org.eclipse.ltk.core.refactoring.TextEditBasedChange getTextEditBasedChangeDelegate()
           
 java.lang.String getTextType()
          Returns the text edit change's text type.
 int hashCode()
           
 boolean hasOneGroupCategory(java.util.List groupCategories)
          Returns true if the change has one of the given group categories.
 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.
 org.eclipse.ltk.core.refactoring.RefactoringStatus isValid(org.eclipse.core.runtime.IProgressMonitor pm)
          Verifies that this change object is still valid and can be executed by calling perform.
 org.eclipse.ltk.core.refactoring.Change perform(org.eclipse.core.runtime.IProgressMonitor pm)
          Performs this change.
 void setEnabled(boolean enabled)
          Sets whether this change is enabled or not.
 void setKeepPreviewEdits(boolean keep)
          Controls whether the text edit change should keep executed edits during preview generation.
 void setTextType(java.lang.String type)
          Sets the text type.
 java.lang.String toString()
           
 
Methods inherited from class org.eclipse.ltk.core.refactoring.TextEditBasedChange
getChangeGroups
 
Methods inherited from class org.eclipse.ltk.core.refactoring.Change
setEnabledShallow
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DisplayChangeWrapper

public DisplayChangeWrapper(org.eclipse.ltk.core.refactoring.TextEditBasedChange delegate)

DisplayChangeWrapper

protected DisplayChangeWrapper(org.eclipse.ltk.core.refactoring.Change delegate)
Method Detail

getDelegate

public org.eclipse.ltk.core.refactoring.Change getDelegate()

getDescriptor

public org.eclipse.ltk.core.refactoring.ChangeDescriptor getDescriptor()
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Returns a descriptor of this change.

Subclasses of changes created by Refactoring.createChange(IProgressMonitor) should override this method to return a RefactoringChangeDescriptor. A change tree created by a particular refactoring is supposed to contain at most one change which returns a refactoring descriptor. Refactorings usually return an instance of CompositeChange in their Refactoring.createChange(IProgressMonitor) method which implements this method. The refactoring framework searches the change tree top-down until a refactoring descriptor is found.

Overrides:
getDescriptor in class org.eclipse.ltk.core.refactoring.Change
Returns:
a descriptor of this change, or null if this change does not provide a change descriptor.

getName

public java.lang.String getName()
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns the human readable name of this change. The name MUST not be null.

Overrides:
getName in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns:
the human readable name of this change

setEnabled

public void setEnabled(boolean enabled)
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Sets whether this change is enabled or not.

Overrides:
setEnabled in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
enabled - true to enable this change; false otherwise

getParent

public org.eclipse.ltk.core.refactoring.Change getParent()
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Returns the parent change. Returns null if no parent exists.

Overrides:
getParent in class org.eclipse.ltk.core.refactoring.Change
Returns:
the parent change

dispose

public void dispose()
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Disposes this change. Subclasses that override this method typically unregister listeners which got registered during the call to initializeValidationData.

Subclasses may override this method.

Overrides:
dispose in class org.eclipse.ltk.core.refactoring.Change

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

getModifiedElement

public java.lang.Object getModifiedElement()
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Returns the element modified by this Change. The method may return null if the change isn't related to an element.

Specified by:
getModifiedElement in class org.eclipse.ltk.core.refactoring.Change
Returns:
the element modified by this change

getAffectedObjects

public java.lang.Object[] getAffectedObjects()
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Returns the elements affected by this change or null if the affected elements cannot be determined. Returns an empty array if the change doesn't modify any elements.

This default implementation returns null to indicate that the affected elements are unknown. Subclasses should reimplement this method if they can compute the set of affected elements.

Overrides:
getAffectedObjects in class org.eclipse.ltk.core.refactoring.Change
Returns:
the elements affected by this change or null if the affected elements cannot be determined

getAdapter

public java.lang.Object getAdapter(java.lang.Class adapter)
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Returns an object which is an instance of the given class associated with this object. Returns null if no such object can be found.

Specified by:
getAdapter in interface org.eclipse.core.runtime.IAdaptable
Overrides:
getAdapter in class org.eclipse.ltk.core.refactoring.Change
Parameters:
adapter - the adapter class to look up
Returns:
a object castable to the given class, or null if this object does not have an adapter for the given class

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

isEnabled

public boolean isEnabled()
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Returns whether this change is enabled or not. Disabled changes must not be executed.

Overrides:
isEnabled in class org.eclipse.ltk.core.refactoring.Change
Returns:
true if the change is enabled; false otherwise.

initializeValidationData

public void initializeValidationData(org.eclipse.core.runtime.IProgressMonitor pm)
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Hook method to initialize some internal state to provide an adequate answer for the 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:

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.

Specified by:
initializeValidationData in class org.eclipse.ltk.core.refactoring.Change
Parameters:
pm - a progress monitor

isValid

public org.eclipse.ltk.core.refactoring.RefactoringStatus isValid(org.eclipse.core.runtime.IProgressMonitor pm)
                                                           throws org.eclipse.core.runtime.CoreException,
                                                                  org.eclipse.core.runtime.OperationCanceledException
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Verifies that this change object is still valid and can be executed by calling 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.

Specified by:
isValid in class org.eclipse.ltk.core.refactoring.Change
Parameters:
pm - a progress monitor.
Returns:
a refactoring status describing the outcome of the validation check
Throws:
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 canceled

perform

public org.eclipse.ltk.core.refactoring.Change perform(org.eclipse.core.runtime.IProgressMonitor pm)
                                                throws org.eclipse.core.runtime.CoreException
Description copied from class: org.eclipse.ltk.core.refactoring.Change
Performs this change. If this method is called on an invalid or disabled change object the result is unspecified. Changes should in general not respond to IProgressMonitor.isCanceled() since canceling a change tree in the middle of its execution leaves the workspace in a half changed state.

Specified by:
perform in class org.eclipse.ltk.core.refactoring.Change
Parameters:
pm - a progress monitor
Returns:
the undo change for this change object or null if no undo is provided
Throws:
org.eclipse.core.runtime.CoreException - if an error occurred during change execution

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

addChangeGroup

public void addChangeGroup(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup group)
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Adds a text edit change group. The edits managed by the given text edit change group must be part of the change's root edit.

Overrides:
addChangeGroup in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
group - the text edit change group to add

addTextEditGroup

public void addTextEditGroup(org.eclipse.text.edits.TextEditGroup group)
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Adds a text edit group. This method is a convenience method for calling change.addChangeGroup(new TextEditBasedChangeGroup(change, group));.

Overrides:
addTextEditGroup in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
group - the text edit group to add

hasOneGroupCategory

public boolean hasOneGroupCategory(java.util.List groupCategories)
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns true if the change has one of the given group categories. Otherwise false is returned.

Overrides:
hasOneGroupCategory in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
groupCategories - the group categories to check
Returns:
whether the change has one of the given group categories

getCurrentContent

public java.lang.String getCurrentContent(org.eclipse.core.runtime.IProgressMonitor pm)
                                   throws org.eclipse.core.runtime.CoreException
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns the current content of the document this text change is associated with.

Specified by:
getCurrentContent in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
pm - a progress monitor to report progress or null if no progress reporting is desired
Returns:
the current content of the text edit change
Throws:
org.eclipse.core.runtime.CoreException - if the content can't be accessed

getCurrentContent

public java.lang.String getCurrentContent(org.eclipse.jface.text.IRegion region,
                                          boolean expandRegionToFullLine,
                                          int surroundingLines,
                                          org.eclipse.core.runtime.IProgressMonitor pm)
                                   throws org.eclipse.core.runtime.CoreException
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns the current content of the text edit change clipped to a specific region. The region is determined as follows:

Specified by:
getCurrentContent in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
region - the starting region for the text to be returned
expandRegionToFullLine - if true is passed the region is extended to cover full lines
surroundingLines - the number of surrounding lines to be added to the clipping region. Is only considered if expandRegionToFullLine is true
pm - a progress monitor to report progress or null if no progress reporting is desired
Returns:
the current content of the text edit change clipped to a region determined by the given parameters.
Throws:
org.eclipse.core.runtime.CoreException - if an exception occurs while accessing the current content

getKeepPreviewEdits

public boolean getKeepPreviewEdits()
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns whether preview edits are remembered for further region tracking or not.

Overrides:
getKeepPreviewEdits in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns:
true if executed text edits are remembered during preview generation; otherwise false

getPreviewContent

public java.lang.String getPreviewContent(org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup[] changeGroups,
                                          org.eclipse.jface.text.IRegion region,
                                          boolean expandRegionToFullLine,
                                          int surroundingLines,
                                          org.eclipse.core.runtime.IProgressMonitor pm)
                                   throws org.eclipse.core.runtime.CoreException
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns 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 of text edit change groups. The region is determined as follows:

Specified by:
getPreviewContent in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
changeGroups - a set of change groups for which a preview is to be generated
region - the starting region for the clipping
expandRegionToFullLine - if true is passed the region is extended to cover full lines
surroundingLines - the number of surrounding lines to be added to the clipping region. Is only considered if expandRegionToFullLine is true
pm - a progress monitor to report progress or null if no progress reporting is desired
Returns:
the current content of the text change clipped to a region determined by the given parameters.
Throws:
org.eclipse.core.runtime.CoreException - if an exception occurs while generating the preview
See Also:
TextEditBasedChange.getCurrentContent(IRegion, boolean, int, IProgressMonitor)

getPreviewContent

public java.lang.String getPreviewContent(org.eclipse.core.runtime.IProgressMonitor pm)
                                   throws org.eclipse.core.runtime.CoreException
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns the preview content as a string.

Specified by:
getPreviewContent in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
pm - a progress monitor to report progress or null if no progress reporting is desired
Returns:
the preview
Throws:
org.eclipse.core.runtime.CoreException - if the preview can't be created

getTextType

public java.lang.String getTextType()
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns the text edit change's text type.

Overrides:
getTextType in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Returns:
the text edit change's text type

setKeepPreviewEdits

public void setKeepPreviewEdits(boolean keep)
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Controls whether the text edit change should keep executed edits during preview generation.

Overrides:
setKeepPreviewEdits in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
keep - if true executed preview edits are kept

setTextType

public void setTextType(java.lang.String type)
Description copied from class: org.eclipse.ltk.core.refactoring.TextEditBasedChange
Sets the text type. The text type is used to determine the content merge viewer used to present the difference between the original and the preview content in the user interface. Content merge viewers are defined via the extension point org.eclipse.compare.contentMergeViewers.

The default text type is txt.

Overrides:
setTextType in class org.eclipse.ltk.core.refactoring.TextEditBasedChange
Parameters:
type - the text type. If null is passed the text type is reseted to the default text type txt.

getTextEditBasedChangeDelegate

protected org.eclipse.ltk.core.refactoring.TextEditBasedChange getTextEditBasedChangeDelegate()