Eclipse Platform
2.0

org.eclipse.ui.texteditor
Class AbstractTextEditor

java.lang.Object
  |
  +--org.eclipse.ui.part.WorkbenchPart
        |
        +--org.eclipse.ui.part.EditorPart
              |
              +--org.eclipse.ui.texteditor.AbstractTextEditor
All Implemented Interfaces:
IAdaptable, IEditorPart, IExecutableExtension, IReusableEditor, ITextEditor, ITextEditorExtension, IWorkbenchPart
Direct Known Subclasses:
StatusTextEditor

public abstract class AbstractTextEditor
extends EditorPart
implements ITextEditor, IReusableEditor, ITextEditorExtension

Abstract base implementation of a text editor.

Subclasses are responsible for configuring the editor appropriately. The standard text editor, TextEditor, is one such example.

If a subclass calls setEditorContextMenuId the arguments is used as the id under which the editor's context menu is registered for extensions. If no id is set, the context menu is registered under [editor_id].EditorContext whereby [editor_id] is replaced with the editor's part id. If the editor is instructed to run in version 1.0 context menu registration compatibility mode, the latter form of the registration even happens if a context menu id has been set via setEditorContextMenuId. If no id is set while in compatibility mode, the menu is registered under DEFAULT_EDITOR_CONTEXT_MENU_ID.

If a subclass calls setRulerContextMenuId the arguments is used as the id under which the ruler's context menu is registered for extensions. If no id is set, the context menu is registered under [editor_id].RulerContext whereby [editor_id] is replaced with the editor's part id. If the editor is instructed to run in version 1.0 context menu registration compatibility mode, the latter form of the registration even happens if a context menu id has been set via setRulerContextMenuId. If no id is set while in compatibility mode, the menu is registered under DEFAULT_RULER_CONTEXT_MENU_ID.

See Also:
TextEditor

Field Summary
protected static org.eclipse.ui.texteditor.AbstractTextEditor.IdMapEntry[] ACTION_MAP
          The complete mapping between action definition ids used by eclipse and StyledText actions.
static String DEFAULT_EDITOR_CONTEXT_MENU_ID
          Menu id for the editor context menu.
static String DEFAULT_RULER_CONTEXT_MENU_ID
          Menu id for the ruler context menu.
protected  String fErrorLabel
          The error message shown in the status line in case of failed information look up.
static String PREFERENCE_COLOR_BACKGROUND
          Key used to look up background color preference Value: AbstractTextEditor.Color.Background
static String PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT
          Key used to look up background color system default preference Value: AbstractTextEditor.Color.Background.SystemDefault
static String PREFERENCE_COLOR_FIND_SCOPE
          Key used to look up find scope background color preference Value: AbstractTextEditor.Color.FindScope
static String PREFERENCE_COLOR_FOREGROUND
          Key used to look up foreground color preference Value: AbstractTextEditor.Color.Foreground
static String PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT
          Key used to look up foreground color system default preference Value: AbstractTextEditor.Color.Foreground.SystemDefault
static String PREFERENCE_FONT
          Key used to look up font preference
protected static int VERTICAL_RULER_WIDTH
          The width of the vertical ruler
 
Fields inherited from interface org.eclipse.ui.IEditorPart
PROP_DIRTY, PROP_INPUT
 
Fields inherited from interface org.eclipse.ui.IWorkbenchPart
PROP_TITLE
 
Constructor Summary
protected AbstractTextEditor()
          Creates a new text editor.
 
Method Summary
protected  void addAction(IMenuManager menu, String actionId)
          Convenience method to add the action installed under the given action id to the given menu.
protected  void addAction(IMenuManager menu, String group, String actionId)
          Convenience method to add the action installed under the given action id to the specified group of the menu.
protected  void addGroup(IMenuManager menu, String existingGroup, String newGroup)
          Convenience method to add a new group after the specified group.
 void addRulerContextMenuListener(IMenuListener listener)
          Adds a ruler context menu listener to the editor.
protected  void adjustHighlightRange(int offset, int length)
          Adjusts the highlight range so that at least the specified range is highlighted.
protected  boolean affectsTextPresentation(PropertyChangeEvent event)
          Determines whether the given preference change affects the editor's presentation.
protected  boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement)
          Returns wether this editor can handle the move of the original element so that it ends up being the moved element.
 void close(boolean save)
          Closes this text editor after optionally saving changes.
protected  void createActions()
          Creates this editor's standard actions and connects them with the global workbench actions.
protected  void createNavigationActions()
          Creates this editor's standard navigation actions.
 void createPartControl(Composite parent)
          The AbstractTextEditor implementation of this IWorkbenchPart method creates the vertical ruler and source viewer.
protected  WorkspaceModifyOperation createSaveOperation(boolean overwrite)
          Creates a workspace modify operation which saves the content of the editor to the editor's input element.
