org.eclipse.graphiti.ui.editor
Class DiagramEditor

java.lang.Object
  extended by GraphicalEditorWithFlyoutPalette
      extended by org.eclipse.graphiti.ui.editor.DiagramEditor
All Implemented Interfaces:
IDiagramEditor

public class DiagramEditor
extends GraphicalEditorWithFlyoutPalette
implements IDiagramEditor

This is the main class for the Graphiti diagram editor. It represents the editor to Eclipse and therefore implements IEditorPart. The implementation is based upon a GEF editor implementation ( GraphicalEditorWithFlyoutPalette) and enhances it with Graphiti-specific stuff.
This editor is registered as an Eclipse editor using the extension point org.eclipse.ui.editors. Therefore the Eclipse standard methods can be used to open a new diagram editor. The associated IEditorInput object is a subclass of DiagramEditorInput, but using another type of input is also ok as long as it can be adapted to an IFile that can be reolved within the workspace of is a URIEditorInput. These types of input objects will be converted to a corresponding DiagramEditorInput when the editor is initialized (see init(IEditorSite, IEditorInput)).
Any clients extending this class should also contribute their editor to the Eclipse editor extension point to gain full advantage of the Eclipse editor integration of Graphiti.
There are a lot of aspects this class needs to deal with; the larger aspects are separated into other classes which share the lifecycle with the DiagramEditor instance. This means they are instantiated when a new diagram editor is created and exist until the editor is closed again. There are default implementations for all of these aspects, see the Default*Behavior classes in this package. The following aspects are separated:

All the other aspects are dealt with directly within this class. One of the larger aspects implemented here is selection handling, which would have been awkward if separated out.


Field Summary
private  IConfigurationProvider configurationProvider
           
private  java.lang.String contributorId
           
static java.lang.String DIAGRAM_EDITOR_ID
          The ID of the DiagramEditor as it is registed with the org.eclipse.ui.editors extension point.
private  DiagramChangeListener diagramChangeListener
           
private  DiagramScrollingBehavior diagramScrollingBehavior
           
private  boolean directEditingActive
           
private  DomainModelChangeListener domainModelListener
           
private  java.lang.String editorInitializationError
           
private  CommandStackEventListener gefCommandStackListener
           
private  KeyHandler keyHandler
           
private  DefaultMarkerBehavior markerBehavior
           
private  Point mouseLocation
           
private  DefaultPaletteBehavior paletteBehaviour
           
private  DefaultPersistencyBehavior persistencyBehavior
           
private  PictogramElement[] pictogramElementsForSelection
           
private  DefaultRefreshBehavior refreshBehavior
           
private  DefaultUpdateBehavior updateBehavior
           
 
Constructor Summary
DiagramEditor()
          Creates a new diagram editor and cares about the creation of the different behavior extensions by delegating to the various create*Behavior() methods.
 
Method Summary
 Point calculateRealMouseLocation(Point nativeLocation)
          Calculates the mouse location depending on scrollbars and zoom factor.
protected  void configureGraphicalViewer()
          Called to configure the editor, before it receives its content.
protected  DiagramEditorInput convertToDiagramEditorInput(IEditorInput input)
          Is called by the init(IEditorSite, IEditorInput) method in case the IEditorInput instance passed is no DiagramEditorInput .
protected  ContextMenuProvider createContextMenuProvider()
          Returns a new ContextMenuProvider.
private  void createErrorPartControl(Composite parent)
           
protected  void createGraphicalViewer(Composite parent)
          Creates the GraphicalViewer on the specified Composite and initializes it.
protected  DefaultMarkerBehavior createMarkerBehavior()
          Creates the behavior extension that deals with markers.
protected  DefaultPaletteBehavior createPaletteBehaviour()
          Creates the behavior extension that deals with the palette handling.
protected  PaletteViewerProvider createPaletteViewerProvider()
          Delegates to the method (or the method in a subclass of) #createPaletteViewerProvider() to create the PaletteViewerProvider used inside the GEF editor.
 void createPartControl(Composite parent)
          Creates the UI of the editor by delegating to the super.createPartControl method.
protected  DefaultPersistencyBehavior createPersistencyBehavior()
          Creates the behavior extension that deals with the persistence handling.
protected  DefaultRefreshBehavior createRefreshBehavior()
          Creates the behavior extension that deals with the refresh handling.
