Package org.eclipse.ui.forms.editor

# Class FormEditor

java.lang.Object
org.eclipse.core.commands.common.EventManager
org.eclipse.ui.part.WorkbenchPart
org.eclipse.ui.part.EditorPart
org.eclipse.ui.part.MultiPageEditorPart
org.eclipse.ui.forms.editor.FormEditor

All Implemented Interfaces:
  `IAdaptable`, `IExecutableExtension`, `IPageChangeProvider`, `IEditorPart`, `ISaveablePart`, `IWorkbenchPart`, `IWorkbenchPart2`, `IWorkbenchPart3`, `IWorkbenchPartOrientation`

Direct Known Subclasses:
  `SharedHeaderFormEditor`

public abstract class FormEditor extends MultiPageEditorPart
This class forms a base of multi-page form editors that typically use one or more pages with forms and one page for raw source of the editor input.

Pages are added 'lazily' i.e. adding a page reserves a tab for it but does not cause the page control to be created. Page control is created when an attempt is made to select the page in question. This allows editors with several tabs and complex pages to open quickly.

Subclasses should extend this class and implement `addPages` method. One of the two `addPage` methods should be called to contribute pages to the editor. One adds complete (standalone) editors as nested tabs. These editors will be created right away and will be hooked so that key bindings, selection service etc. is compatible with the one for the standalone case. The other method adds classes that implement `IFormPage` interface. These pages will be created lazily and they will share the common key binding and selection service. Since 3.1, FormEditor is a page change provider. It allows listeners to attach to it and get notified when pages are changed. This new API in JFace allows dynamic help to update on page changes.

Since:
  3.0

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Vector<Object>`
`pages`
An array of pages currently in the editor.

### Fields inherited from class org.eclipse.ui.part.MultiPageEditorPart

`PAGE_CONTAINER_SITE`

### Fields inherited from interface org.eclipse.ui.IEditorPart

`PROP_DIRTY, PROP_INPUT`

### Fields inherited from interface org.eclipse.ui.IWorkbenchPart

`PROP_TITLE`

## Constructor Summary

Constructors
Constructor
Description
`FormEditor()`
The constructor.

## Method Summary

Modifier and Type
Method
Description
`void`
`addPage(int index, Control control)`
Adds a simple SWT control as a page.
`void`
`addPage(int index, IFormPage page)`
Adds the form page to this editor at the specified index (0-based).
`void`
`addPage(int index, IEditorPart editor, IEditorInput input)`
Adds a complete editor part to the multi-page editor at the specified position.
`int`
`addPage(Control control)`
Adds a simple SWT control as a page.
`int`
`addPage(IFormPage page)`
Adds the form page to this editor.
`int`
`addPage(IEditorPart editor, IEditorInput input)`
Adds a complete editor part to the multi-page editor.
`protected abstract void`
`addPages()`
Subclass should implement this method to add pages to the editor using 'addPage(IFormPage)' method.
`void`
`close(boolean save)`
Closes the editor programmatically.
`protected void`
`commitPages(boolean onSave)`
Commits all dirty pages in the editor.
`protected void`
`configurePage(int index, IFormPage page)`
Configures the form page.
`protected Composite`
`createPageContainer(Composite parent)`
Creates the parent control for the container returned by `MultiPageEditorPart.getContainer()`.
`protected void`
`createPages()`
Creates the common toolkit for this editor and adds pages to the editor.
`protected FormToolkit`
`createToolkit(Display display)`
Creates the form toolkit.
`void`
`dispose()`
Disposes the pages and the toolkit after disposing the editor itself.
`void`
`editorDirtyStateChanged()`
Called to indicate that the editor has been made dirty or the changes have been saved.
`IFormPage`
`findPage(String pageId)`
Finds the page instance that has the provided id.
`IEditorPart`
`getActiveEditor()`
Widens the visibility of the method in the superclass.
`IFormPage`
`getActivePageInstance()`
Returns active page instance if the currently selected page index is not -1 and active page is a IFormPage, or `null` otherwise.
`protected int`
`getCurrentPage()`
Returns the current page index.
`Object`
`getSelectedPage()`
Returns the selected page for the current active page index, either the IEditorPart for editors or the Control for other pages.
`FormToolkit`
`getToolkit()`
Returns the toolkit owned by this editor.
`void`
`init(IEditorSite site, IEditorInput input)`
Overrides super to plug in a different selection provider.
`boolean`
`isDirty()`
Tests whether the editor is dirty by checking all the pages that implement `IFormPage`.
`protected void`
`pageChange(int newPageIndex)`
Notifies this multi-page editor that the page with the given id has been activated.
`void`
`removePage(int pageIndex)`
Overrides the superclass to remove the page from the page table.
`IFormPage`
`selectReveal(Object pageInput)`
Iterates through the pages calling similar method until a page is found that contains the desired page input.
`protected void`
`setActivePage(int pageIndex)`
Sets the currently active page.
`IFormPage`
`setActivePage(String pageId)`
Sets the active page using the unique page identifier.
`IFormPage`
`setActivePage(String pageId, Object pageInput)`
Sets the active page using the unique page identifier and sets its input to the provided object.
`protected void`
`updateActionBarContributor(int pageIndex)`
Notifies action bar contributor about page change.

### Methods inherited from class org.eclipse.ui.part.MultiPageEditorPart

`activateSite, addPageChangedListener, createContainer, createItem, createPartControl, createSite, deactivateSite, findEditors, getActivePage, getAdapter, getContainer, getControl, getEditor, getPageCount, getPageImage, getPageSite, getPageText, handlePropertyChange, initializePageSwitching, removePageChangedListener, setActiveEditor, setControl, setFocus, setPageImage, setPageText`

### Methods inherited from class org.eclipse.ui.part.EditorPart

`checkSite, doSave, doSaveAs, getEditorInput, getEditorSite, getTitleToolTip, isSaveAsAllowed, isSaveOnCloseNeeded, setContentDescription, setInitializationData, setInput, setInputWithNotify, setPartName`

### Methods inherited from class org.eclipse.ui.part.WorkbenchPart

`addPartPropertyListener, addPropertyListener, firePartPropertyChanged, firePropertyChange, getConfigurationElement, getContentDescription, getDefaultImage, getOrientation, getPartName, getPartProperties, getPartProperty, getSite, getTitle, getTitleImage, removePartPropertyListener, removePropertyListener, setPartProperty, setSite, setTitle, setTitleImage, setTitleToolTip, showBusy`

### Methods inherited from class org.eclipse.core.commands.common.EventManager

`addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject`

### 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, getSite, getTitle, getTitleImage, removePropertyListener`

## Field Details

### pages

protected Vector<Object> pages
An array of pages currently in the editor. Page objects are not limited to those that implement `IFormPage`, hence the size of this array matches the number of pages as viewed by the user.

Subclasses can access this field but should not modify it.

## Constructor Details

### FormEditor

public FormEditor()
The constructor.

## Method Details

### init

public void init(IEditorSite site, IEditorInput input) throws PartInitException
Overrides super to plug in a different selection provider.

Specified by:
  `init` in interface `IEditorPart`
Overrides:
  `init` in class `MultiPageEditorPart`
Parameters:
  `site` - The site for which this part is being created; must not be `null`.
  `input` - The input on which this editor should be created; must not be `null`.
Throws:
  `PartInitException` - If the initialization of the part fails -- currently never.

### createPages

protected void createPages()
Creates the common toolkit for this editor and adds pages to the editor.

Specified by:
  `createPages` in class `MultiPageEditorPart`
See Also:
  - `addPages()`

### createPageContainer

protected Composite createPageContainer(Composite parent)
Description copied from class: `MultiPageEditorPart`
Creates the parent control for the container returned by `MultiPageEditorPart.getContainer()`.

Subclasses may extend and must call super implementation first.

Overrides:
  `createPageContainer` in class `MultiPageEditorPart`
Parameters:
  `parent` - the parent for all of the editors contents.
Returns:
  the parent for this editor's container. Must not be `null`.

### createToolkit

protected FormToolkit createToolkit(Display display)
Creates the form toolkit. The method can be implemented to substitute a subclass of the toolkit that should be used for this editor. A typical use of this method would be to create the form toolkit using one shared `FormColors` object to share resources across the multiple editor instances.

Parameters:
  `display` - the display to use when creating the toolkit
Returns:
  the newly created toolkit instance

### addPages

protected abstract void addPages()
Subclass should implement this method to add pages to the editor using 'addPage(IFormPage)' method.

### getSelectedPage

public Object getSelectedPage()
Description copied from class: `MultiPageEditorPart`
Returns the selected page for the current active page index, either the IEditorPart for editors or the Control for other pages.

Note: clients may override this method to return a page appropriate for their editors. Maybe be `null`.

Specified by:
  `getSelectedPage` in interface `IPageChangeProvider`
Overrides:
  `getSelectedPage` in class `MultiPageEditorPart`
Returns:
  The IEditorPart or Control representing the current active page, or `null` if there are no active pages.
See Also:
  - `MultiPageEditorPart.getActivePage()`

### addPage

public int addPage(IFormPage page) throws PartInitException
Adds the form page to this editor. Form page will be loaded lazily. Its part control will not be created until it is activated for the first time.

Parameters:
  `page` - the form page to add
Throws:
  `PartInitException`

### addPage

public void addPage(int index, IFormPage page) throws PartInitException
Adds the form page to this editor at the specified index (0-based). Form page will be loaded lazily. Its part control will not be created until it is activated for the first time.

Parameters:
  `index` - the position to add the page at (0-based)
  `page` - the form page to add
Throws:
  `PartInitException`
Since:
  3.1

### addPage

public int addPage(Control control)
Adds a simple SWT control as a page. Overrides superclass implementation to keep track of pages.

Overrides:
  `addPage` in class `MultiPageEditorPart`
Parameters:
  `control` - the page control to add
Returns:
  the 0-based index of the newly added page
See Also:
  - `MultiPageEditorPart.setControl(int, Control)`

### addPage

public void addPage(int index, Control control)
Adds a simple SWT control as a page. Overrides superclass implementation to keep track of pages.

Overrides:
  `addPage` in class `MultiPageEditorPart`
Parameters:
  `control` - the page control to add
  `index` - the index at which to add the page (0-based)
Since:
  3.1
See Also:
  - `MultiPageEditorPart.setControl(int, Control)`

### isDirty

public boolean isDirty()
Tests whether the editor is dirty by checking all the pages that implement `IFormPage`. If none of them is dirty, the method delegates further processing to `super.isDirty()`.

Specified by:
  `isDirty` in interface `ISaveablePart`
Overrides:
  `isDirty` in class `MultiPageEditorPart`
Returns:
  `true` if any of the pages in the editor are dirty, `false` otherwise.
Since:
  3.1

### commitPages

protected void commitPages(boolean onSave)
Commits all dirty pages in the editor. This method should be called as a first step of a 'save' operation.

Parameters:
  `onSave` - `true` if commit is performed as part of the 'save' operation, `false` otherwise.
Since:
  3.3

### addPage

public int addPage(IEditorPart editor, IEditorInput input) throws PartInitException
Adds a complete editor part to the multi-page editor.

Overrides:
  `addPage` in class `MultiPageEditorPart`
Parameters:
  `editor` - the nested editor
  `input` - the input for the nested editor
Returns:
  the index of the new page
Throws:
  `PartInitException` - if a new page could not be created
See Also:
  - `MultiPageEditorPart.addPage(IEditorPart, IEditorInput)`

### addPage

public void addPage(int index, IEditorPart editor, IEditorInput input) throws PartInitException
Adds a complete editor part to the multi-page editor at the specified position.

Overrides:
  `addPage` in class `MultiPageEditorPart`
Parameters:
  `index` - the index at which to add the page (0-based)
  `editor` - the nested editor
  `input` - the input for the nested editor
Throws:
  `PartInitException` - if a new page could not be created
Since:
  3.1
See Also:
  - `MultiPageEditorPart.addPage(int, IEditorPart, IEditorInput)`

### configurePage

protected void configurePage(int index, IFormPage page) throws PartInitException
Configures the form page.

Parameters:
  `index` - the page index
  `page` - the page to configure
Throws:
  `PartInitException` - if there are problems in configuring the page

### removePage

public void removePage(int pageIndex)
Overrides the superclass to remove the page from the page table.

Overrides:
  `removePage` in class `MultiPageEditorPart`
Parameters:
  `pageIndex` - the 0-based index of the page in the editor
See Also:
  - `MultiPageEditorPart.addPage(Control)`
  - `MultiPageEditorPart.addPage(IEditorPart, IEditorInput)`

### editorDirtyStateChanged

public void editorDirtyStateChanged()
Called to indicate that the editor has been made dirty or the changes have been saved.

### dispose

public void dispose()
Disposes the pages and the toolkit after disposing the editor itself. Subclasses must call 'super' when reimplementing the method.

Specified by:
  `dispose` in interface `IWorkbenchPart`
Overrides:
  `dispose` in class `MultiPageEditorPart`

### getToolkit

public FormToolkit getToolkit()
Returns the toolkit owned by this editor.

Returns:
  the toolkit object

### getActiveEditor

public IEditorPart getActiveEditor()
Widens the visibility of the method in the superclass.

Overrides:
  `getActiveEditor` in class `MultiPageEditorPart`
Returns:
  the active nested editor

### getCurrentPage

protected int getCurrentPage()
Returns the current page index. The value is identical to the value of 'getActivePage()' except during the page switch, when this method still has the old active page index.

Another important difference is during the editor closing. When the tab folder is disposed, 'getActivePage()' will return -1, while this method will still return the last active page.

Returns:
  the currently selected page or -1 if no page is currently selected
See Also:
  - `MultiPageEditorPart.getActivePage()`

### pageChange

protected void pageChange(int newPageIndex)
Description copied from class: `MultiPageEditorPart`
Notifies this multi-page editor that the page with the given id has been activated. This method is called when the user selects a different tab.

The `MultiPageEditorPart` implementation of this method sets focus to the new page, and notifies the action bar contributor (if there is one). This checks whether the action bar contributor is an instance of `MultiPageEditorActionBarContributor`, and, if so, calls `setActivePage` with the active nested editor. This also fires a selection change event if required.

Subclasses may extend this method.

Overrides:
  `pageChange` in class `MultiPageEditorPart`
Parameters:
  `newPageIndex` - the index of the activated page
See Also:
  - `MultiPageEditorPart.pageChange(int)`

### setActivePage

public IFormPage setActivePage(String pageId)
Sets the active page using the unique page identifier.

Parameters:
  `pageId` - the id of the page to switch to
Returns:
  page that was set active or `null` if not found.

### findPage

public IFormPage findPage(String pageId)
Finds the page instance that has the provided id.

Parameters:
  `pageId` - the id of the page to find
Returns:
  page with the matching id or `null` if not found.

### setActivePage

public IFormPage setActivePage(String pageId, Object pageInput)
Sets the active page using the unique page identifier and sets its input to the provided object.

Parameters:
  `pageId` - the id of the page to switch to
  `pageInput` - the page input
Returns:
  page that was set active or `null` if not found.

### selectReveal

public IFormPage selectReveal(Object pageInput)
Iterates through the pages calling similar method until a page is found that contains the desired page input.

Parameters:
  `pageInput` - the object to select and reveal
Returns:
  the page that accepted the request or `null` if no page has the desired object.
See Also:
  - `setActivePage(String, Object)`

### getActivePageInstance

public IFormPage getActivePageInstance()
Returns active page instance if the currently selected page index is not -1 and active page is a IFormPage, or `null` otherwise.

Returns:
  active page instance if selected, or `null` if no page is currently active.
See Also:
  - `MultiPageEditorPart.getSelectedPage()`

### setActivePage

protected void setActivePage(int pageIndex)
Description copied from class: `MultiPageEditorPart`
Sets the currently active page.

Overrides:
  `setActivePage` in class `MultiPageEditorPart`
Parameters:
  `pageIndex` - the index of the page to be activated; the index must be valid
See Also:
  - `MultiPageEditorPart.setActivePage(int)`

### updateActionBarContributor

protected void updateActionBarContributor(int pageIndex)
Notifies action bar contributor about page change.

Parameters:
  `pageIndex` - the index of the new page

### close

public void close(boolean save)
Closes the editor programmatically.

Parameters:
  `save` - if `true`, the content should be saved before closing.