protected  ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles)
          Creates the source viewer to be used by this editor.
protected  IVerticalRuler createVerticalRuler()
          Creates the vertical ruler to be used by this editor.
 void dispose()
          The AbstractTextEditor implementation of this IWorkbenchPart method may be extended by subclasses.
 void doRevertToSaved()
          The AbstractTextEditor implementation of this ITextEditor method may be extended by subclasses.
 void doSave(IProgressMonitor progressMonitor)
          The AbstractTextEditor implementation of this IEditorPart method may be extended by subclasses.
 void doSaveAs()
          The AbstractTextEditor implementation of this IEditorPart method calls oerformSaveAs.
protected  void doSetInput(IEditorInput input)
          Internal setInput method.
protected  void editorContextMenuAboutToShow(IMenuManager menu)
          Sets up this editor's context menu before it is made visible.
protected  void enableSanityChecking(boolean enable)
          Enables/Disabled sanity checking.
protected  void firePropertyChange(int property)
          Fires a property changed event.
 IAction getAction(String actionID)
          Returns the action installed under the given action id.
 Object getAdapter(Class required)
          Returns an object which is an instance of the given class associated with this object.
protected  IMenuListener getContextMenuListener()
          Creates and returns the listener on this editor's context menus.
protected  org.eclipse.ui.texteditor.AbstractTextEditor.ICursorListener getCursorListener()
          Returns this editor's "cursor" listener to be installed on the editor's source viewer.
protected  String getCursorPosition()
          Returns a description of the cursor position.
 IDocumentProvider getDocumentProvider()
          Returns this text editor's document provider.
protected  String getEditorContextMenuId()
          Returns the editor's context menu id.
protected  String getHelpContextId()
          Returns the editor's help context id.
 IRegion getHighlightRange()
          Returns the highlighted range of this text editor.
protected  IPreferenceStore getPreferenceStore()
          Returns this editor's preference store.
protected  Annotation getRangeIndicator()
          Returns the editor's range indicator.
protected  String getRulerContextMenuId()
          Returns the ruler's context menu id.
protected  MouseListener getRulerMouseListener()
          Creates and returns the listener on this editor's vertical ruler.
protected  ISelectionChangedListener getSelectionChangedListener()
          Returns this editor's selection changed listener to be installed on the editor's source viewer.
 ISelectionProvider getSelectionProvider()
          Returns this text editor's selection provider.
protected  ISourceViewer getSourceViewer()
          Returns the editor's source viewer.
protected  SourceViewerConfiguration getSourceViewerConfiguration()
          Returns the editor's source viewer configuration.
protected  IStatusField getStatusField(String category)
          Returns the current status field for the given status category.
protected  IVerticalRuler getVerticalRuler()
          Returns the editor's vertical ruler.
 void gotoMarker(IMarker marker)
          If the editor can be saved all marker ranges have been changed according to the text manipulations.
protected  void handleCursorPositionChanged()
          Handles a potential change of the cursor position.
protected  void handleEditorInputChanged()
          Handles an external change of the editor's input element.
protected  void handleExceptionOnSave(CoreException exception, IProgressMonitor progressMonitor)
          Handles the given exception.
protected  void handleInsertModeChanged()
          Handles a change of the editor's insert mode.
protected  void handlePreferenceStoreChanged(PropertyChangeEvent event)
          Handles a property change event describing a change of the editor's preference store and updates the preference related editor properties.
 void init(IEditorSite site, IEditorInput input)
          Initializes this editor with the given editor site and input.
 boolean isDirty()
          Returns whether the contents of this editor have changed since the last save operation.
 boolean isEditable()
          Returns whether the text in this text editor can be changed by the user.
 boolean isEditorInputReadOnly()
          Returns whether the editor's input is read-only.
protected  boolean isInInsertMode()
          Returns whether this editor is in overwrite or insert mode.
 boolean isSaveAsAllowed()
          The AbstractTextEditor implementation of this IEditorPart method returns false.
 boolean isSaveOnCloseNeeded()
          Returns whether the contents of this editor should be saved when the editor is closed.
 void markAsContentDependentAction(String actionId, boolean mark)
          Marks or unmarks the given action to be updated on content changes.
 void markAsPropertyDependentAction(String actionId, boolean mark)
          Marks or unmarks the given action to be updated on property changes.
 void markAsSelectionDependentAction(String actionId, boolean mark)
          Marks or unmarks the given action to be updated on text selection changes.
 void markAsStateDependentAction(String actionId, boolean mark)
          Marks or unmarks the given action to be updated on state changes.
protected  void performSaveAs(IProgressMonitor progressMonitor)
          Performs a save as and reports the result state back to the given progress monitor.
protected  void performSaveOperation(WorkspaceModifyOperation operation, IProgressMonitor progressMonitor)
          Performs the given save operation and handles errors appropriatly.
