Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 


Eclipse Platform
Release 3.5

org.eclipse.ltk.core.refactoring
Class MultiStateTextFileChange


java.lang.Object
  extended by 

org.eclipse.ltk.core.refactoring.Change
      extended by 

org.eclipse.ltk.core.refactoring.TextEditBasedChange
          extended by 
org.eclipse.ltk.core.refactoring.MultiStateTextFileChange
All Implemented Interfaces:
IAdaptable

public class MultiStateTextFileChange
extends TextEditBasedChange

A multi state text file change is a special change object that applies a sequence of 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
MultiStateTextFileChange ( String name, IFile file)
          Creates a new composite text file change.
 
Method Summary
 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.
 
Methods inherited from class org.eclipse.ltk.core.refactoring. TextEditBasedChange
addChangeGroup, addTextEditGroup, getChangeGroups, getKeepPreviewEdits, getName, getTextType, hasOneGroupCategory, setEnabled, setTextType
 
Methods inherited from class org.eclipse.ltk.core.refactoring. Change
getAdapter, getAffectedObjects, getDescriptor, getParent, isEnabled, setEnabledShallow
 
Methods inherited from class java.lang. Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiStateTextFileChange

public MultiStateTextFileChange(
String name,
                                
IFile file)
Creates a new composite text file change.

The default text type is txt.

Parameters:
name - the name of the composite text file change
file - the text file to apply the change to
Method Detail

addChange

public final void addChange(
TextChange change)
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: Change
Disposes this change. Subclasses that override this method typically unregister listeners which got registered during the call to initializeValidationState.

Subclasses may override this method.

Overrides:
dispose in class Change

getCurrentContent

public final 
String getCurrentContent(
IProgressMonitor monitor)
                               throws 
CoreException
Description copied from class: TextEditBasedChange
Returns the current content of the document this text change is associated with.

Specified by:
getCurrentContent in class TextEditBasedChange
Parameters:
monitor - a progress monitor to report progress or null if 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: TextEditBasedChange
Returns the current content of the text edit change clipped to a specific region. The region is determined as follows:
  • if expandRegionToFullLine is false then the parameter region determines the clipping.
  • if expandRegionToFullLine is true then the region determined by the parameter region is extended to cover full lines.
  • if surroundingLines > 0 then the given number of surrounding lines is added. The value of surroundingLines is only considered if expandRegionToFullLine is true

Specified by:
getCurrentContent in class TextEditBasedChange
Parameters:
region - the starting region for the text to be returned
expand - if true is passed the region is extended to cover full lines
surround - 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 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

getCurrentDocument

public final 
IDocument getCurrentDocument(
IProgressMonitor monitor)
                                   throws 
CoreException
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, or null
Returns:
the current document, or the empty document
Throws:
CoreException - if no document could be acquired

getModifiedElement

public final 
Object getModifiedElement()
Description copied from class: 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 Change
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: 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:
  • if expandRegionToFullLine is false then the parameter region determines the clipping.
  • if expandRegionToFullLine is true then the region determined by the parameter region is extended to cover full lines.
  • if surroundingLines > 0 then the given number of surrounding lines is added. The value of surroundingLines is only considered if expandRegionToFullLine is true

Specified by:
getPreviewContent in class TextEditBasedChange
Parameters:
groups - a set of change groups for which a preview is to be generated
region - the starting region for the clipping
expand - if true is passed the region is extended to cover full lines
surround - 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 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:
TextEditBasedChange.getCurrentContent(IRegion, boolean, int, IProgressMonitor)

getPreviewContent

public final 
String getPreviewContent(
IProgressMonitor monitor)
                               throws 
CoreException
Description copied from class: TextEditBasedChange
Returns the preview content as a string.

Specified by:
getPreviewContent in class TextEditBasedChange
Parameters:
monitor - a progress monitor to report progress or null if no progress reporting is desired
Returns:
the preview
Throws:
CoreException - if the preview can't be created

getPreviewDocument

public final 
IDocument getPreviewDocument(
IProgressMonitor monitor)
                                   throws 
CoreException
Returns a document representing the preview of the refactored buffer, after the application of the change object.

Parameters:
monitor - the progress monitor to use, or null
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

public final void initializeValidationData(
IProgressMonitor monitor)
Description copied from class: 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:

  • 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 when isValid is called.

Specified by:
initializeValidationData in class Change
Parameters:
monitor - a progress monitor

isValid

public final 
RefactoringStatus isValid(
IProgressMonitor monitor)
                                throws 
CoreException,
                                       
OperationCanceledException
Description copied from class: 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 Change
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 occurs
OperationCanceledException - if the validation check got canceled

needsSaving

public final boolean needsSaving()
Does the change need saving?

Returns:
true if it needs saving, false otherwise

perform

public final 
Change perform(
IProgressMonitor monitor)
                     throws 
CoreException
Description copied from class: 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 Change
Parameters:
monitor - a progress monitor
Returns:
the undo change for this change object or null if no undo is provided
Throws:
CoreException - if an error occurred during change execution

setKeepPreviewEdits

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

Overrides:
setKeepPreviewEdits in class TextEditBasedChange
Parameters:
keep - if true executed preview edits are kept

setSaveMode

public final void setSaveMode(int mode)
Sets the save mode.

Parameters:
mode - The mode to set

Eclipse Platform
Release 3.5

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire