roneditor
Class AbstractMultiViewerPage

java.lang.Object
  extended by org.eclipse.ui.part.Page
      extended by roneditor.AbstractMultiViewerPage
All Implemented Interfaces:
org.eclipse.core.runtime.IAdaptable, org.eclipse.emf.common.notify.Adapter, org.eclipse.gef.commands.CommandStackListener, org.eclipse.jface.viewers.ISelectionChangedListener, org.eclipse.ui.part.IPage, org.eclipse.ui.part.IPageBookViewPage
Direct Known Subclasses:
ObjectNetPage, RONPage, RulePage

public abstract class AbstractMultiViewerPage
extends org.eclipse.ui.part.Page
implements org.eclipse.jface.viewers.ISelectionChangedListener, org.eclipse.core.runtime.IAdaptable, org.eclipse.emf.common.notify.Adapter, org.eclipse.gef.commands.CommandStackListener

This class is based roughly on GraphicalEditorWithFlyoutPalette.

It is an IPage that contains some GraphicalViewers and a FlyoutPaletteComposite and is able to change the current viewer. It is meant to be used in a PageBookView (especially AbstractPageBookView) like an editor. Like an editor this page has its own EditDomain and ActionRegistry. A top model element and a parent editor (from which this page is being called to show up) are set in the constructor. A ZoomManagerDelegate for a ZoomComboContributionItem is provided via getAdapter(Class) to the workbench page's part service.

Prerequisites: The parent editor must provide non-null instances of the following classes via getAdapter():

When initialized and in createControl(Composite) this class does the following:

  1. The page registers itself as an eAdapter of the model EObject that can react on notifications of the EMF model. For this, subclasses may implement
  2. The page registers itself as an CommandStackListener on the editor's CommandStack to update actions on command stack changes.
  3. A FlyoutPaletteComposite is being created which uses the Preferences of the Plugin delivered by the parent editor.
  4. Some AbstractMultiViewerPage.MultiViewerPageViewers (depending on getNumberOfViewers()) are being created and added to the SelectionSynchronizer delivered by the parent editor. The objects returned by getViewerContents() are set as contents of these viewers.
  5. A Thumbnail showing a miniature overview of the current viewer is being installed below the palette.
  6. The first viewer is set as the current viewer.
  7. Actions are being created: ZoomInAction, ZoomOutAction and custom Actions in createActions(). Some standard handles for RetargetActions from the ActionFactory besides zooming and undo/redo are being registered if they have been created in createActions(): COPY, CUT, PASTE, DELETE.

A AbstractMultiViewerPage.MultiViewerPageViewer notices if a mouse click occurs on it and sets itself as the current viewer which performs the following updates:

  1. The clicked viewer is set as ISelectionProvider of the IPageSite.
  2. The page registers itself as an ISelectionChangedListener on the viewer to be able to update the UpdateActions in its ActionRegistry on selection changes.
  3. The viewer is set as selection provider for all SelectionActions in the ActionRegistry.
  4. The Thumbnail is being configured to show the new current viewer.
  5. The ZoomManager of the clicked viewer is set as delegating target in the ZoomManagerDelegate.
Ths contents of an existing viewer may be replaced with another object via setViewersContents(int, EObject).

These methods have to be implemented by subclasses:

Author:
Tony Modica

Nested Class Summary
 class AbstractMultiViewerPage.MultiViewerPageViewer
          This local class extends ScrollingGraphicalViewer by a MouseListener that sets this viewer as the page's current viewer when a mouse click occurs on this viewer.
 
Nested classes/interfaces inherited from interface org.eclipse.emf.common.notify.Adapter
org.eclipse.emf.common.notify.Adapter.Internal
 
Field Summary
private  org.eclipse.gef.ui.actions.ActionRegistry actionRegistry
          The action registry that hold the actions for this page.