protected  DefaultUpdateBehavior createUpdateBehavior()
          Creates the behavior extension that deals with the update handling.
 void disableAdapters()
          Should be called (e.g.
 void dispose()
          Disposes this DiagramEditor instance and frees all used resources and clears all references.
 void doSave(IProgressMonitor monitor)
          Called to perform the saving of the editor.
 void editingDomainInitialized()
          Hook that is called by the holder of the TransactionalEditingDomain (DefaultUpdateBehavior or a subclass of it) after the editing domain has been initialized.
 void enableAdapters()
          Should be called by the various behavior instances after mass EMF resource operations have been triggered (e.g.
 java.lang.Object executeFeature(IFeature feature, IContext context)
          Executes the given IFeature with the given IContext in the scope of this DiagramEditor, meaning within its TransactionalEditingDomain and on its CommandStack.
 java.lang.Object getAdapter(java.lang.Class type)
          Implements the Eclipse IAdaptable interface.
protected  KeyHandler getCommonKeyHandler()
          Returns the KeyHandler with common bindings to be used for both the Outline and the Graphical Viewer.
protected  IConfigurationProvider getConfigurationProvider()
          Returns the IConfigurationProvider instance used with this editor; the interface provides access to most of the Graphiti editor description means like IDiagramTypeProvider and IToolBehaviorProvider.
 EditPart getContentEditPart()
          Returns the contents EditPart of this Editor.
 java.lang.String getContributorId()
          Returns the ID for contributions in the tabbed property sheets by delegating to the method IToolBehaviorProvider.getContributorId() .
private  DiagramScrollingBehavior getDiagramScrollingBehavior()
          Deprecated. Scroll bar based infinite canvas is a workaround for GEF limitations.
 IDiagramTypeProvider getDiagramTypeProvider()
          Returns the IDiagramTypeProvider instance associated with this DiagramEditor.
 DefaultEditDomain getEditDomain()
          Returns the GEF edit domain as needed for some of the feature functionality in Graphiti; simply a public rewrite of the GEF editor super method.
 TransactionalEditingDomain getEditingDomain()
          Returns the EMF TransactionalEditingDomain used within this editor by delegating to the update behavior extension, by default DefaultUpdateBehavior.getEditingDomain().
 GraphicalEditPart getEditPartForPictogramElement(PictogramElement pe)
          Method to retrieve the GEF EditPart for a given PictogramElement.
private  FigureCanvas getFigureCanvas()
           
 IFigure getFigureForPictogramElement(PictogramElement pe)
          Method to retrieve the Draw2D IFigure for a given PictogramElement.
private  GFFigureCanvas getGFFigureCanvas()
           
 GraphicalViewer getGraphicalViewer()
          Returns the GEF GraphicalViewer as it is needed in some Graphiti feature implementations.
 Point getMouseLocation()
          Gets the current mouse location as a Point.
protected  FlyoutPreferences getPalettePreferences()
          Delegates to the method (or the method in a subclass of) DefaultPaletteBehavior.getPalettePreferences().
protected  PaletteRoot getPaletteRoot()
          Returns the PaletteRoot to use in the GEF editor by delegating to DefaultPaletteBehavior.getPaletteRoot().
protected  PictogramElement[] getPictogramElementsForSelection()
          Returns the PictogramElements that are set for later selection.
 DefaultRefreshBehavior getRefreshBehavior()
          Returns the instance of the refresh behavior that is used with this editor.
 ResourceSet getResourceSet()
          The EMF ResourceSet used within this DiagramEditor.
 PictogramElement[] getSelectedPictogramElements()
          Returns the PictogramElements that are currently selected in the diagram editor.
 java.lang.String getTitleToolTip()
          Returns the tooltip that shall be displayed when hovering over the editor title tab.
private  IToolBehaviorProvider getToolBehaviorProvider()
           
 DefaultUpdateBehavior getUpdateBehavior()
          Returns the instance of the update behavior that is used with this editor.
 double getZoomLevel()
          Returns the zoom level currently used in the editor.
 void init(IEditorSite site, IEditorInput input)
          Does the initialization of the editor.
protected  void initActionRegistry(ZoomManager zoomManager)
          Initializes the action registry with the predefined actions (update, remove, delete, copy, paste, zooming, direct editing, alignment and toggling actions for the diagram grip and hiding of the context button pad.
protected  void initializeGraphicalViewer()
          Called to initialize the editor with its content.
 boolean isAlive()
          Checks if this editor is alive.
 boolean isDirectEditingActive()
          Returns if direct editing is currently active for this editor.
 boolean isDirty()
          Returns if the editor is currently dirty and needs to be saved or not.
protected  void migrateDiagramModelIfNecessary()
          We provide migration from 0.8.0 to 0.9.0.
 void refresh()
          Triggers a complete refresh of the editor (content, title, tooltip, palette and decorators) by delegating to DefaultRefreshBehavior.refresh().
 void refreshContent()
          Refreshes the content of the editor (what's shown inside the diagram itself).
 void refreshPalette()
          Refreshes to palette to correctly reflect all available creation tools for the available create features and the currently enabled selection tools
 void refreshRenderingDecorators(PictogramElement pe)
          Refreshes the rendering decorators (image decorators and the like) by delegating to DefaultRefreshBehavior.refreshRenderingDecorators(PictogramElement) for the given PictogramElement.
 void refreshTitle()
          Refreshes the editor title to show the name of the diagram
 void refreshTitleToolTip()
          Refreshes the tooltip displayed for the editor title tab according to what is returned in getTitleToolTip().
protected  void registerAction(IAction action)
          Registers the given action with the Eclipse ActionRegistry.
protected  void registerBusinessObjectsListener()
          Hook that is called to register listeners for changes of the business objects (domain objects) in the resource set of the editor.
protected  void registerDiagramResourceSetListener()
          Hook to register listeners for diagram changes.
 void selectBufferedPictogramElements()
          Triggers the selection for the PictogramElements that are stored for later selection.
 void selectionChanged(IWorkbenchPart part, ISelection selection)
          Handles a selection changed event that is triggered by any selection source, e.g.
 void selectPictogramElements(PictogramElement[] pictogramElements)
          Selects the given PictogramElements in the diagram.
private  void setConfigurationProvider(IConfigurationProvider configurationProvider)
           
 void setDirectEditingActive(boolean directEditingActive)
          Sets that direct editing is now active in the editor or not.
 void setFocus()
          Sets the focus by delegating to the super class implementation in the GEF editor and additionally triggers a update of the diagram by delegating to DefaultUpdateBehavior.handleActivate().
protected  void setInput(IEditorInput input)
          Sets the given IEditorInput object as the input for this editor.
private  void setMouseLocation(int x, int y)
           
 void setPictogramElementForSelection(PictogramElement pictogramElement)
          Sets one PictogramElement for later selection.
 void setPictogramElementsForSelection(PictogramElement[] pictogramElements)
          Sets PictogramElements for later selection.
protected  boolean shouldRegisterContextMenu()
          Allows subclasses to prevent that the diagram context menu should be registered for extensions at Eclipse.
protected  void unregisterBusinessObjectsListener()
          Hook that is called to unregister the listeners for changes of the business objects (domain objects).
protected  void unregisterDiagramResourceSetListener()
          Hook to unregister the listeners for diagram changes.
 void updateDirtyState()
          Updates the UI to correctly reflect the dirty state of the editor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIAGRAM_EDITOR_ID

public static final java.lang.String DIAGRAM_EDITOR_ID
The ID of the DiagramEditor as it is registed with the org.eclipse.ui.editors extension point.

See Also:
Constant Field Values

updateBehavior

private final DefaultUpdateBehavior updateBehavior

paletteBehaviour

private final DefaultPaletteBehavior paletteBehaviour

persistencyBehavior

private final DefaultPersistencyBehavior persistencyBehavior

markerBehavior

private final DefaultMarkerBehavior markerBehavior

refreshBehavior

private final DefaultRefreshBehavior refreshBehavior

gefCommandStackListener

private CommandStackEventListener gefCommandStackListener

diagramChangeListener

private DiagramChangeListener diagramChangeListener

domainModelListener

private DomainModelChangeListener domainModelListener

diagramScrollingBehavior

private DiagramScrollingBehavior diagramScrollingBehavior

pictogramElementsForSelection

private PictogramElement[] pictogramElementsForSelection

contributorId

private java.lang.String contributorId

configurationProvider

private IConfigurationProvider configurationProvider

keyHandler

private KeyHandler keyHandler

mouseLocation

private Point mouseLocation

directEditingActive

private boolean directEditingActive

editorInitializationError

private java.lang.String editorInitializationError
Constructor Detail

DiagramEditor

public DiagramEditor()
Creates a new diagram editor and cares about the creation of the different behavior extensions by delegating to the various create*Behavior() methods.

Method Detail

createMarkerBehavior

protected DefaultMarkerBehavior createMarkerBehavior()
Creates the behavior extension that deals with markers. See DefaultMarkerBehavior for details and the default implementation. Override to change the marker behavior.

Returns:
a new instance of DefaultMarkerBehavior
Since:
0.9

createUpdateBehavior

protected DefaultUpdateBehavior createUpdateBehavior()
Creates the behavior extension that deals with the update handling. See DefaultUpdateBehavior for details and the default implementation. Override to change the update behavior.

Returns:
a new instance of DefaultUpdateBehavior
Since:
0.9

getUpdateBehavior

public final DefaultUpdateBehavior getUpdateBehavior()
Returns the instance of the update behavior that is used with this editor. To change the behavior override createUpdateBehavior().

Returns:
the used instance of the update behavior, by default a DefaultUpdateBehavior.
Since:
0.9

createPaletteBehaviour

protected DefaultPaletteBehavior createPaletteBehaviour()
Creates the behavior extension that deals with the palette handling. See DefaultPaletteBehavior for details and the default implementation. Override to change the palette behavior.

Returns:
a new instance of DefaultPaletteBehavior
Since:
0.9

createPersistencyBehavior

protected DefaultPersistencyBehavior createPersistencyBehavior()
Creates the behavior extension that deals with the persistence handling. See DefaultPersistencyBehavior for details and the default implementation. Override to change the persistence behavior.

Returns:
a new instance of DefaultPersistencyBehavior
Since:
0.9

createRefreshBehavior

protected DefaultRefreshBehavior createRefreshBehavior()
Creates the behavior extension that deals with the refresh handling. See DefaultRefreshBehavior for details and the default implementation. Override to change the refresh behavior.

Returns:
a new instance of DefaultRefreshBehavior
Since:
0.9

getRefreshBehavior

public final DefaultRefreshBehavior getRefreshBehavior()
Returns the instance of the refresh behavior that is used with this editor. To change the behavior override createRefreshBehavior().

Returns:
the used instance of the refresh behavior, by default a DefaultRefreshBehavior.
Since:
0.9

editingDomainInitialized

public void editingDomainInitialized()
Hook that is called by the holder of the TransactionalEditingDomain (DefaultUpdateBehavior or a subclass of it) after the editing domain has been initialized. Can be used to e.g. register additional listeners on the domain.
The default implementation notifies the marker behavior extension to register its listeners.

Since:
0.9

disableAdapters

public void disableAdapters()
Should be called (e.g. by the various behavior instances) before mass EMF resource operations are triggered (e.g. saving all resources). Can be used to disable eventing for performance reasons. See enableAdapters() as well.
Important note: make sure that you re-enable eventing using enableAdapters() after the operation has finished (best in a finally clause to do that also in case of exceptions), otherwise strange errors may happen.

Since:
0.9

enableAdapters

public void enableAdapters()
Should be called by the various behavior instances after mass EMF resource operations have been triggered (e.g. saving all resources). Can be used to re-enable eventing after it was disabled for performance reasons. See disableAdapters() as well.
Must be called after disableAdapters() has been called and the operation has finshed (best in a finally clause to also enable the exception case), otherwise strange errors may occur within the editor.

Since:
0.9

init

public void init(IEditorSite site,
                 IEditorInput input)
          throws PartInitException
Does the initialization of the editor. The default implementation cares about:
  1. converting the passed IEditorInput to a DiagramEditorInput. In case this fails, a PartInitException is thrown.
  2. creating the editing domain by delegating to the update behavior extension, see DefaultUpdateBehavior.createEditingDomain() for details
  3. initializing the underlying GEF editor by delegating to super
  4. initializing the update behavior extension (the order is important here as this must happen after initializing the GEF editor!)
  5. triggering the migration of diagram data if necessary
Any clients overriding this method have to make sure that they they always call super.init(site, input).

Parameters:
site - the Eclipse IEditorSite that will host this editor
input - the editor input that shall be used. Note that this method will exchange the input instance in case it is no DiagramEditorInput.
Throws:
PartInitException
See Also:
org.eclipse.ui.IEditorPart#init(IEditorSite, IEditorInput)

convertToDiagramEditorInput

protected DiagramEditorInput convertToDiagramEditorInput(IEditorInput input)
                                                  throws PartInitException
Is called by the init(IEditorSite, IEditorInput) method in case the IEditorInput instance passed is no DiagramEditorInput . This method should try to convert the passed input object to a DiagramEditorInput or throw an PartInitException in case the conversion can (or should) not be done for any reason. The default implementation uses the EditorInputAdapter.adaptToDiagramEditorInput(IEditorInput) method to do the conversion. Clients may adapt to do additional conversions or to prohibit any conversion by simply throwing a PartInitException .

Parameters:
input - the original input
Returns:
a DiagramEditorInput corresponding to the passed input instance in case a conversion is possible. This method must not return null, otherwise the editor initialization will fail.
Throws:
PartInitException - in case the passed input object cannot or should not be converted to a DiagramEditorInput instance.
Since:
0.9

setInput

protected void setInput(IEditorInput input)
Sets the given IEditorInput object as the input for this editor. It must be of type DiagramEditorInput otherwise an IllegalArgumentException is thrown.
The default implementation here cares about loading the diagram from the EMF Resource the input points to, sets the ID of the IDiagramTypeProvider for the diagram given in the input, registers listeners (by delegating to registerDiagramResourceSetListener() and registerBusinessObjectsListener()) and does the refreshing of the editor UI.

Parameters:
input - the DiagramEditorInput instance to use within this editor.

initActionRegistry

protected void initActionRegistry(ZoomManager zoomManager)
Initializes the action registry with the predefined actions (update, remove, delete, copy, paste, zooming, direct editing, alignment and toggling actions for the diagram grip and hiding of the context button pad.

Parameters:
zoomManager - the GEF zoom manager to use
Since:
0.9

createPartControl

public void createPartControl(Composite parent)
Creates the UI of the editor by delegating to the super.createPartControl method. The default implementation here also registers the command stack listener to correctly reflect the dirty state of the editor.


createErrorPartControl

private void createErrorPartControl(Composite parent)

createGraphicalViewer

protected void createGraphicalViewer(Composite parent)
Creates the GraphicalViewer on the specified Composite and initializes it.

Parameters:
parent - the parent composite

initializeGraphicalViewer

protected void initializeGraphicalViewer()
Called to initialize the editor with its content. Here everything is done, which is dependent of the IConfigurationProvider.

See Also:
org.eclipse.gef.ui.parts.GraphicalEditorWithFlyoutPalette#initializeGraphicalViewer()

configureGraphicalViewer

protected void configureGraphicalViewer()
Called to configure the editor, before it receives its content. The default-implementation is for example doing the following: configure the ZoomManager, registering Actions... Here everything is done, which is independent of the IConfigurationProvider.

See Also:
org.eclipse.gef.ui.parts.GraphicalEditor#configureGraphicalViewer()

updateDirtyState

public void updateDirtyState()
Updates the UI to correctly reflect the dirty state of the editor. The default implementation does this by firing a IEditorPart#PROP_DIRTY property change.

Since:
0.9

doSave

public void doSave(IProgressMonitor monitor)
Called to perform the saving of the editor. The default implementation delegates to DefaultPersistencyBehavior.saveDiagram(IProgressMonitor).

Parameters:
monitor - the Eclipse progress monitor to report progress with.

isDirty

public boolean isDirty()
Returns if the editor is currently dirty and needs to be saved or not. The default implementation delegates to DefaultPersistencyBehavior.isDirty().

Specified by:
isDirty in interface IDiagramEditor
Returns:
true in case the editor is dirty, false otherwise.

createPaletteViewerProvider

protected final PaletteViewerProvider createPaletteViewerProvider()
Delegates to the method (or the method in a subclass of) #createPaletteViewerProvider() to create the PaletteViewerProvider used inside the GEF editor.

Returns:
the PaletteViewerProvider to use

getPalettePreferences

protected final FlyoutPreferences getPalettePreferences()
Delegates to the method (or the method in a subclass of) DefaultPaletteBehavior.getPalettePreferences(). To change the palette override the behavior there.

Returns:
the PaletteViewerProvider preferences to use.

getPaletteRoot

protected final PaletteRoot getPaletteRoot()
Returns the PaletteRoot to use in the GEF editor by delegating to DefaultPaletteBehavior.getPaletteRoot().

Returns:
the PaletteRoot to use

refreshPalette

public final void refreshPalette()
Refreshes to palette to correctly reflect all available creation tools for the available create features and the currently enabled selection tools

Specified by:
refreshPalette in interface IDiagramEditor
Since:
0.9

createContextMenuProvider

protected ContextMenuProvider createContextMenuProvider()
Returns a new ContextMenuProvider. Clients can return null, if no context-menu shall be displayed.

Returns:
A new instance of ContextMenuProvider.
Since:
0.9

shouldRegisterContextMenu

protected boolean shouldRegisterContextMenu()
Allows subclasses to prevent that the diagram context menu should be registered for extensions at Eclipse. By default others can provide extensions to the menu (default return value of this method is true). By returning false any extension of the context menu can be prevented.

For details see Bugzilla 345347 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=345347).

Returns:
true in case extensions shall be allowed (default), false otherwise.
Since:
0.9

registerDiagramResourceSetListener

protected void registerDiagramResourceSetListener()
Hook to register listeners for diagram changes. The listener will be notified with all events and has to filter for the ones regarding the diagram.
Note that additional listeners registered here should also be unregistered in unregisterDiagramResourceSetListener().

Since:
0.9

registerBusinessObjectsListener

protected void registerBusinessObjectsListener()
Hook that is called to register listeners for changes of the business objects (domain objects) in the resource set of the editor. The default implementation registers the DomainModelChangeListener.
Note that additional listeners registered here should also be unregistered in unregisterBusinessObjectsListener().

Since:
0.9

unregisterDiagramResourceSetListener

protected void unregisterDiagramResourceSetListener()
Hook to unregister the listeners for diagram changes.

Since:
0.9
See Also:
registerDiagramResourceSetListener()

unregisterBusinessObjectsListener

protected void unregisterBusinessObjectsListener()
Hook that is called to unregister the listeners for changes of the business objects (domain objects).

Since:
0.9
See Also:
registerBusinessObjectsListener()

refreshTitle

public void refreshTitle()
Refreshes the editor title to show the name of the diagram

Specified by:
refreshTitle in interface IDiagramEditor
Since:
0.9

refreshTitleToolTip

public void refreshTitleToolTip()
Refreshes the tooltip displayed for the editor title tab according to what is returned in getTitleToolTip().

Specified by:
refreshTitleToolTip in interface IDiagramEditor
Since:
0.9

refresh

public void refresh()
Triggers a complete refresh of the editor (content, title, tooltip, palette and decorators) by delegating to DefaultRefreshBehavior.refresh().

Specified by:
refresh in interface IDiagramEditor
Since:
0.9

refreshContent

public void refreshContent()
Refreshes the content of the editor (what's shown inside the diagram itself).

Since:
0.9

refreshRenderingDecorators

public void refreshRenderingDecorators(PictogramElement pe)
Refreshes the rendering decorators (image decorators and the like) by delegating to DefaultRefreshBehavior.refreshRenderingDecorators(PictogramElement) for the given PictogramElement.

Specified by:
refreshRenderingDecorators in interface IDiagramEditor
Parameters:
pe - the PictogramElement for which the decorators shall be refreshed.
Since:
0.9

getAdapter

public java.lang.Object getAdapter(java.lang.Class type)
Implements the Eclipse IAdaptable interface. This implementation first delegates to the IToolBehaviorProvider.getAdapter(Class) method and checks if something is returned. In case the return value is null it returns adapters for ZoomManager, IPropertySheetPage, Diagram, KeyHandler, SelectionSynchronizer and IContextButtonManager. It also delegates to the super implementation in GraphicalEditorWithFlyoutPalette#getAdapter(Class).

Parameters:
type - the type to which shall be adapted
Returns:
the adapter instance

dispose

public void dispose()
Disposes this DiagramEditor instance and frees all used resources and clears all references. Also delegates to all the behavior extensions to also free their resources (e.g. and most important is the TransactionalEditingDomain held by the DefaultPersistencyBehavior. Always delegate to super.dispose() in case you override this method!


setFocus

public void setFocus()
Sets the focus by delegating to the super class implementation in the GEF editor and additionally triggers a update of the diagram by delegating to DefaultUpdateBehavior.handleActivate().


getSelectedPictogramElements

public PictogramElement[] getSelectedPictogramElements()
Returns the PictogramElements that are currently selected in the diagram editor.

Specified by:
getSelectedPictogramElements in interface IDiagramEditor
Returns:
an array of PictogramElements.
Since:
0.9

selectionChanged

public void selectionChanged(IWorkbenchPart part,
                             ISelection selection)
Handles a selection changed event that is triggered by any selection source, e.g. a browser with "Link to Editor" enabled.
Checks if the currently active editor is a MultiPageEditorPart with an opened diagram editor inside, tries to find any PictogramElement for the objects in the selection and selects them in the diagram.
Note that in case of the CommonNavigator as event source, its editor linking mechanism must be enabled.

Parameters:
part - the source IWorkbenchPart that triggered the event
selection - the new selection (mostly a IStructuredSelection instance.
Since:
0.9

selectPictogramElements

public void selectPictogramElements(PictogramElement[] pictogramElements)
Selects the given PictogramElements in the diagram.

Specified by:
selectPictogramElements in interface IDiagramEditor
Parameters:
pictogramElements - an array of PictogramElements to select.
Since:
0.9

getPictogramElementsForSelection

protected PictogramElement[] getPictogramElementsForSelection()
Returns the PictogramElements that are set for later selection.

The methods getPictogramElementsForSelection(), setPictogramElementForSelection(PictogramElement), setPictogramElementsForSelection(PictogramElement[]) and selectBufferedPictogramElements() offer the possibility to use a deferred selection mechanism: via the setters, PictogramElements can be stored for a selection operation that is triggered lateron during a general refresh via the method selectBufferedPictogramElements(). This mechanism is used e.g. in the Graphiti framework in direct editing to restore the previous selection, but can also be used by clients.

Returns:
the PictogramElements stored for later selection
Since:
0.9

setPictogramElementForSelection

public void setPictogramElementForSelection(PictogramElement pictogramElement)
Sets one PictogramElement for later selection.

The methods getPictogramElementsForSelection(), setPictogramElementForSelection(PictogramElement), setPictogramElementsForSelection(PictogramElement[]) and selectBufferedPictogramElements() offer the possibility to use a deferred selection mechanism: via the setters, PictogramElements can be stored for a selection operation that is triggered lateron during a general refresh via the method selectBufferedPictogramElements(). This mechanism is used e.g. in the Graphiti framework in direct editing to restore the previous selection, but can also be used by clients.

Specified by:
setPictogramElementForSelection in interface IDiagramEditor
Parameters:
pictogramElement - the PictogramElement that shall be stored for later selection
Since:
0.9

setPictogramElementsForSelection

public void setPictogramElementsForSelection(PictogramElement[] pictogramElements)
Sets PictogramElements for later selection.

The methods getPictogramElementsForSelection(), setPictogramElementForSelection(PictogramElement), setPictogramElementsForSelection(PictogramElement[]) and selectBufferedPictogramElements() offer the possibility to use a deferred selection mechanism: via the setters, PictogramElements can be stored for a selection operation that is triggered lateron during a general refresh via the method selectBufferedPictogramElements(). This mechanism is used e.g. in the Graphiti framework in direct editing to restore the previous selection, but can also be used by clients.

Specified by:
setPictogramElementsForSelection in interface IDiagramEditor
Parameters:
pictogramElements - the PictogramElements that shall be stored for later selection
Since:
0.9

selectBufferedPictogramElements

public void selectBufferedPictogramElements()
Triggers the selection for the PictogramElements that are stored for later selection. Can be called e.g during a general refresh of the editor or after another operation needing another selection is finished (an example in the framework is direct editing).

The methods getPictogramElementsForSelection(), setPictogramElementForSelection(PictogramElement), setPictogramElementsForSelection(PictogramElement[]) and selectBufferedPictogramElements() offer the possibility to use a deferred selection mechanism: via the setters, PictogramElements can be stored for a selection operation that is triggered lateron during a general refresh via the method selectBufferedPictogramElements(). This mechanism is used e.g. in the Graphiti framework in direct editing to restore the previous selection, but can also be used by clients.

Since:
0.9

getMouseLocation

public Point getMouseLocation()
Gets the current mouse location as a Point.

Returns:
the mouse location
Since:
0.9

calculateRealMouseLocation

public Point calculateRealMouseLocation(Point nativeLocation)
Calculates the mouse location depending on scrollbars and zoom factor.

Parameters:
nativeLocation - the native location given as Point
Returns:
the Point of the real mouse location
Since:
0.9

setMouseLocation

private void setMouseLocation(int x,
                              int y)

getCommonKeyHandler

protected KeyHandler getCommonKeyHandler()
Returns the KeyHandler with common bindings to be used for both the Outline and the Graphical Viewer.

Returns:
The KeyHandler with common bindings for both the Outline and the Graphical Viewer.
Since:
0.9

getConfigurationProvider

protected IConfigurationProvider getConfigurationProvider()
Returns the IConfigurationProvider instance used with this editor; the interface provides access to most of the Graphiti editor description means like IDiagramTypeProvider and IToolBehaviorProvider.

Note however that the IConfigurationProvider interface is not part of the official API in Graphiti 0.9; so useing this method and the returned interface will result in compilation warnings. This issue will be resolved with Graphiti 0.10 where the interface is split into a public (being part of the API) and an internal part. For details see Bugzilla 383768.

Returns:
The instance of IConfigurationProvider that is used within this editor.
Since:
0.9

getContentEditPart

public EditPart getContentEditPart()
Returns the contents EditPart of this Editor. This is the topmost EditPart in the GraphicalViewer.

Returns:
The contents EditPart of this Editor.
Since:
0.9

getContributorId

public java.lang.String getContributorId()
Returns the ID for contributions in the tabbed property sheets by delegating to the method IToolBehaviorProvider.getContributorId() .

Returns:
the contributor id as a String
Since:
0.9

getDiagramScrollingBehavior

@Deprecated
private DiagramScrollingBehavior getDiagramScrollingBehavior()
Deprecated. Scroll bar based infinite canvas is a workaround for GEF limitations.

Gets the diagram scrolling behavior.

Returns:
the diagram scrolling behavior
Since:
0.9
See Also:
DefaultToolBehaviorProvider.getDiagramScrollingBehavior()

getDiagramTypeProvider

public IDiagramTypeProvider getDiagramTypeProvider()
Returns the IDiagramTypeProvider instance associated with this DiagramEditor. There is always a 1:1 relation between the editor and the provider.

Specified by:
getDiagramTypeProvider in interface IDiagramEditor
Returns:
the associated IDiagramTypeProvider instance.
Since:
0.9

getEditDomain

public DefaultEditDomain getEditDomain()
Returns the GEF edit domain as needed for some of the feature functionality in Graphiti; simply a public rewrite of the GEF editor super method.

Returns:
the DefaultEditDomain used in this editor
Since:
0.9
See Also:
GraphicalEditor#getEditDomain()

getEditPartForPictogramElement

public GraphicalEditPart getEditPartForPictogramElement(PictogramElement pe)
Method to retrieve the GEF EditPart for a given PictogramElement.

Parameters:
pe - the PictogramElement to retrieve the GEF representation for
Returns:
the GEF GraphicalEditPart that represents the given PictogramElement.
Since:
0.9

getFigureForPictogramElement

public IFigure getFigureForPictogramElement(PictogramElement pe)
Method to retrieve the Draw2D IFigure for a given PictogramElement.

Parameters:
pe - the PictogramElement to retrieve the Draw2D representation for
Returns:
the Draw2D IFigure that represents the given PictogramElement.
Since:
0.9

getFigureCanvas

private FigureCanvas getFigureCanvas()

getGFFigureCanvas

private GFFigureCanvas getGFFigureCanvas()

getGraphicalViewer

public GraphicalViewer getGraphicalViewer()
Returns the GEF GraphicalViewer as it is needed in some Graphiti feature implementations. This is simply a public rewrite of the according super method.

Returns:
the GraphicalViewer used within this editor instance
See Also:
GraphicalEditor#getGraphicalViewer()

getTitleToolTip

public java.lang.String getTitleToolTip()
Returns the tooltip that shall be displayed when hovering over the editor title tab.

Returns:
the tooltip as a String

getToolBehaviorProvider

private IToolBehaviorProvider getToolBehaviorProvider()

getZoomLevel

public double getZoomLevel()
Returns the zoom level currently used in the editor.

Returns:
the zoom level
Since:
0.9

migrateDiagramModelIfNecessary

protected void migrateDiagramModelIfNecessary()
We provide migration from 0.8.0 to 0.9.0. You can override if you want to migrate manually. WARNING: If your diagram is under version control, this method can cause a check out dialog to be opened etc.

Since:
0.9

isAlive

public boolean isAlive()
Checks if this editor is alive.

Returns:
true, if editor contains a model connector and a valid Diagram, false otherwise.
Since:
0.9

registerAction

protected void registerAction(IAction action)
Registers the given action with the Eclipse ActionRegistry.

Parameters:
action - the action to register
Since:
0.9

setConfigurationProvider

private void setConfigurationProvider(IConfigurationProvider configurationProvider)

isDirectEditingActive

public boolean isDirectEditingActive()
Returns if direct editing is currently active for this editor.

Returns:
true in case direct editing is currently active within this editor, false otherwise.
Since:
0.9

setDirectEditingActive

public void setDirectEditingActive(boolean directEditingActive)
Sets that direct editing is now active in the editor or not. Note that this flag set to true does not actually start direct editing it is simply an indication that prevents certain operations from running (e.g. refresh)

Parameters:
directEditingActive - true to set the flag to direct editing currently active, false otherwise.
Since:
0.9

getEditingDomain

public TransactionalEditingDomain getEditingDomain()
Returns the EMF TransactionalEditingDomain used within this editor by delegating to the update behavior extension, by default DefaultUpdateBehavior.getEditingDomain().

Specified by:
getEditingDomain in interface IDiagramEditor
Returns:
the TransactionalEditingDomain instance used in the editor
Since:
0.9

executeFeature

public java.lang.Object executeFeature(IFeature feature,
                                       IContext context)
Executes the given IFeature with the given IContext in the scope of this DiagramEditor, meaning within its TransactionalEditingDomain and on its CommandStack.

Specified by:
executeFeature in interface IDiagramEditor
Parameters:
feature - the feature to execute
context - the context to use. In case the passed feature is a IAddFeature this context needs to be an instance of IAddContext, otherwise an AssertionFailedException will be thrown.
Returns:
in case of an IAddFeature being passed as feature the newly added PictogramElement will be returned (in case the add method returning it), in all other cases null
Since:
0.9

getResourceSet

public ResourceSet getResourceSet()
The EMF ResourceSet used within this DiagramEditor. The resource set is always associated in a 1:1 releation to the TransactionalEditingDomain.

Specified by:
getResourceSet in interface IDiagramEditor
Returns:
the resource set used within this editor
Since:
0.9


Copyright (c) SAP AG 2005, 2012.