protected  void rememberSelection()
          Remembers the current selection of this editor.
 void removeActionActivationCode(String actionID)
          Removes any installed activation code for the specified action.
 void removeRulerContextMenuListener(IMenuListener listener)
          Removes a ruler context menu listener from the editor.
 void resetHighlightRange()
          Resets the highlighted range of this text editor.
protected  void restoreSelection()
          Restores a selection previously remembered by rememberSelection.
protected  void rulerContextMenuAboutToShow(IMenuManager menu)
          Sets up the ruler context menu before it is made visible.
protected  void safelySanityCheckState(IEditorInput input)
          Checks the state of the given editor input if sanity checking is enabled.
protected  void sanityCheckState(IEditorInput input)
          Checks the state of the given editor input.
 void selectAndReveal(int start, int length)
          Selects and reveals the specified range in this text editor.
 void setAction(String actionID, IAction action)
          Installs the given action under the given action id.
 void setActionActivationCode(String actionID, char activationCharacter, int activationKeyCode, int activationStateMask)
          Sets the given activation code for the specified action.
protected  void setCompatibilityMode(boolean compatible)
          Sets the context menu registration 1.0 compatibility mode.
protected  void setDocumentProvider(IDocumentProvider provider)
          Sets this editor's document provider.
protected  void setEditorContextMenuId(String contextMenuId)
          Sets this editor's context menu id.
 void setFocus()
          Asks this part to take focus within the workbench.
protected  void setHelpContextId(String helpContextId)
          Sets the editor's help context id.
 void setHighlightRange(int start, int length, boolean moveCursor)
          Sets the highlighted range of this text editor to the specified region.
 void setInput(IEditorInput input)
          Sets the input to this editor.
protected  void setPreferenceStore(IPreferenceStore store)
          Sets this editor's preference store.
protected  void setRangeIndicator(Annotation rangeIndicator)
          Sets the annotation which this editor uses to represent the highlight range if the editor is configured to show the entire document.
protected  void setRulerContextMenuId(String contextMenuId)
          Sets the ruler's context menu id.
protected  void setSourceViewerConfiguration(SourceViewerConfiguration configuration)
          Sets this editor's source viewer configuration used to configure its internal source viewer.
 void setStatusField(IStatusField field, String category)
          Informs the editor which status field is to be used when posting status information in the given category.
 void showHighlightRangeOnly(boolean showHighlightRangeOnly)
          Configures this text editor to show only the highlighted range of the text.
 boolean showsHighlightRangeOnly()
          Returns whether this text editor is configured to show only the highlighted range of the text.
protected  void updateContentDependentActions()
          Updates all content dependent actions.
protected  void updatePropertyDependentActions()
          Updates all property dependent actions.
protected  void updateSelectionDependentActions()
          Updates all selection dependent actions.
protected  void updateState(IEditorInput input)
          Updates the state of the given editor input such as read-only flag etc.
protected  void updateStateDependentActions()
          Updates all state dependent actions.
protected  void updateStatusField(String category)
          Updates the status fields for the given category.
protected  void updateStatusFields()
          Updates all status fields.
protected  void validateState(IEditorInput input)
          Validates the state of the given editor input.
 
Methods inherited from class org.eclipse.ui.part.EditorPart
getEditorInput, getEditorSite, getTitleToolTip
 
Methods inherited from class org.eclipse.ui.part.WorkbenchPart
addPropertyListener, getConfigurationElement, getDefaultImage, getSite, getTitle, getTitleImage, removePropertyListener, setInitializationData, setSite, setTitle, setTitleImage, setTitleToolTip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.ui.IEditorPart
getEditorInput, getEditorSite
 
Methods inherited from interface org.eclipse.ui.IWorkbenchPart
addPropertyListener, getSite, getTitle, getTitleImage, getTitleToolTip, removePropertyListener
 

Field Detail

PREFERENCE_FONT

public static final String PREFERENCE_FONT
Key used to look up font preference

See Also:
Constant Field Values

PREFERENCE_COLOR_FOREGROUND

public static final String PREFERENCE_COLOR_FOREGROUND
Key used to look up foreground color preference Value: AbstractTextEditor.Color.Foreground

Since:
2.0
See Also:
Constant Field Values

PREFERENCE_COLOR_BACKGROUND

public static final String PREFERENCE_COLOR_BACKGROUND
Key used to look up background color preference Value: AbstractTextEditor.Color.Background

Since:
2.0
See Also:
Constant Field Values

PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT

public static final String PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT
Key used to look up foreground color system default preference Value: AbstractTextEditor.Color.Foreground.SystemDefault

Since:
2.0
See Also:
Constant Field Values

PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT

public static final String PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT
Key used to look up background color system default preference Value: AbstractTextEditor.Color.Background.SystemDefault

Since:
2.0
See Also:
Constant Field Values

PREFERENCE_COLOR_FIND_SCOPE