private  AbstractMultiViewerPage.MultiViewerPageViewer currentViewer
          The viewer that is showed in the Thumbnail, the current ISelectionProvider for this page's IPageSite and providing a ZoomManager for the zoom actions via a ZoomManagerDelegate.
private  org.eclipse.gef.EditDomain editDomain
          The EditDomain managing this page like an encapsulated editor.
private  org.eclipse.ui.IEditorPart editor
          The editor that requested to display the model.
private  org.eclipse.gef.ui.palette.FlyoutPaletteComposite flyoutPaletteComposite
          The main Control of this page.
private  org.eclipse.gef.KeyHandler keyHandler
          A shared KeyHandler for the viewers on this page.
private  org.eclipse.emf.ecore.EObject model
          The model which is shown in the viewer.
private  SelectionProviderIntermediate selectionProvider
          This enables this page to switch the actual selection-providing viewer
private  org.eclipse.emf.common.notify.Notifier target
          Target field for Adapter implementation.
private  org.eclipse.draw2d.parts.ScrollableThumbnail thumbnail
          A thumbnail showing a miniature of what the viewer contains.
private  AbstractMultiViewerPage.MultiViewerPageViewer[] viewers
          An array of the viewers hosted by this page.
private  ZoomManagerDelegate zoomManagerDelegate
          This subclassed ZoomManager is set for the zoom actions and the returned by getAdapter(Class) for the ZoomComboContributionItem created in the ActionBarContributor.
 
Constructor Summary
protected AbstractMultiViewerPage(org.eclipse.emf.ecore.EObject model, org.eclipse.ui.IEditorPart editor)
           
 
Method Summary
 void commandStackChanged(java.util.EventObject event)
          If some command manipulates the model the actions are updated so that actions are not only updated if a selection change occurs.
protected abstract  void createActions()
          To be implemented by subclasses.
protected abstract  ContextMenuProviderWithActionRegistry createContextMenuProvider(org.eclipse.gef.EditPartViewer viewer)
          Subclasses must implement to specify the ContextMenuProviderWithActionRegistry that should be used by this page's GraphicalViewers and is responsible to show the created actions in the context menu.
 void createControl(org.eclipse.swt.widgets.Composite parent)
          This method creates all the visual parts and configures them: A FlyoutPaletteComposite is created and associated with the Preferences of the editor's Plugin.
protected abstract  org.eclipse.gef.EditPartFactory createEditPartFactory()
          Subclasses must implement to specify the EditPartFactory that should be used by this page's GraphicalViewers.
private  org.eclipse.swt.widgets.Composite createGraphicalViewerComposite()
          This method creates an configures some AbstractMultiViewerPage.MultiViewerPageViewer according to getNumberOfViewers() and adds them to a SashForm: For each newly created graphical viewer the shared editDomain is set, a shared KeyHandler (configured via setupKeyHandler(KeyHandler)) is set, it is registered with the editor's SelectionSynchronizer, a shared EditPartFactory returned by createEditPartFactory() is set, a unique ContextMenuProviderWithActionRegistry returned by createContextMenuProvider(EditPartViewer), an object of the array getViewerContents() returns is set as the contents of the viewers.
protected abstract  org.eclipse.gef.palette.PaletteRoot createPaletteRoot()
          Subclasses must implement to specify the PaletteRoot that should be used by this page's EditDomain and which defines the contents of the palette.
 void dispose()
          Unhooks the model, removes viewers from the editor's SelectionSynchronizer and deregisters this page as currentViewer's ISelectionChangedListener and deactivates the thumbnail.
protected  org.eclipse.gef.ui.actions.ActionRegistry getActionRegistry()
           
 java.lang.Object getAdapter(java.lang.Class adapter)
          Extended to provide zoomManagerDelegate as ZoomManager.
 org.eclipse.swt.widgets.Control getControl()
           
private  org.eclipse.gef.EditDomain getEditDomain()
           
 org.eclipse.ui.IEditorPart getEditor()
           
