public abstract class MultiPageEditorPart extends EditorPart implements IPageChangeProvider
Subclasses must implement the following methods:
createPages
- to create the required pages by calling one of
the addPage
methodsIEditorPart.doSave
- to save contents of editorIEditorPart.doSaveAs
- to save contents of editorIEditorPart.isSaveAsAllowed
- to enable Save AsIEditorPart.gotoMarker
- to scroll to a marker
Multi-page editors have a single action bar contributor, which manages
contributions for all the pages. The contributor must be a subclass of
MultiPageEditorActionBarContributor
. Note that since any nested
editors are created directly in code by callers of
addPage(IEditorPart,IEditorInput)
, nested editors do not have
their own contributors.
As of 3.5 multi-page editors will post PageChangedEvents at the end of
pageChange(int)
. Subclasses may override getSelectedPage()
to return a page appropriate to their multi-page editor. IPartListener2
listeners registered with the IPartService can implement IPageChangedListener
to be notified about all page change events within the workbench page or
workbench window.
Modifier and Type | Field and Description |
---|---|
protected static int |
PAGE_CONTAINER_SITE
Subclasses that override
createPageContainer(Composite) can use
this constant to get a site for the container that can be active while
the current page is deactivated. |
PROP_DIRTY, PROP_INPUT
PROP_TITLE
Modifier | Constructor and Description |
---|---|
protected |
MultiPageEditorPart()
Creates an empty multi-page editor with no pages.
|
Modifier and Type | Method and Description |
---|---|
protected void |
activateSite()
This method can be used by implementors of
createPageContainer(Composite) to activate the active inner
editor services when their header loses focus. |
int |
addPage(Control control)
Creates and adds a new page containing the given control to this
multi-page editor.
|
int |
addPage(IEditorPart editor,
IEditorInput input)
Creates and adds a new page containing the given editor to this
multi-page editor.
|
void |
addPage(int index,
Control control)
Creates and adds a new page containing the given control to this
multi-page editor.
|
void |
addPage(int index,
IEditorPart editor,
IEditorInput input)
Creates and adds a new page containing the given editor to this
multi-page editor.
|
void |
addPageChangedListener(IPageChangedListener listener)
Add the page change listener to be notified when the page changes.
|
protected Composite |
createPageContainer(Composite parent)
Creates the parent control for the container returned by
getContainer() . |
protected abstract void |
createPages()
Creates the pages of this multi-page editor.
|
void |
createPartControl(Composite parent)
The
MultiPageEditor implementation of this
IWorkbenchPart method creates the control for the
multi-page editor by calling createContainer , then
createPages . |
protected IEditorSite |
createSite(IEditorPart editor)
Creates the site for the given nested editor.
|
protected void |
deactivateSite(boolean immediate,
boolean containerSiteActive)
This method can be used by implementors of
createPageContainer(Composite) to deactivate
the active inner editor services while their header has focus. |
void |
dispose()
The
MultiPageEditorPart implementation of this
IWorkbenchPart method disposes all nested editors. |
IEditorPart[] |
findEditors(IEditorInput input)
Find the editors contained in this multi-page editor
whose editor input match the provided input.
|
protected IEditorPart |
getActiveEditor()
Returns the active nested editor if there is one.
|
int |
getActivePage()
Returns the index of the currently active page, or -1 if there is no
active page.
|
Object |
getAdapter(Class adapter)
If there is an adapter registered against the subclass of
MultiPageEditorPart return that.
|
protected Composite |
getContainer()
Returns the composite control containing this multi-page editor's pages.
|
protected Control |
getControl(int pageIndex)
Returns the control for the given page index, or
null if
no control has been set for the page. |
protected IEditorPart |
getEditor(int pageIndex)
Returns the editor for the given page index.
|
protected int |
getPageCount()
Returns the number of pages in this multi-page editor.
|
protected Image |
getPageImage(int pageIndex)
Returns the image for the page with the given index, or
null
if no image has been set for the page. |
protected IServiceLocator |
getPageSite(int pageIndex)
Returns the service locator for the given page index.
|
protected String |
getPageText(int pageIndex)
Returns the text label for the page with the given index.
|
Object |
getSelectedPage()
Returns the selected page for the current active page index, either the
IEditorPart for editors or the Control for other pages.
|
protected void |
handlePropertyChange(int propertyId)
Handles a property change notification from a nested editor.
|
void |
init(IEditorSite site,
IEditorInput input)
The
MultiPageEditorPart implementation of this
IEditorPart method sets its site to the given site, its
input to the given input, and the site's selection provider to a
MultiPageSelectionProvider . |
protected void |
initializePageSwitching()
Initialize the MultiPageEditorPart to use the page switching command.
|
boolean |
isDirty()
The
MultiPageEditorPart implementation of this
IEditorPart method returns whether the contents of any of
this multi-page editor's nested editors have changed since the last save. |
protected void |
pageChange(int newPageIndex)
Notifies this multi-page editor that the page with the given id has been
activated.
|
void |
removePage(int pageIndex)
Removes the page with the given index from this multi-page editor.
|
void |
removePageChangedListener(IPageChangedListener listener)
Remove the page change listener.
|
void |
setActiveEditor(IEditorPart editorPart)
Set the active page of this multi-page editor to the
page that contains the given editor part.
|
protected void |
setActivePage(int pageIndex)
Sets the currently active page.
|
protected void |
setControl(int pageIndex,
Control control)
Sets the control for the given page index.
|
void |
setFocus()
The
MultiPageEditor implementation of this
IWorkbenchPart method sets focus on the active nested
editor, if there is one. |
protected void |
setPageImage(int pageIndex,
Image image)
Sets the image for the page with the given index, or
null
to clear the image for the page. |
protected void |
setPageText(int pageIndex,
String text)
Sets the text label for the page with the given index.
|
checkSite, doSave, doSaveAs, getEditorInput, getEditorSite, getTitleToolTip, isSaveAsAllowed, isSaveOnCloseNeeded, setContentDescription, setInitializationData, setInput, setInputWithNotify, setPartName
addPartPropertyListener, addPropertyListener, firePartPropertyChanged, firePropertyChange, getConfigurationElement, getContentDescription, getDefaultImage, getOrientation, getPartName, getPartProperties, getPartProperty, getSite, getTitle, getTitleImage, removePartPropertyListener, removePropertyListener, setPartProperty, setSite, setTitle, setTitleImage, setTitleToolTip, showBusy
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addPropertyListener, getSite, getTitle, getTitleImage, removePropertyListener
protected static final int PAGE_CONTAINER_SITE
createPageContainer(Composite)
can use
this constant to get a site for the container that can be active while
the current page is deactivated.activateSite()
,
deactivateSite(boolean, boolean)
,
getPageSite(int)
,
Constant Field Valuesprotected MultiPageEditorPart()
public int addPage(Control control)
null
, allowing it
to be created and set later using setControl
.control
- the control, or null
setControl(int, Control)
public void addPage(int index, Control control)
null
, allowing it to be created and set later using
setControl
.index
- the index at which to add the page (0-based)control
- the control, or null
setControl(int, Control)
public int addPage(IEditorPart editor, IEditorInput input) throws PartInitException
editor
- the nested editorinput
- the input for the nested editorPartInitException
- if a new page could not be createdthe handler for
property change events from the nested editor
public void addPage(int index, IEditorPart editor, IEditorInput input) throws PartInitException
index
- the index at which to add the page (0-based)editor
- the nested editorinput
- the input for the nested editorPartInitException
- if a new page could not be createdthe handler for
property change events from the nested editor
protected abstract void createPages()
Subclasses must implement this method.
public final void createPartControl(Composite parent)
MultiPageEditor
implementation of this
IWorkbenchPart
method creates the control for the
multi-page editor by calling createContainer
, then
createPages
. Subclasses should implement
createPages
rather than overriding this method.createPartControl
in interface IWorkbenchPart
createPartControl
in class WorkbenchPart
parent
- The parent in which the editor should be created; must not be
null
.protected void initializePageSwitching()
protected Composite createPageContainer(Composite parent)
getContainer()
.
Subclasses may extend and must call super implementation first.
parent
- the parent for all of the editors contents.null
.protected IEditorSite createSite(IEditorPart editor)
MultiPageEditorPart
implementation of this method creates
an instance of MultiPageEditorSite
. Subclasses may
reimplement to create more specialized sites.editor
- the nested editorpublic void dispose()
MultiPageEditorPart
implementation of this
IWorkbenchPart
method disposes all nested editors.
Subclasses may extend.dispose
in interface IWorkbenchPart
dispose
in class WorkbenchPart
protected IEditorPart getActiveEditor()
Subclasses should not override this method
null
if nonepublic int getActivePage()
Subclasses should not override this method
protected Composite getContainer()
addPage(Control)
,
the passed control should be a child of this container.
Warning: Clients should not assume that the container is any particular subclass of Composite. The actual class used may change in order to improve the look and feel of multi-page editors. Any code making assumptions on the particular subclass would thus be broken.
Subclasses should not override this method
null
if
createPartControl
has not been called yetprotected Control getControl(int pageIndex)
null
if
no control has been set for the page. The page index must be valid.
Subclasses should not override this method
pageIndex
- the index of the pagenull
if
none has been setprotected IEditorPart getEditor(int pageIndex)
pageIndex
- the index of the pagenull
if the
specified page was not created with
addPage(IEditorPart,IEditorInput)
protected final IServiceLocator getPageSite(int pageIndex)
This will return the editor site service locator for an editor, and create one for a page that is just a control.
pageIndex
- the index of the pagenull
if the
specified page was not created with
addPage(IEditorPart,IEditorInput)
protected int getPageCount()
protected Image getPageImage(int pageIndex)
null
if no image has been set for the page. The page index must be valid.pageIndex
- the index of the pagenull
if noneprotected String getPageText(int pageIndex)
pageIndex
- the index of the pageprotected void handlePropertyChange(int propertyId)
firePropertyChange
with the same
property id. For example, if the dirty state of a nested editor changes
(property id IEditorPart.PROP_DIRTY
), this method handles
it by firing a property change event for
IEditorPart.PROP_DIRTY
to property listeners on this
multi-page editor.
Subclasses may extend or reimplement this method.
propertyId
- the id of the property that changedpublic void init(IEditorSite site, IEditorInput input) throws PartInitException
MultiPageEditorPart
implementation of this
IEditorPart
method sets its site to the given site, its
input to the given input, and the site's selection provider to a
MultiPageSelectionProvider
. Subclasses may extend this
method.init
in interface IEditorPart
init
in class EditorPart
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
.PartInitException
- If the initialization of the part fails -- currently never.public boolean isDirty()
MultiPageEditorPart
implementation of this
IEditorPart
method returns whether the contents of any of
this multi-page editor's nested editors have changed since the last save.
Pages created with addPage(Control)
are ignored.
Subclasses may extend or reimplement this method.
isDirty
in interface ISaveablePart
isDirty
in class EditorPart
true
if any of the nested editors are dirty;
false
otherwise.protected void pageChange(int newPageIndex)
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.
newPageIndex
- the index of the activated pageprotected final void deactivateSite(boolean immediate, boolean containerSiteActive)
createPageContainer(Composite)
to deactivate
the active inner editor services while their header has focus. A
deactivateSite() must have a matching call to activateSite() when
appropriate.
An new inner editor will have its site activated on a
pageChange(int)
.
Note: This API is evolving in 3.4 and this might not be its final form.
immediate
- immediately deactivate the legacy keybinding servicecontainerSiteActive
- Leave the page container site active.activateSite()
,
createPageContainer(Composite)
,
getPageSite(int)
,
PAGE_CONTAINER_SITE
protected final void activateSite()
createPageContainer(Composite)
to activate the active inner
editor services when their header loses focus.
An new inner editor will have its site activated on a
pageChange(int)
.
Note: This API is evolving in 3.4 and this might not be its final form.
deactivateSite(boolean,boolean)
,
createPageContainer(Composite)
,
getPageSite(int)
public void removePage(int pageIndex)
pageIndex
- the index of the pageaddPage(Control)
,
addPage(IEditorPart, IEditorInput)
protected void setActivePage(int pageIndex)
pageIndex
- the index of the page to be activated; the index must be validprotected void setControl(int pageIndex, Control control)
pageIndex
- the index of the pagecontrol
- the control for the specified page, or null
to
clear the controlpublic void setFocus()
MultiPageEditor
implementation of this
IWorkbenchPart
method sets focus on the active nested
editor, if there is one.
Subclasses may extend or reimplement.
setFocus
in interface IWorkbenchPart
setFocus
in class WorkbenchPart
protected void setPageImage(int pageIndex, Image image)
null
to clear the image for the page. The page index must be valid.pageIndex
- the index of the pageimage
- the image, or null
protected void setPageText(int pageIndex, String text)
pageIndex
- the index of the pagetext
- the text labelpublic Object getAdapter(Class adapter)
getAdapter
in interface IAdaptable
getAdapter
in class WorkbenchPart
adapter
- the adapter class to look upnull
if this object does not
have an adapter for the given classWorkbenchPart.getAdapter(java.lang.Class)
public final IEditorPart[] findEditors(IEditorInput input)
input
- the editor inputpublic final void setActiveEditor(IEditorPart editorPart)
editorPart
- the editor partpublic Object getSelectedPage()
Note: clients may override this method to return a page
appropriate for their editors. Maybe be null
.
getSelectedPage
in interface IPageChangeProvider
null
if there are no active pages.getActivePage()
public void addPageChangedListener(IPageChangedListener listener)
getSelectedPage()
. In the default case, this will be the active
page Control, IEditorPart, or null
.
This method has no effect if the listener has already been added.
addPageChangedListener
in interface IPageChangeProvider
listener
- a page changed listenerpublic void removePageChangedListener(IPageChangedListener listener)
This method has no effect if the listener is not in the list.
removePageChangedListener
in interface IPageChangeProvider
listener
- a page changed listener
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.