Eclipse Platform
Release 3.0

org.eclipse.ui.part
Class EditorPart

java.lang.Object
  extended byorg.eclipse.ui.part.WorkbenchPart
      extended byorg.eclipse.ui.part.EditorPart
All Implemented Interfaces:
IAdaptable, IEditorPart, IExecutableExtension, ISaveablePart, IWorkbenchPart, IWorkbenchPart2
Direct Known Subclasses:
AbstractTextEditor, FormPage, MultiEditor, MultiPageEditor, MultiPageEditorPart

public abstract class EditorPart
extends WorkbenchPart
implements IEditorPart

Abstract base implementation of all workbench editors.

This class should be subclassed by clients wishing to define new editors. The name of the subclass should be given as the "class" attribute in a editor extension contributed to the workbench's view extension point (named "org.eclipse.ui.editors"). For example, the plug-in's XML markup might contain:

 <extension point="org.eclipse.ui.editors">
      <editor id="com.example.myplugin.ed"
         name="My Editor"
         icon="./images/cedit.gif"
 		   extensions="foo" 
 		   class="com.example.myplugin.MyFooEditor" 
 		   contributorClass="com.example.myplugin.MyFooEditorContributor" 
      />
 </extension>
 
where com.example.myplugin.MyEditor is the name of the EditorPart subclass.

Subclasses must implement the following methods:

Subclasses may extend or reimplement the following methods as required:


Field Summary
 
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 EditorPart()
          Creates a new workbench editor.
 
Method Summary
abstract  void doSave(IProgressMonitor monitor)
          Saves the contents of this part.
abstract  void doSaveAs()
          Saves the contents of this part to another object.
 IEditorInput getEditorInput()
          Returns the input for this editor.
 IEditorSite getEditorSite()
          Returns the site for this editor.
 String getTitleToolTip()
          Returns the title tool tip text of this workbench part.
abstract  void init(IEditorSite site, IEditorInput input)
          Initializes this editor with the given editor site and input.
abstract  boolean isDirty()
          Returns whether the contents of this part have changed since the last save operation.
abstract  boolean isSaveAsAllowed()
          Returns whether the "Save As" operation is supported by this part.
 boolean isSaveOnCloseNeeded()
          Returns whether the contents of this part should be saved when the part is closed.
protected  void setContentDescription(String description)
          Sets the content description for this part.
 void setInitializationData(IConfigurationElement cfig, String propertyName, Object data)
          This method is called by the implementation of the method IConfigurationElement.createExecutableExtension on a newly constructed extension, passing it its relevant configuration information. Most executable extensions only make use of the first two call arguments.

Regular executable extensions specify their Java implementation class name as an attribute of the configuration element for the extension. For example

     <action run="com.example.BaseAction"/>
 
In the above example, this method would be called with a reference to the <action> element (first argument), and "run" as the name of the attribute that defined this executable extension (second argument).

The last parameter is for the specific use of extension adapters and is typically not used by regular executable extensions.

There are two supported ways of associating additional adapter-specific data with the configuration in a way that is transparent to the extension point implementor:

(1) by specifying adapter data as part of the implementation class attribute value. The Java class name can be followed by a ":" separator, followed by any adapter data in string form. For example, if the extension point specifies an attribute "run" to contain the name of the extension implementation, an adapter can be configured as

     <action run="com.example.ExternalAdapter:./cmds/util.exe -opt 3"/>
 

(2) by converting the attribute used to specify the executable extension to a child element of the original configuration element, and specifying the adapter data in the form of xml markup. Using this form, the example above would become

     <action>
         <run class="com.xyz.ExternalAdapter">
             <parameter name="exec" value="./cmds/util.exe"/>
             <parameter name="opt"  value="3"/>
         </run>
     </action>
 

Form (2) will typically only be used for extension points that anticipate the majority of extensions configured into it will in fact be in the form of adapters.

In either case, the specified adapter class is instantiated using its 0-argument public constructor. The adapter data is passed as the last argument of this method. The data argument is defined as Object. It can have the following values:

  • null, if no adapter data was supplied
  • in case (1), the initialization data string is passed as a String
  • in case (2), the initialization data is passed as a Hashtable containing the actual parameter names and values (both Strings)

The WorkbenchPart implementation of this IExecutableExtension records the configuration element in and internal state variable (accessible via getConfigElement). It also loads the title image, if one is specified in the configuration element. Subclasses may extend. Should not be called by clients. It is called by the core plugin when creating this executable extension. The WorkbenchPart implementation of this IExecutableExtension records the configuration element in and internal state variable (accessible via getConfigElement).
protected  void setInput(IEditorInput input)
          Sets the input to this editor.
protected  void setPartName(String partName)
          Sets the name of this part.
 
Methods inherited from class org.eclipse.ui.part.WorkbenchPart
addPropertyListener, createPartControl, dispose, firePropertyChange, getAdapter, getConfigurationElement, getContentDescription, getDefaultImage, getPartName, getSite, getTitle, getTitleImage, removePropertyListener, setFocus, setSite, setTitle, setTitleImage, setTitleToolTip, showBusy
 
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.IWorkbenchPart
addPropertyListener, createPartControl, dispose, getSite, getTitle, getTitleImage, removePropertyListener, setFocus
 
Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapter
 

Constructor Detail

EditorPart

protected EditorPart()
Creates a new workbench editor.

Method Detail

doSave

public abstract void doSave(IProgressMonitor monitor)
Description copied from interface: ISaveablePart
Saves the contents of this part.

If the save is successful, the part should fire a property changed event reflecting the new dirty state (PROP_DIRTY property).

If the save is cancelled through user action, or for any other reason, the part should invoke setCancelled on the IProgressMonitor to inform the caller.