protected  org.eclipse.gef.KeyHandler getKeyHandler()
           
 org.eclipse.emf.ecore.EObject getModel()
           
abstract  int getNumberOfViewers()
           
private  org.eclipse.gef.ui.parts.SelectionSynchronizer getSelectionSynchronizer()
           
 org.eclipse.jface.action.IStatusLineManager getStatusLineManager()
          This can be used to display messages in this page's status line.
 org.eclipse.emf.common.notify.Notifier getTarget()
           
protected abstract  int[] getThumbSashWeights()
          The two values in the returned array specify how the flyout composite's space is being divided between the palette entries and the thumbnail in the palette.
 org.eclipse.jface.action.IToolBarManager getToolBarManager()
          This can be used to add actions to this page's tool bar.
abstract  org.eclipse.emf.ecore.EObject[] getViewerContents()
          The viewer's are arranged horizontal and will be showing these objects in the order of the returned array from left to right.
protected  AbstractMultiViewerPage.MultiViewerPageViewer[] getViewers()
          Method to get the array of viewers if needed to implement advanced editor features.
 org.eclipse.emf.ecore.EObject getViewersContents(int viewerPosition)
          A method to access the object which is being displayed in a specific viewer.
 void init(org.eclipse.ui.part.IPageSite pageSite)
          Hooks into the model.
private  void installActions()
          Creates and registers actions.
private  void installThumbnailInPalette()
          Creates a Thumbnail on the Control of this page's PaletteViewer.
 boolean isAdapterForType(java.lang.Object type)
           
protected  void registerHandleForEditorAction(java.lang.String id)
          Registers an Action as a handler for a RetargetAction.
 void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
          If a selection change occurs in the current viewer the UpdateActions in the ActionRegistry are being updated.
protected  void setCurrentViewer(AbstractMultiViewerPage.MultiViewerPageViewer viewer)
          This method sets the current graphical viewer of this page which implies that the passed viewer will be shown in the Thumbnail, becomes the current ISelectionProvider for this page's IPageSite and provides the ZoomManager for the zoom actions the ZoomManagerDelegate delegates to.
 void setFocus()
          Sets focus to a part in the page.
 void setTarget(org.eclipse.emf.common.notify.Notifier newTarget)
           
protected abstract  void setupKeyHandler(org.eclipse.gef.KeyHandler kh)
          Subclasses must implement to associate KeyStrokes with Actions in the passed KeyHandler} which is the one used for the GraphicalViewers.
 void setViewersContents(int viewerPosition, org.eclipse.emf.ecore.EObject model)
          A method to set a new object to be displayed in a specific viewer.
 void switchViewerVisibility(int viewerPosition)
          This method inverts the visibility of a viewer's control and relayouts the SashForm that the visible viewers on it share the remaining space.
protected  void updateActions()
          Updates all UpdateActions registered in the actionRegistry.
 
Methods inherited from class org.eclipse.ui.part.Page
getSite, makeContributions, setActionBars
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.eclipse.emf.common.notify.Adapter
notifyChanged
 

Field Detail

actionRegistry

private final org.eclipse.gef.ui.actions.ActionRegistry actionRegistry
The action registry that hold the actions for this page.


flyoutPaletteComposite

private org.eclipse.gef.ui.palette.FlyoutPaletteComposite flyoutPaletteComposite
The main Control of this page.


editor

private final org.eclipse.ui.IEditorPart editor
The editor that requested to display the model.


viewers

private final AbstractMultiViewerPage.MultiViewerPageViewer[] viewers
An array of the viewers hosted by this page. Its length is specified by getNumberOfViewers().


currentViewer

private AbstractMultiViewerPage.MultiViewerPageViewer currentViewer
The viewer that is

See Also:
setCurrentViewer(roneditor.AbstractMultiViewerPage.MultiViewerPageViewer)

thumbnail

private org.eclipse.draw2d.parts.ScrollableThumbnail thumbnail
A thumbnail showing a miniature of what the viewer contains.


editDomain

private org.eclipse.gef.EditDomain editDomain
The EditDomain managing this page like an encapsulated editor.


model

private final org.eclipse.emf.ecore.EObject model
The model which is shown in the viewer.


target

private org.eclipse.emf.common.notify.Notifier target
Target field for Adapter implementation.


zoomManagerDelegate

private final ZoomManagerDelegate zoomManagerDelegate
This subclassed ZoomManager is set for the zoom actions and the returned by getAdapter(Class) for the ZoomComboContributionItem created in the ActionBarContributor. It delegates to the ZoomManager of currentViewer.


selectionProvider

private final SelectionProviderIntermediate selectionProvider
This enables this page to switch the actual selection-providing viewer


keyHandler

private org.eclipse.gef.KeyHandler keyHandler
A shared KeyHandler for the viewers on this page.

Constructor Detail

AbstractMultiViewerPage

protected AbstractMultiViewerPage(org.eclipse.emf.ecore.EObject model,
                                  org.eclipse.ui.IEditorPart editor)
Parameters:
model - The model element to be displayed in this page's GraphicalViewer.
editor - The editor that requested the model to be displayed.
Method Detail

getModel

public org.eclipse.emf.ecore.EObject getModel()
Returns:
The model passed in the constructor.

init

public void init(org.eclipse.ui.part.IPageSite pageSite)
Hooks into the model.

Specified by:
init in interface org.eclipse.ui.part.IPageBookViewPage
Overrides:
init in class org.eclipse.ui.part.Page

installActions

private void installActions()
Creates and registers actions. Handle actions for some standard RetargetActions are set:

Except for zoom, undo, and redo, these handles have to be created by subclasses via createActions() and with appropriate IDs.


createActions

protected abstract void createActions()
To be implemented by subclasses. Actions have to be registered via getActionRegistry().
WorkbenchPartActions should get the editor (getEditor()) as workbench part in their constructor.
To register actions as handles for RetargetActions you may use registerHandleForEditorAction(String) with a string that matches both the RetargetAction's and the handle's ID.

In setCurrentViewer(roneditor.AbstractMultiViewerPage.MultiViewerPageViewer) the currentViewer will be set with SelectionAction.setSelectionProvider(ISelectionProvider) for SelectionActions.

See Also:
to find out which actions will be created by default.

registerHandleForEditorAction

protected void registerHandleForEditorAction(java.lang.String id)
Registers an Action as a handler for a RetargetAction. This has to be done only once since PageBookView.partActivated(org.eclipse.ui.IWorkbenchPart) takes care about refreshing the global action handlers for the ViewSite with the global action handlers defined for the SubActionBars of this IPageSite.


createControl

public void createControl(org.eclipse.swt.widgets.Composite parent)
This method creates all the visual parts and configures them:
  1. A FlyoutPaletteComposite is created and associated with the Preferences of the editor's Plugin.
  2. With createGraphicalViewerComposite() a composite hosting the AbstractMultiViewerPage.MultiViewerPageViewers is being created and set as graphical control for the flyoutPaletteComposite.
  3. The Thumbnail is being created with installThumbnailInPalette().
  4. The first viewer in viewers is set with setCurrentViewer(roneditor.AbstractMultiViewerPage.MultiViewerPageViewer).
  5. Actions are being created via installActions().

Specified by:
createControl in interface org.eclipse.ui.part.IPage
Specified by:
createControl in class org.eclipse.ui.part.Page

getEditDomain

private org.eclipse.gef.EditDomain getEditDomain()
Returns:
A lazily created EditDomain with slightly modified selection behaviour.

createPaletteRoot

protected abstract org.eclipse.gef.palette.PaletteRoot createPaletteRoot()
Subclasses must implement to specify the PaletteRoot that should be used by this page's EditDomain and which defines the contents of the palette.