public static final String PREFERENCE_COLOR_FIND_SCOPE
Key used to look up find scope background color preference Value: AbstractTextEditor.Color.FindScope

Since:
2.0
See Also:
Constant Field Values

DEFAULT_EDITOR_CONTEXT_MENU_ID

public static final String DEFAULT_EDITOR_CONTEXT_MENU_ID
Menu id for the editor context menu.

See Also:
Constant Field Values

DEFAULT_RULER_CONTEXT_MENU_ID

public static final String DEFAULT_RULER_CONTEXT_MENU_ID
Menu id for the ruler context menu.

See Also:
Constant Field Values

VERTICAL_RULER_WIDTH

protected static final int VERTICAL_RULER_WIDTH
The width of the vertical ruler

See Also:
Constant Field Values

ACTION_MAP

protected static final org.eclipse.ui.texteditor.AbstractTextEditor.IdMapEntry[] ACTION_MAP
The complete mapping between action definition ids used by eclipse and StyledText actions.

Since:
2.0

fErrorLabel

protected final String fErrorLabel
The error message shown in the status line in case of failed information look up.

Constructor Detail

AbstractTextEditor

protected AbstractTextEditor()
Creates a new text editor. If not explicitly set, this editor uses a SourceViewerConfiguration to configure its source viewer. This viewer does not have a range indicator installed, nor any menu id set. By default, the created editor runs in 1.0 context menu registration compatibility mode.

Method Detail

getDocumentProvider

public IDocumentProvider getDocumentProvider()
Description copied from interface: ITextEditor
Returns this text editor's document provider.

Specified by:
getDocumentProvider in interface ITextEditor
Returns:
the document provider

getRangeIndicator

protected final Annotation getRangeIndicator()
Returns the editor's range indicator.

Returns:
the editor's range indicator

getSourceViewerConfiguration

protected final SourceViewerConfiguration getSourceViewerConfiguration()
Returns the editor's source viewer configuration.

Returns:
the editor's source viewer configuration

getSourceViewer

protected final ISourceViewer getSourceViewer()
Returns the editor's source viewer.

Returns:
the editor's source viewer

getVerticalRuler

protected final IVerticalRuler getVerticalRuler()
Returns the editor's vertical ruler.

Returns:
the editor's vertical ruler

getEditorContextMenuId

protected final String getEditorContextMenuId()
Returns the editor's context menu id.

Returns:
the editor's context menu id

getRulerContextMenuId

protected final String getRulerContextMenuId()
Returns the ruler's context menu id.

Returns:
the ruler's context menu id

getHelpContextId

protected final String getHelpContextId()
Returns the editor's help context id.

Returns:
the editor's help context id

getPreferenceStore

protected final IPreferenceStore getPreferenceStore()
Returns this editor's preference store.

Returns:
this editor's preference store

setDocumentProvider

protected void setDocumentProvider(IDocumentProvider provider)
Sets this editor's document provider. This method must be called before the editor's control is created.

Parameters:
provider - the document provider

setSourceViewerConfiguration

protected void setSourceViewerConfiguration(SourceViewerConfiguration configuration)
Sets this editor's source viewer configuration used to configure its internal source viewer. This method must be called before the editor's control is created. If not, this editor uses a SourceViewerConfiguration.

Parameters:
configuration - the source viewer configuration object

setRangeIndicator

protected void setRangeIndicator(Annotation rangeIndicator)
Sets the annotation which this editor uses to represent the highlight range if the editor is configured to show the entire document. If the range indicator is not set, this editor uses a DefaultRangeIndicator.

Parameters:
rangeIndicator - the annotation

setEditorContextMenuId

protected void setEditorContextMenuId(String contextMenuId)
Sets this editor's context menu id.

Parameters:
contextMenuId - the context menu id

setRulerContextMenuId

protected void setRulerContextMenuId(String contextMenuId)
Sets the ruler's context menu id.

Parameters:
contextMenuId - the context menu id

setCompatibilityMode

protected final void setCompatibilityMode(boolean compatible)
Sets the context menu registration 1.0 compatibility mode. (See class description for more details.)

Parameters:
compatible - true if compatibility mode is enabled
Since:
2.0

setHelpContextId

protected void setHelpContextId(String helpContextId)
Sets the editor's help context id.

Parameters:
helpContextId - the help context id

setPreferenceStore

protected void setPreferenceStore(IPreferenceStore store)
Sets this editor's preference store. This method must be called before the editor's control is created.

Parameters:
store - the new preference store

isEditable

public boolean isEditable()
Description copied from interface: ITextEditor
Returns whether the text in this text editor can be changed by the user.

Specified by:
isEditable in interface ITextEditor
Returns:
true if it can be edited, and false if it is read-only

getSelectionProvider

public ISelectionProvider getSelectionProvider()
Description copied from interface: ITextEditor
Returns this text editor's selection provider. Repeated calls to this method return the same selection provider.

