Class MultiPageEditorPart
- All Implemented Interfaces:
IAdaptable,IExecutableExtension,IPageChangeProvider,IEditorPart,ISaveablePart,IWorkbenchPart,IWorkbenchPart2,IWorkbenchPart3,IWorkbenchPartOrientation
- Direct Known Subclasses:
FormEditor
Subclasses must implement the following methods:
createPages- to create the required pages by calling one of theaddPagemethodsIEditorPart.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intSubclasses that overridecreatePageContainer(Composite)can use this constant to get a site for the container that can be active while the current page is deactivated.Fields inherited from interface org.eclipse.ui.IEditorPart
PROP_DIRTY, PROP_INPUTFields inherited from interface org.eclipse.ui.IWorkbenchPart
PROP_TITLE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates an empty multi-page editor with no pages. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidThis method can be used by implementors ofcreatePageContainer(Composite)to activate the active inner editor services when their header loses focus.voidCreates and adds a new page containing the given control to this multi-page editor.voidaddPage(int index, IEditorPart editor, IEditorInput input) Creates and adds a new page containing the given editor to this multi-page editor.intCreates and adds a new page containing the given control to this multi-page editor.intaddPage(IEditorPart editor, IEditorInput input) Creates and adds a new page containing the given editor to this multi-page editor.voidaddPageChangedListener(IPageChangedListener listener) Add the page change listener to be notified when the page changes.protected CTabFoldercreateContainer(Composite parent) Creates an empty container.protected CTabItemcreateItem(int index, Control control) Creates a tab item at the given index and places the given control in the new item.protected CompositecreatePageContainer(Composite parent) Creates the parent control for the container returned bygetContainer().protected abstract voidCreates the pages of this multi-page editor.voidcreatePartControl(Composite parent) TheMultiPageEditorimplementation of thisIWorkbenchPartmethod creates the control for the multi-page editor by callingcreateContainer, thencreatePages.protected IEditorSitecreateSite(IEditorPart editor) Creates the site for the given nested editor.protected final voiddeactivateSite(boolean immediate, boolean containerSiteActive) This method can be used by implementors ofcreatePageContainer(Composite)to deactivate the active inner editor services while their header has focus.voiddispose()TheMultiPageEditorPartimplementation of thisIWorkbenchPartmethod disposes all nested editors.final IEditorPart[]findEditors(IEditorInput input) Find the editors contained in this multi-page editor whose editor input match the provided input.protected IEditorPartReturns the active nested editor if there is one.intReturns the index of the currently active page, or -1 if there is no active page.<T> TgetAdapter(Class<T> adapter) If there is an adapter registered against the subclass of MultiPageEditorPart return that.protected CompositeReturns the composite control containing this multi-page editor's pages.protected ControlgetControl(int pageIndex) Returns the control for the given page index, ornullif no control has been set for the page.protected IEditorPartgetEditor(int pageIndex) Returns the editor for the given page index.protected intReturns the number of pages in this multi-page editor.protected ImagegetPageImage(int pageIndex) Returns the image for the page with the given index, ornullif no image has been set for the page.protected final IServiceLocatorgetPageSite(int pageIndex) Returns the service locator for the given page index.protected StringgetPageText(int pageIndex) Returns the text label for the page with the given index.Returns the selected page for the current active page index, either the IEditorPart for editors or the Control for other pages.protected voidhandlePropertyChange(int propertyId) Handles a property change notification from a nested editor.voidinit(IEditorSite site, IEditorInput input) TheMultiPageEditorPartimplementation of thisIEditorPartmethod sets its site to the given site, its input to the given input, and the site's selection provider to aMultiPageSelectionProvider.protected voidInitialize the MultiPageEditorPart to use the page switching command.booleanisDirty()TheMultiPageEditorPartimplementation of thisIEditorPartmethod returns whether the contents of any of this multi-page editor's nested editors have changed since the last save.protected voidpageChange(int newPageIndex) Notifies this multi-page editor that the page with the given id has been activated.voidremovePage(int pageIndex) Removes the page with the given index from this multi-page editor.voidRemove the page change listener.final voidsetActiveEditor(IEditorPart editorPart) Set the active page of this multi-page editor to the page that contains the given editor part.protected voidsetActivePage(int pageIndex) Sets the currently active page.protected voidsetControl(int pageIndex, Control control) Sets the control for the given page index.voidsetFocus()TheMultiPageEditorimplementation of thisIWorkbenchPartmethod sets focus on the active nested editor, if there is one.protected voidsetPageImage(int pageIndex, Image image) Sets the image for the page with the given index, ornullto clear the image for the page.protected voidsetPageText(int pageIndex, String text) Sets the text label for the page with the given index.Methods inherited from class org.eclipse.ui.part.EditorPart
checkSite, doSave, doSaveAs, getEditorInput, getEditorSite, getTitleToolTip, isSaveAsAllowed, isSaveOnCloseNeeded, setContentDescription, setInitializationData, setInput, setInputWithNotify, setPartNameMethods 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, showBusyMethods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObjectMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.ui.IWorkbenchPart
addPropertyListener, getSite, getTitle, getTitleImage, removePropertyListener
-
Field Details
-
PAGE_CONTAINER_SITE
protected static final int PAGE_CONTAINER_SITESubclasses that overridecreatePageContainer(Composite)can use this constant to get a site for the container that can be active while the current page is deactivated.- Since:
- 3.4
- See Also:
-
-
Constructor Details
-
MultiPageEditorPart
protected MultiPageEditorPart()Creates an empty multi-page editor with no pages.
-
-
Method Details
-
addPage
Creates and adds a new page containing the given control to this multi-page editor. The control may benull, allowing it to be created and set later usingsetControl.- Parameters:
control- the control, ornull- Returns:
- the index of the new page
- See Also:
-
addPage
Creates and adds a new page containing the given control to this multi-page editor. The page is added at the given index. The control may benull, allowing it to be created and set later usingsetControl.- Parameters:
index- the index at which to add the page (0-based)control- the control, ornull- See Also:
-
addPage
Creates and adds a new page containing the given editor to this multi-page editor. This also hooks a property change listener on the nested editor.- Parameters:
editor- the nested editorinput- 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:
-
addPage
Creates and adds a new page containing the given editor to this multi-page editor. The page is added at the given index. This also hooks a property change listener on the nested editor.- Parameters:
index- the index at which to add the page (0-based)editor- the nested editorinput- the input for the nested editor- Throws:
PartInitException- if a new page could not be created- See Also:
-
createContainer
Creates an empty container. Creates a CTabFolder with no style bits set, and hooks a selection listener which callspageChange()whenever the selected tab changes.- Parameters:
parent- The composite in which the container tab folder should be created; must not benull.- Returns:
- a new container
- Since:
- 3.115
-
createItem
Creates a tab item at the given index and places the given control in the new item. The item is a CTabItem with no style bits set.- Parameters:
index- the index at which to add the controlcontrol- is the control to be placed in an item- Returns:
- a new item
- Since:
- 3.115
-
createPages
protected abstract void createPages()Creates the pages of this multi-page editor.Subclasses must implement this method.
-
createPartControl
TheMultiPageEditorimplementation of thisIWorkbenchPartmethod creates the control for the multi-page editor by callingcreateContainer, thencreatePages. Subclasses should implementcreatePagesrather than overriding this method.- Specified by:
createPartControlin interfaceIWorkbenchPart- Specified by:
createPartControlin classWorkbenchPart- Parameters:
parent- The parent in which the editor should be created; must not benull.
-
initializePageSwitching
protected void initializePageSwitching()Initialize the MultiPageEditorPart to use the page switching command. Clients can override this method with an empty body if they wish to opt-out.- Since:
- 3.4
-
createPageContainer
Creates the parent control for the container returned bygetContainer().Subclasses may extend and must call super implementation first.
- Parameters:
parent- the parent for all of the editors contents.- Returns:
- the parent for this editor's container. Must not be
null. - Since:
- 3.2
-
createSite
Creates the site for the given nested editor. TheMultiPageEditorPartimplementation of this method creates an instance ofMultiPageEditorSite. Subclasses may reimplement to create more specialized sites.- Parameters:
editor- the nested editor- Returns:
- the editor site
-
dispose
public void dispose()TheMultiPageEditorPartimplementation of thisIWorkbenchPartmethod disposes all nested editors. Subclasses may extend.- Specified by:
disposein interfaceIWorkbenchPart- Overrides:
disposein classWorkbenchPart
-
getActiveEditor
Returns the active nested editor if there is one.Subclasses should not override this method
- Returns:
- the active nested editor, or
nullif none - Restriction:
-
getActivePage
public int getActivePage()Returns the index of the currently active page, or -1 if there is no active page.Subclasses should not override this method
- Returns:
- the index of the active page, or -1 if there is no active page
- Since:
- 3.5
- Restriction:
-
getContainer
Returns the composite control containing this multi-page editor's pages. This should be used as the parent when creating controls for the individual pages. That is, when callingaddPage(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
- Returns:
- the composite, or
nullifcreatePartControlhas not been called yet
-
getControl
Returns the control for the given page index, ornullif no control has been set for the page. The page index must be valid.Subclasses should not override this method
- Parameters:
pageIndex- the index of the page- Returns:
- the control for the specified page, or
nullif none has been set
-
getEditor
Returns the editor for the given page index. The page index must be valid.- Parameters:
pageIndex- the index of the page- Returns:
- the editor for the specified page, or
nullif the specified page was not created withaddPage(IEditorPart,IEditorInput)
-
getPageSite
Returns the service locator for the given page index. This method can be used to create service locators for pages that are just controls. The page index must be valid.This will return the editor site service locator for an editor, and create one for a page that is just a control.
- Parameters:
pageIndex- the index of the page- Returns:
- the editor for the specified page, or
nullif the specified page was not created withaddPage(IEditorPart,IEditorInput) - Since:
- 3.4
-
getPageCount
protected int getPageCount()Returns the number of pages in this multi-page editor.- Returns:
- the number of pages
-
getPageImage
Returns the image for the page with the given index, ornullif no image has been set for the page. The page index must be valid.- Parameters:
pageIndex- the index of the page- Returns:
- the image, or
nullif none
-
getPageText
Returns the text label for the page with the given index. Returns the empty string if no text label has been set for the page. The page index must be valid.- Parameters:
pageIndex- the index of the page- Returns:
- the text label for the page
-
handlePropertyChange
protected void handlePropertyChange(int propertyId) Handles a property change notification from a nested editor. The default implementation simply forwards the change to listeners on this multi-page editor by callingfirePropertyChangewith the same property id. For example, if the dirty state of a nested editor changes (property idIEditorPart.PROP_DIRTY), this method handles it by firing a property change event forIEditorPart.PROP_DIRTYto property listeners on this multi-page editor.Subclasses may extend or reimplement this method.
- Parameters:
propertyId- the id of the property that changed
-
init
TheMultiPageEditorPartimplementation of thisIEditorPartmethod sets its site to the given site, its input to the given input, and the site's selection provider to aMultiPageSelectionProvider. Subclasses may extend this method.- Specified by:
initin interfaceIEditorPart- Specified by:
initin classEditorPart- Parameters:
site- The site for which this part is being created; must not benull.input- The input on which this editor should be created; must not benull.- Throws:
PartInitException- If the initialization of the part fails -- currently never.
-
isDirty
public boolean isDirty()TheMultiPageEditorPartimplementation of thisIEditorPartmethod returns whether the contents of any of this multi-page editor's nested editors have changed since the last save. Pages created withaddPage(Control)are ignored.Subclasses may extend or reimplement this method.
- Specified by:
isDirtyin interfaceISaveablePart- Specified by:
isDirtyin classEditorPart- Returns:
trueif any of the nested editors are dirty;falseotherwise.
-
pageChange
protected void pageChange(int newPageIndex) 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
MultiPageEditorPartimplementation 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 ofMultiPageEditorActionBarContributor, and, if so, callssetActivePagewith the active nested editor. This also fires a selection change event if required.Subclasses may extend this method.
- Parameters:
newPageIndex- the index of the activated page
-
deactivateSite
protected final void deactivateSite(boolean immediate, boolean containerSiteActive) This method can be used by implementors ofcreatePageContainer(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.
- Parameters:
immediate- immediately deactivate the legacy keybinding servicecontainerSiteActive- Leave the page container site active.- Since:
- 3.4
- See Also:
-
activateSite
protected final void activateSite()This method can be used by implementors ofcreatePageContainer(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.
- Since:
- 3.4
- See Also:
-
removePage
public void removePage(int pageIndex) Removes the page with the given index from this multi-page editor. The controls for the page are disposed of; if the page has an editor, it is disposed of too. The page index must be valid.- Parameters:
pageIndex- the index of the page- See Also:
-
setActivePage
protected void setActivePage(int pageIndex) Sets the currently active page.- Parameters:
pageIndex- the index of the page to be activated; the index must be valid
-
setControl
Sets the control for the given page index. The page index must be valid.- Parameters:
pageIndex- the index of the pagecontrol- the control for the specified page, ornullto clear the control
-
setFocus
public void setFocus()TheMultiPageEditorimplementation of thisIWorkbenchPartmethod sets focus on the active nested editor, if there is one.Subclasses may extend or reimplement.
- Specified by:
setFocusin interfaceIWorkbenchPart- Specified by:
setFocusin classWorkbenchPart
-
setPageImage
Sets the image for the page with the given index, ornullto clear the image for the page. The page index must be valid.- Parameters:
pageIndex- the index of the pageimage- the image, ornull
-
setPageText
Sets the text label for the page with the given index. The page index must be valid. The text label must not be null.- Parameters:
pageIndex- the index of the pagetext- the text label
-
getAdapter
If there is an adapter registered against the subclass of MultiPageEditorPart return that. Otherwise, delegate to the internal editor.- Specified by:
getAdapterin interfaceIAdaptable- Overrides:
getAdapterin classWorkbenchPart- Type Parameters:
T- the class type- Parameters:
adapter- the adapter class to look up- Returns:
- a object of the given class, or
nullif this object does not have an adapter for the given class - See Also:
-
findEditors
Find the editors contained in this multi-page editor whose editor input match the provided input.- Parameters:
input- the editor input- Returns:
- the editors contained in this multi-page editor whose editor input match the provided input
- Since:
- 3.3
-
setActiveEditor
Set the active page of this multi-page editor to the page that contains the given editor part. This method has no effect of the given editor part is not contained in this multi-page editor.- Parameters:
editorPart- the editor part- Since:
- 3.3
-
getSelectedPage
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:
getSelectedPagein interfaceIPageChangeProvider- Returns:
- The IEditorPart or Control representing the current active page, or
nullif there are no active pages. - Since:
- 3.5
- See Also:
-
addPageChangedListener
Add the page change listener to be notified when the page changes. The newly selected page will be the Object returned fromgetSelectedPage(). In the default case, this will be the active page Control, IEditorPart, ornull.This method has no effect if the listener has already been added.
- Specified by:
addPageChangedListenerin interfaceIPageChangeProvider- Parameters:
listener- a page changed listener- Since:
- 3.5
- Restriction:
-
removePageChangedListener
Remove the page change listener.This method has no effect if the listener is not in the list.
- Specified by:
removePageChangedListenerin interfaceIPageChangeProvider- Parameters:
listener- a page changed listener- Since:
- 3.5
- Restriction:
-