Returns:
The PaletteRoot for the EditDomain of this page.

installThumbnailInPalette

private void installThumbnailInPalette()
Creates a Thumbnail on the Control of this page's PaletteViewer.

See Also:
getThumbSashWeights()

getThumbSashWeights

protected abstract int[] getThumbSashWeights()
The two values in the returned array specify how the flyout composite's space is being divided between the palette entries and the thumbnail in the palette. When implementing this template should be used:
return new int[] { Palette_Weight, Thumb_Weight };

Returns:
An array of 2 integers describing the ratio of the palette to the thumbnail.

createGraphicalViewerComposite

private org.eclipse.swt.widgets.Composite createGraphicalViewerComposite()
This method creates an configures some AbstractMultiViewerPage.MultiViewerPageViewer according to getNumberOfViewers() and adds them to a SashForm:

For each newly created graphical viewer

  1. the shared editDomain is set,
  2. a shared KeyHandler (configured via setupKeyHandler(KeyHandler)) is set,
  3. it is registered with the editor's SelectionSynchronizer,
  4. a shared EditPartFactory returned by createEditPartFactory() is set,
  5. a unique ContextMenuProviderWithActionRegistry returned by createContextMenuProvider(EditPartViewer),
  6. an object of the array getViewerContents() returns is set as the contents of the viewers. This depends on the viewers' position.
  7. The ZoomManager of the viewer is configured with some zoom levels.

Returns:
The SashForm composite holding all the viewers.

getKeyHandler

protected org.eclipse.gef.KeyHandler getKeyHandler()
Returns:
A lazily created shared KeyHandler for the viewers on this page.

getNumberOfViewers

public abstract int getNumberOfViewers()
Returns:
The number of viewers that shall be created on this page.
See Also:
getViewerContents(), createGraphicalViewerComposite()

getViewerContents

public abstract org.eclipse.emf.ecore.EObject[] getViewerContents()
The viewer's are arranged horizontal and will be showing these objects in the order of the returned array from left to right. The length of the array has to be exactly the value of getNumberOfViewers()!

Returns:
The objects that will be set as contents in each of viewers.
See Also:
setViewersContents(int, EObject), createGraphicalViewerComposite()

getViewersContents

public org.eclipse.emf.ecore.EObject getViewersContents(int viewerPosition)
A method to access the object which is being displayed in a specific viewer.

Parameters:
viewerPosition - the position (starting with 0) of the viewer
Returns:
the model of the top edit part of viewers[viewerPosition]
See Also:
setViewersContents(int, EObject)

setViewersContents

public void setViewersContents(int viewerPosition,
                               org.eclipse.emf.ecore.EObject model)
A method to set a new object to be displayed in a specific viewer.

Parameters:
viewerPosition - the position (starting with 0) of the viewer
See Also:
getViewerContents()

switchViewerVisibility

public void switchViewerVisibility(int viewerPosition)
This method inverts the visibility of a viewer's control and relayouts the SashForm that the visible viewers on it share the remaining space.

Parameters:
viewerPosition - the position (starting with 0) of the viewer

setupKeyHandler

protected abstract void setupKeyHandler(org.eclipse.gef.KeyHandler kh)
Subclasses must implement to associate KeyStrokes with Actions in the passed KeyHandler} which is the one used for the GraphicalViewers.

See Also:
createGraphicalViewerComposite()

createContextMenuProvider

protected abstract ContextMenuProviderWithActionRegistry createContextMenuProvider(org.eclipse.gef.EditPartViewer viewer)
Subclasses must implement to specify the ContextMenuProviderWithActionRegistry that should be used by this page's GraphicalViewers and is responsible to show the created actions in the context menu.

Parameters:
viewer - The graphical viewer for context menu provider
Returns:
The ContextMenuProviderWithActionRegistry for the specified GraphicalViewer.
See Also:
createGraphicalViewerComposite()

createEditPartFactory