This method is long-running; progress and cancellation are provided by the given progress monitor.

Specified by:
doSave in interface ISaveablePart
Parameters:
monitor - the progress monitor

doSaveAs

public abstract void doSaveAs()
Description copied from interface: ISaveablePart
Saves the contents of this part to another object.

Implementors are expected to open a "Save As" dialog where the user will be able to select a new name for the contents. After the selection is made, the contents should be saved to that new name. During this operation a IProgressMonitor should be used to indicate progress.

If the save is successful, the part fires a property changed event reflecting the new dirty state (PROP_DIRTY property).

Specified by:
doSaveAs in interface ISaveablePart

getEditorInput

public IEditorInput getEditorInput()
Description copied from interface: IEditorPart
Returns the input for this editor. If this value changes the part must fire a property listener event with PROP_INPUT.

Specified by:
getEditorInput in interface IEditorPart
Returns:
the editor input

getEditorSite

public IEditorSite getEditorSite()
Description copied from interface: IEditorPart
Returns the site for this editor. The method is equivalent to (IEditorSite) getSite().

Specified by:
getEditorSite in interface IEditorPart
Returns:
the editor site

getTitleToolTip

public String getTitleToolTip()
Description copied from interface: IWorkbenchPart
Returns the title tool tip text of this workbench part. An empty string result indicates no tool tip. If this value changes the part must fire a property listener event with PROP_TITLE.

The tool tip text is used to populate the title bar of this part's visual container.

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

init

public abstract 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 the part is instantiated. 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
Parameters:
site - the editor site
input - the editor input
Throws:
PartInitException - if this editor was not initialized successfully

isDirty

public abstract boolean isDirty()
Description copied from interface: ISaveablePart
Returns whether the contents of this part 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 ISaveablePart
Returns:
true if the contents have been modified and need saving, and false if they have not changed since the last save

isSaveAsAllowed

public abstract boolean isSaveAsAllowed()
Description copied from interface: ISaveablePart
Returns whether the "Save As" operation is supported by this part.

Specified by:
isSaveAsAllowed in interface ISaveablePart
Returns:
true if "Save As" is supported, and false if not supported

isSaveOnCloseNeeded

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

Specified by:
isSaveOnCloseNeeded in interface ISaveablePart
Returns:
true if the contents of the part should be saved on close, and false if the contents are expendable

setInput

protected void setInput(IEditorInput input)
Sets the input to this editor.

Parameters:
input - the editor input

setContentDescription

protected void setContentDescription(String description)
Description copied from class: WorkbenchPart
Sets the content description for this part. The content description is typically a short string describing the current contents of the part. Setting this to the empty string will cause a default content description to be used. Clients should call this method instead of overriding getContentDescription(). For views, the content description is shown (by default) in a line near the top of the view. For editors, the content description is shown beside the part name when showing a list of editors. If the editor is open on a file, this typically contains the path to the input file, without the filename or trailing slash.

This may overwrite a value that was previously set in setTitle

Overrides:
setContentDescription in class WorkbenchPart
Parameters:
description - the content description

setPartName

protected void setPartName(String partName)
Description copied from class: WorkbenchPart
Sets the name of this part. The name will be shown in the tab area for the part. Clients should call this method instead of overriding getPartName. Setting this to the empty string will cause a default part name to be used.

setPartName and setContentDescription are intended to replace setTitle. This may change a value that was previously set using setTitle.

Overrides:
setPartName in class WorkbenchPart
Parameters:
partName - the part name, as it should be displayed in tabs.

setInitializationData

public void setInitializationData(IConfigurationElement cfig,
                                  String propertyName,
                                  Object data)
Description copied from class: WorkbenchPart
This method is called by the implementation of the method IConfigurationElement.createExecutableExtension on a newly constructed extension, passing it its relevant configuration information. Most executable extensions only make use of the first two call arguments.

Regular executable extensions specify their Java implementation class name as an attribute of the configuration element for the extension. For example

     <action run="com.example.BaseAction"/>
 
In the above example, this method would be called with a reference to the <action> element (first argument), and "run" as the name of the attribute that defined this executable extension (second argument).

The last parameter is for the specific use of extension adapters and is typically not used by regular executable extensions.

There are two supported ways of associating additional adapter-specific data with the configuration in a way that is transparent to the extension point implementor:

(1) by specifying adapter data as part of the implementation class attribute value. The Java class name can be followed by a ":" separator, followed by any adapter data in string form. For example, if the extension point specifies an attribute "run" to contain the name of the extension implementation, an adapter can be configured as

     <action run="com.example.ExternalAdapter:./cmds/util.exe -opt 3"/>
 

(2) by converting the attribute used to specify the executable extension to a child element of the original configuration element, and specifying the adapter data in the form of xml markup. Using this form, the example above would become

     <action>
         <run class="com.xyz.ExternalAdapter">
             <parameter name="exec" value="./cmds/util.exe"/>
             <parameter name="opt"  value="3"/>
         </run>
     </action>
 

Form (2) will typically only be used for extension points that anticipate the majority of extensions configured into it will in fact be in the form of adapters.

In either case, the specified adapter class is instantiated using its 0-argument public constructor. The adapter data is passed as the last argument of this method. The data argument is defined as Object. It can have the following values:

The WorkbenchPart implementation of this IExecutableExtension records the configuration element in and internal state variable (accessible via getConfigElement). It also loads the title image, if one is specified in the configuration element. Subclasses may extend. Should not be called by clients. It is called by the core plugin when creating this executable extension.

Specified by:
setInitializationData in interface IExecutableExtension
Overrides:
setInitializationData in class WorkbenchPart

Eclipse Platform
Release 3.0

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2004. All rights reserved.