Specified by:
getSelectionProvider in interface ITextEditor
Returns:
the selection provider

rememberSelection

protected void rememberSelection()
Remembers the current selection of this editor. This method is called when, e.g., the content of the editor is about to be reverted to the saved state. This method remembers the selection in a semantic format, i.e., in a format which allows to restore the selection even if the originally selected text is no longer part of the editor's content.

Subclasses should implement this method including all necessary state. This default implementation remembers the textual range only and is thus purely syntactic.

Since:
2.0
See Also:
restoreSelection()

restoreSelection

protected void restoreSelection()
Restores a selection previously remembered by rememberSelection. Subclasses may reimplement this method and thereby semantically adapt the remembered selection. This default implementation just selects the remembered textual range.

Since:
2.0
See Also:
rememberSelection()

getContextMenuListener

protected final IMenuListener getContextMenuListener()
Creates and returns the listener on this editor's context menus.

Returns:
the menu listener

getRulerMouseListener

protected final MouseListener getRulerMouseListener()
Creates and returns the listener on this editor's vertical ruler.

Returns:
the mouse listener

getSelectionChangedListener

protected final ISelectionChangedListener getSelectionChangedListener()
Returns this editor's selection changed listener to be installed on the editor's source viewer.

Returns:
the listener

getCursorListener

protected final org.eclipse.ui.texteditor.AbstractTextEditor.ICursorListener getCursorListener()
Returns this editor's "cursor" listener to be installed on the editor's source viewer. This listener is listening to key and mouse button events. It triggers the updating of the status line by calling handleCursorPositionChanged().

Returns:
the listener
Since:
2.0

init

public void init(IEditorSite site,
                 IEditorInput input)
          throws PartInitException
Description copied from interface: IEditorPart
Initializes this editor with the given editor site and input.

This method is automatically called shortly after part construction; it marks the start of the part's lifecycle. The IWorkbenchPart.dispose method will be called automically at the end of the lifecycle. Clients must not call this method.

Implementors of this method must examine the editor input object type to determine if it is understood. If not, the implementor must throw a PartInitException

Specified by:
init in interface IEditorPart
Specified by:
init in class EditorPart
Parameters:
site - the editor site
input - the editor input
Throws:
PartInitException - if this editor was not initialized successfully

createVerticalRuler

protected IVerticalRuler createVerticalRuler()
Creates the vertical ruler to be used by this editor. Subclasses may re-implement this method.

Returns:
the vertical ruler

createSourceViewer

protected ISourceViewer createSourceViewer(Composite parent,
                                           IVerticalRuler ruler,
                                           int styles)
Creates the source viewer to be used by this editor. Subclasses may re-implement this method.

Parameters:
parent - the parent control
ruler - the vertical ruler
styles - style bits
Returns:
the source viewer

createPartControl

public void createPartControl(Composite parent)
The AbstractTextEditor implementation of this IWorkbenchPart method creates the vertical ruler and source viewer. Subclasses may extend.

Specified by:
createPartControl in interface IWorkbenchPart
Specified by:
createPartControl in class WorkbenchPart
Parameters:
parent - the parent control

doSetInput

protected void doSetInput(IEditorInput input)
                   throws CoreException
Internal setInput method.

Parameters:
input - the input to be set
Throws:
CoreException - if input cannot be connected to the document provider

setInput

public final void setInput(IEditorInput input)
Description copied from class: EditorPart
Sets the input to this editor.

Specified by:
setInput in interface IReusableEditor
Overrides:
setInput in class EditorPart
See Also:
EditorPart#setInput

close

public void close(boolean save)
Description copied from interface: ITextEditor
Closes this text editor after optionally saving changes.

Specified by:
close in interface ITextEditor
Parameters:
save - true if unsaved changed should be saved, and false if unsaved changed should be discarded

dispose

public void dispose()
The AbstractTextEditor implementation of this IWorkbenchPart method may be extended by subclasses. Subclasses must call super.dispose().

Specified by:
dispose in interface IWorkbenchPart
Overrides:
dispose in class WorkbenchPart

affectsTextPresentation

protected boolean affectsTextPresentation(PropertyChangeEvent event)
Determines whether the given preference change affects the editor's presentation. This implementation always returns false. May be reimplemented by subclasses.

Parameters:
event - the event which should be investigated
Returns:
true if the event describes a preference change affecting the editor's presentation
Since:
2.0

handlePreferenceStoreChanged

protected void handlePreferenceStoreChanged(PropertyChangeEvent event)
Handles a property change event describing a change of the editor's preference store and updates the preference related editor properties.

Parameters:
event - the property change event

handleEditorInputChanged

protected void handleEditorInputChanged()
Handles an external change of the editor's input element.


doSaveAs

public void doSaveAs()
The AbstractTextEditor implementation of this IEditorPart method calls oerformSaveAs. Subclasses may reimplement.