protected abstract org.eclipse.gef.EditPartFactory createEditPartFactory()
Subclasses must implement to specify the EditPartFactory that should be used by this page's GraphicalViewers.

Returns:
The EditPartFactory for the GraphicalViewers of this page.
See Also:
createGraphicalViewerComposite()

getSelectionSynchronizer

private org.eclipse.gef.ui.parts.SelectionSynchronizer getSelectionSynchronizer()
Returns:
The editor's SelectionSynchronizer

dispose

public void dispose()
Unhooks the model, removes viewers from the editor's SelectionSynchronizer and deregisters this page as currentViewer's ISelectionChangedListener and deactivates the thumbnail.

Specified by:
dispose in interface org.eclipse.ui.part.IPage
Overrides:
dispose in class org.eclipse.ui.part.Page

getControl

public org.eclipse.swt.widgets.Control getControl()
Specified by:
getControl in interface org.eclipse.ui.part.IPage
Specified by:
getControl in class org.eclipse.ui.part.Page

setFocus

public void setFocus()
Sets focus to a part in the page.

Specified by:
setFocus in interface org.eclipse.ui.part.IPage
Specified by:
setFocus in class org.eclipse.ui.part.Page

selectionChanged

public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent event)
If a selection change occurs in the current viewer the UpdateActions in the ActionRegistry are being updated.

Specified by:
selectionChanged in interface org.eclipse.jface.viewers.ISelectionChangedListener

updateActions

protected void updateActions()
Updates all UpdateActions registered in the actionRegistry.


getAdapter

public java.lang.Object getAdapter(java.lang.Class adapter)
Extended to provide zoomManagerDelegate as ZoomManager.

Specified by:
getAdapter in interface org.eclipse.core.runtime.IAdaptable

getActionRegistry

protected org.eclipse.gef.ui.actions.ActionRegistry getActionRegistry()
Returns:
the actionRegistry

getEditor

public org.eclipse.ui.IEditorPart getEditor()
Returns:
the editor

isAdapterForType

public boolean isAdapterForType(java.lang.Object type)
Specified by:
isAdapterForType in interface org.eclipse.emf.common.notify.Adapter

setTarget

public void setTarget(org.eclipse.emf.common.notify.Notifier newTarget)
Specified by:
setTarget in interface org.eclipse.emf.common.notify.Adapter

getTarget

public org.eclipse.emf.common.notify.Notifier getTarget()
Specified by:
getTarget in interface org.eclipse.emf.common.notify.Adapter

setCurrentViewer

protected void setCurrentViewer(AbstractMultiViewerPage.MultiViewerPageViewer viewer)
This method sets the current graphical viewer of this page which implies that the passed viewer Additionally the page sets the current viewer as selection provider for its SelectionActions by calling #updateSelectionActionsProvider() and registers itself as an ISelectionChangedListener on the new current viewer to be able to update its UpdateActions

Parameters:
viewer -

getViewers

protected AbstractMultiViewerPage.MultiViewerPageViewer[] getViewers()
Method to get the array of viewers if needed to implement advanced editor features.

To set new contents for a viewer setViewersContents(int, EObject) should be used!

Returns:
the viewers
See Also:
setViewersContents(int, EObject)

getStatusLineManager

public org.eclipse.jface.action.IStatusLineManager getStatusLineManager()
This can be used to display messages in this page's status line.

Returns:
The IStatusLineManager from the IActionBars of this page's IPageSite

getToolBarManager

public org.eclipse.jface.action.IToolBarManager getToolBarManager()
This can be used to add actions to this page's tool bar.

Returns:
The IToolBarManager from the IActionBars of this page's IPageSite

commandStackChanged

public void commandStackChanged(java.util.EventObject event)
If some command manipulates the model the actions are updated so that actions are not only updated if a selection change occurs.

Specified by:
commandStackChanged in interface org.eclipse.gef.commands.CommandStackListener