Specified by:
doSaveAs in interface IEditorPart
Specified by:
doSaveAs in class EditorPart

performSaveAs

protected void performSaveAs(IProgressMonitor progressMonitor)
Performs a save as and reports the result state back to the given progress monitor. This default implementation does nothing. Subclasses may reimplement.

Parameters:
progressMonitor - the progress monitor for communicating result state or null

doSave

public void doSave(IProgressMonitor progressMonitor)
The AbstractTextEditor implementation of this IEditorPart method may be extended by subclasses.

Specified by:
doSave in interface IEditorPart
Specified by:
doSave in class EditorPart
Parameters:
progressMonitor - the progress monitor

enableSanityChecking

protected void enableSanityChecking(boolean enable)
Enables/Disabled sanity checking.

Parameters:
enable - true if santity checking should be enabled, false otherwise
Since:
2.0

safelySanityCheckState

protected void safelySanityCheckState(IEditorInput input)
Checks the state of the given editor input if sanity checking is enabled.

Parameters:
input - the editor input whose state is to be checked
Since:
2.0

sanityCheckState

protected void sanityCheckState(IEditorInput input)
Checks the state of the given editor input.

Parameters:
input - the editor input whose state is to be checked
Since:
2.0

validateState

protected void validateState(IEditorInput input)
Validates the state of the given editor input. The predominate intent of this method is to take any action propably necessary to ensure that the input can persistently be changed.

Parameters:
input - the input to be validated
Since:
2.0

updateState

protected void updateState(IEditorInput input)
Updates the state of the given editor input such as read-only flag etc.

Parameters:
input - the input to be validated
Since:
2.0

createSaveOperation

protected WorkspaceModifyOperation createSaveOperation(boolean overwrite)
Creates a workspace modify operation which saves the content of the editor to the editor's input element. overwrite indicates whether the editor input element may be overwritten if necessary. Clients may reimplement this method.

Parameters:
overwrite - indicates whether or not overwrititng is allowed
Returns:
the save operation

performSaveOperation

protected void performSaveOperation(WorkspaceModifyOperation operation,
                                    IProgressMonitor progressMonitor)
Performs the given save operation and handles errors appropriatly.

Parameters:
operation - the operation to be performed
progressMonitor - the monitor in which to run the operation

handleExceptionOnSave

protected void handleExceptionOnSave(CoreException exception,
                                     IProgressMonitor progressMonitor)
Handles the given exception. If the exception reports an out-of-sync situation, this is reported to the user. Otherwise, the exception is generically reported.

Parameters:
exception - the exception to handle
progressMonitor - the progress monitor

isSaveAsAllowed

public boolean isSaveAsAllowed()
The AbstractTextEditor implementation of this IEditorPart method returns false. Subclasses may override.

Specified by:
isSaveAsAllowed in interface IEditorPart
Specified by:
isSaveAsAllowed in class EditorPart
Returns:
true if "save as" is supported, and false if "save as" is not supported

isSaveOnCloseNeeded

public boolean isSaveOnCloseNeeded()
Description copied from interface: IEditorPart
Returns whether the contents of this editor should be saved when the editor is closed.

Specified by:
isSaveOnCloseNeeded in interface IEditorPart
Overrides:
isSaveOnCloseNeeded in class EditorPart
Returns:
true if the contents of the editor should be saved on close, and false if the contents are expendable

isDirty

public boolean isDirty()
Description copied from interface: IEditorPart
Returns whether the contents of this editor have changed since the last save operation. If this value changes the part must fire a property listener event with PROP_DIRTY.

Specified by:
isDirty in interface IEditorPart
Specified by:
isDirty in class EditorPart
Returns:
true if the contents have been modified and need saving, and false if they have not changed since the last save

doRevertToSaved

public void doRevertToSaved()
The AbstractTextEditor implementation of this ITextEditor method may be extended by subclasses.

Specified by:
doRevertToSaved in interface ITextEditor

setAction

public void setAction(String actionID,
                      IAction action)
Description copied from interface: ITextEditor
Installs the given action under the given action id.

Specified by:
setAction in interface ITextEditor
Parameters:
action - the action, or null to clear it
See Also:
ITextEditor.getAction(java.lang.String)

setActionActivationCode

public void setActionActivationCode(String actionID,
                                    char activationCharacter,
                                    int activationKeyCode,
                                    int activationStateMask)
Description copied from interface: ITextEditor
Sets the given activation code for the specified action. If there is an activation code already registered, it is replaced. The activation code consists of the same information as a KeyEvent. If the activation code is triggered and the associated action is enabled, the action is performed and the triggering KeyEvent is considered consumed. If the action is disabled, the KeyEvent is passed on unmodified. Thus, action activation codes and action accelerators differ in their model of event consumption.

Specified by:
setActionActivationCode in interface ITextEditor
Parameters:
actionID - the action id

removeActionActivationCode

public void removeActionActivationCode(String actionID)
Description copied from interface: ITextEditor
Removes any installed activation code for the specified action. If no activation code is installed, this method does not have any effect.

Specified by:
removeActionActivationCode in interface ITextEditor
Parameters:
actionID - the action id

getAction

public IAction getAction(String actionID)
Description copied from interface: ITextEditor
Returns the action installed under the given action id.

Specified by:
getAction in interface ITextEditor
Parameters:
actionID - the action id
Returns:
the action, or null if none
See Also:
ITextEditor.setAction(java.lang.String, org.eclipse.jface.action.IAction)

markAsSelectionDependentAction

public void markAsSelectionDependentAction(String actionId,
                                           boolean mark)
Marks or unmarks the given action to be updated on text selection changes.

Parameters:
actionId - the action id
mark - true if the action is selection dependent

markAsContentDependentAction

public void markAsContentDependentAction(String actionId,
                                         boolean mark)
Marks or unmarks the given action to be updated on content changes.

Parameters:
actionId - the action id
mark - true if the action is content dependent

markAsPropertyDependentAction

public void markAsPropertyDependentAction(String actionId,
                                          boolean mark)
Marks or unmarks the given action to be updated on property changes.

Parameters:
actionId - the action id
mark - true if the action is property dependent
Since:
2.0

markAsStateDependentAction

public void markAsStateDependentAction(String actionId,
                                       boolean mark)
Marks or unmarks the given action to be updated on state changes.

Parameters:
actionId - the action id
mark - true if the action is state dependent
Since:
2.0

updateSelectionDependentActions

protected void updateSelectionDependentActions()
Updates all selection dependent actions.


updateContentDependentActions

protected void updateContentDependentActions()
Updates all content dependent actions.


updatePropertyDependentActions

protected void updatePropertyDependentActions()
Updates all property dependent actions.

Since:
2.0

updateStateDependentActions

protected void updateStateDependentActions()
Updates all state dependent actions.

Since:
2.0

createNavigationActions

protected void createNavigationActions()
Creates this editor's standard navigation actions.

Subclasses may extend.

Since:
2.0

createActions

protected void createActions()
Creates this editor's standard actions and connects them with the global workbench actions.

Subclasses may extend.


addAction

protected final void addAction(IMenuManager menu,
                               String actionId)
Convenience method to add the action installed under the given action id to the given menu.

Parameters:
menu - the menu to add the action to
actionId - the id of the action to be added

addAction

protected final void addAction(IMenuManager menu,
                               String group,
                               String actionId)
Convenience method to add the action installed under the given action id to the specified group of the menu.

Parameters:
menu - the menu to add the action to
group - the group in the menu
actionId - the id of the action to add

addGroup

protected final void addGroup(IMenuManager menu,
                              String existingGroup,
                              String newGroup)
Convenience method to add a new group after the specified group.

Parameters:
menu - the menu to add the new group to
existingGroup - the group after which to insert the new group
newGroup - the new group

rulerContextMenuAboutToShow

protected void rulerContextMenuAboutToShow(IMenuManager menu)
Sets up the ruler context menu before it is made visible.

Subclasses may extend to add other actions.

Parameters:
menu - the menu

editorContextMenuAboutToShow

protected void editorContextMenuAboutToShow(IMenuManager menu)
Sets up this editor's context menu before it is made visible.

Subclasses may extend to add other actions.

Parameters:
menu - the menu

getAdapter

public Object getAdapter(Class required)
Description copied from interface: IAdaptable
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 IAdaptable
Overrides:
getAdapter in class WorkbenchPart
Parameters:
required - 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

setFocus

public void setFocus()
Description copied from interface: IWorkbenchPart
Asks this part to take focus within the workbench.

Clients should not call this method (the workbench calls this method at appropriate times).

Specified by:
setFocus in interface IWorkbenchPart
Specified by:
setFocus in class WorkbenchPart

gotoMarker

public void gotoMarker(IMarker marker)
If the editor can be saved all marker ranges have been changed according to the text manipulations. However, those changes are not yet propagated to the marker manager. Thus, when opening a marker, the marker's position in the editor must be determined as it might differ from the position stated in the marker.

Specified by:
gotoMarker in interface IEditorPart
Specified by:
gotoMarker in class EditorPart
Parameters:
marker - the marker to go to
See Also:
EditorPart.gotoMarker(org.eclipse.core.resources.IMarker)

showsHighlightRangeOnly

public boolean showsHighlightRangeOnly()
Description copied from interface: ITextEditor
Returns whether this text editor is configured to show only the highlighted range of the text.

Specified by:
showsHighlightRangeOnly in interface ITextEditor
Returns:
true if only the highlighted range is shown, and false if this editor shows the entire text of the document
See Also:
ITextEditor.showHighlightRangeOnly(boolean)

showHighlightRangeOnly

public void showHighlightRangeOnly(boolean showHighlightRangeOnly)
Description copied from interface: ITextEditor
Configures this text editor to show only the highlighted range of the text.

Specified by:
showHighlightRangeOnly in interface ITextEditor
Parameters:
showHighlightRangeOnly - true if only the highlighted range is shown, and false if this editor shows the entire text of the document
See Also:
ITextEditor.showsHighlightRangeOnly()

setHighlightRange

public void setHighlightRange(int start,
                              int length,
                              boolean moveCursor)
Description copied from interface: ITextEditor
Sets the highlighted range of this text editor to the specified region.

Specified by:
setHighlightRange in interface ITextEditor
Parameters:
start - the offset of the highlighted range
length - the length of the highlighted range
moveCursor - true if the cursor should be moved to the start of the highlighted range, and false to leave the cursor unaffected
See Also:
ITextEditor.getHighlightRange()

getHighlightRange

public IRegion getHighlightRange()
Description copied from interface: ITextEditor
Returns the highlighted range of this text editor.

Specified by:
getHighlightRange in interface ITextEditor
Returns:
the highlighted range
See Also:
ITextEditor.setHighlightRange(int, int, boolean)

resetHighlightRange

public void resetHighlightRange()
Description copied from interface: ITextEditor
Resets the highlighted range of this text editor.

Specified by:
resetHighlightRange in interface ITextEditor

adjustHighlightRange

protected void adjustHighlightRange(int offset,
                                    int length)
Adjusts the highlight range so that at least the specified range is highlighted.

Subclasses may re-implement this method.

Parameters:
offset - the offset of the range which at least should be highlighted
length - the length of the range which at least should be highlighted

selectAndReveal

public void selectAndReveal(int start,
                            int length)
Description copied from interface: ITextEditor
Selects and reveals the specified range in this text editor.

Specified by:
selectAndReveal in interface ITextEditor
Parameters:
start - the offset of the selection
length - the length of the selection

firePropertyChange

protected void firePropertyChange(int property)
Description copied from class: WorkbenchPart
Fires a property changed event.

Overrides:
firePropertyChange in class WorkbenchPart
Parameters:
property - the id of the property that changed

setStatusField

public void setStatusField(IStatusField field,
                           String category)
Description copied from interface: ITextEditorExtension
Informs the editor which status field is to be used when posting status information in the given category.

Specified by:
setStatusField in interface ITextEditorExtension
Parameters:
field - the status field to be used
category - the status information category
See Also:
ITextEditorActionConstants

getStatusField

protected IStatusField getStatusField(String category)
Returns the current status field for the given status category.

Parameters:
category - the status category
Returns:
the current status field for the given status category.
Since:
2.0

isInInsertMode

protected boolean isInInsertMode()
Returns whether this editor is in overwrite or insert mode.

Returns:
true if in insert mode, false for overwrite mode
Since:
2.0

handleCursorPositionChanged

protected void handleCursorPositionChanged()
Handles a potential change of the cursor position. Subclasses may extend.

Since:
2.0

handleInsertModeChanged

protected void handleInsertModeChanged()
Handles a change of the editor's insert mode. Subclasses may extend.

Since:
2.0

updateStatusField

protected void updateStatusField(String category)
Updates the status fields for the given category.

Parameters:
category -
Since:
2.0

updateStatusFields

protected void updateStatusFields()
Updates all status fields.

Since:
2.0

getCursorPosition

protected String getCursorPosition()
Returns a description of the cursor position.

Returns:
a description of the cursor position
Since:
2.0

isEditorInputReadOnly

public boolean isEditorInputReadOnly()
Description copied from interface: ITextEditorExtension
Returns whether the editor's input is read-only. The semantics of this method is orthogonal to isEditable as it talks about the editor input, i.e. the domain element, and not about the editor document.

Specified by:
isEditorInputReadOnly in interface ITextEditorExtension
Returns:
true if the editor input is read-only

addRulerContextMenuListener

public void addRulerContextMenuListener(IMenuListener listener)
Description copied from interface: ITextEditorExtension
Adds a ruler context menu listener to the editor.

Specified by:
addRulerContextMenuListener in interface ITextEditorExtension
Parameters:
listener - the listener

removeRulerContextMenuListener

public void removeRulerContextMenuListener(IMenuListener listener)
Description copied from interface: ITextEditorExtension
Removes a ruler context menu listener from the editor.

Specified by:
removeRulerContextMenuListener in interface ITextEditorExtension
Parameters:
listener - the listener

canHandleMove

protected boolean canHandleMove(IEditorInput originalElement,
                                IEditorInput movedElement)
Returns wether this editor can handle the move of the original element so that it ends up being the moved element. By default this method returns true. Subclasses may reimplement.

Parameters:
originalElement - the original element
movedElement - the moved element
Since:
2.0

Eclipse Platform
2.0

Copyright (c) IBM Corp. and others 2000, 2002. All Rights Reserved.