de.cau.cs.kieler.core.model.graphiti.ui
Class AbstractInitGraphitiDiagramHandler

java.lang.Object
  extended by org.eclipse.core.commands.common.EventManager
      extended by org.eclipse.core.commands.AbstractHandler
          extended by de.cau.cs.kieler.core.model.handlers.AbstractInitDiagramHandler
              extended by de.cau.cs.kieler.core.model.graphiti.ui.AbstractInitGraphitiDiagramHandler
All Implemented Interfaces:
IHandler, IHandler2

public abstract class AbstractInitGraphitiDiagramHandler
extends AbstractInitDiagramHandler

Abstract super class for commands that initialize any graphiti diagram.

Rating red

Constructor Summary
AbstractInitGraphitiDiagramHandler(String diagramTypeNameParam, int gridSizeParam, boolean snapToGridParam)
          Creates a new AbstractReInitGraphitiDiagramCommand.
 
Method Summary
protected  boolean addChildrenRecursively(EObject eObj)
          If true all contained elements will be added recursively.
 void alignBoxRelativeAnchors(org.eclipse.graphiti.mm.pictograms.AnchorContainer ac)
          Align the BoxRelativeAnchors on one container to a sensible position.
 void alignBoxRelativeAnchors(org.eclipse.graphiti.mm.pictograms.AnchorContainer ac, de.cau.cs.kieler.core.model.graphiti.ui.AbstractInitGraphitiDiagramHandler.LayoutDirection dir)
          Align the BoxRelativeAnchors according to the layout direction.
protected  void alignPortsOnSide(List<org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor> ports, de.cau.cs.kieler.core.model.graphiti.ui.AbstractInitGraphitiDiagramHandler.LayoutDirection side)
          Distribute the ports equally on the specified side.
protected  TransactionalEditingDomain createEditingDomain()
          Create a new transactional editing domain.
 IEditorPart createNewDiagram(EObject modelRootParam, TransactionalEditingDomain editingDomain, IFile diagramFile, IProgressMonitor monitor)
          Create a new diagram file from the given semantics model.
protected  void determineSideForAnchors(List<org.eclipse.graphiti.mm.pictograms.Anchor> anchors, List<org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor> inPorts, List<org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor> outPorts)
          Determine on which side to place a port.
protected  org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm findVisibleGa(org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm graphicsAlgorithm)
          Find a visible GraphicsAlgorithm to stick the ports on.
protected abstract  EObject getConnectionSource(EObject connection)
          Get the source element of a connection.
protected abstract  EObject getConnectionTarget(EObject connection)
          Get the target element for a connection.
protected abstract  String getEditorId()
          Getter for the editor id.
protected abstract  boolean isConnection(EObject eObj)
          The given domain model element represents a connection which should be dealt with after all other elements are added.
protected  void linkModelToDiagram(org.eclipse.graphiti.ui.editor.DiagramEditor editor)
          Link the model to the newly created diagram inside the editor.
protected  org.eclipse.graphiti.features.context.impl.AddConnectionContext processConnection(Map<EObject,org.eclipse.graphiti.mm.pictograms.PictogramElement> elementsParam, EObject connection)
          Process a single connection.
 
Methods inherited from class de.cau.cs.kieler.core.model.handlers.AbstractInitDiagramHandler
execute, getDiagramExtension, initializeDiagram, openDiagram, performPostOperationAction, performPreOperationActions, refreshWorkspace, reinitialize
 
Methods inherited from class org.eclipse.core.commands.AbstractHandler
addHandlerListener, dispose, fireHandlerChanged, hasListeners, isEnabled, isHandled, removeHandlerListener, setBaseEnabled, setEnabled
 
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractInitGraphitiDiagramHandler

public AbstractInitGraphitiDiagramHandler(String diagramTypeNameParam,
                                          int gridSizeParam,
                                          boolean snapToGridParam)
Creates a new AbstractReInitGraphitiDiagramCommand.

Parameters:
diagramTypeNameParam - the name
gridSizeParam - the grid size
snapToGridParam - true if it should snap to grid
Method Detail

getEditorId

protected abstract String getEditorId()
Getter for the editor id.

Returns:
the id

createEditingDomain

protected TransactionalEditingDomain createEditingDomain()
Create a new transactional editing domain. For GMF this is done using
   GMFEditingDomainFactory.INSTANCE.createEditingDomain()
 

Specified by:
createEditingDomain in class AbstractInitDiagramHandler
Returns:
a new transactional editing domain

createNewDiagram

public IEditorPart createNewDiagram(EObject modelRootParam,
                                    TransactionalEditingDomain editingDomain,
                                    IFile diagramFile,
                                    IProgressMonitor monitor)
Create a new diagram file from the given semantics model. Subclasses must override this as it is specific for each different diagram type.

Specified by:
createNewDiagram in class AbstractInitDiagramHandler
Parameters:
modelRootParam - the root element of the domain model.
editingDomain - the editing domain.
diagramFile - the destination file
monitor - the progress monitor
Returns:
the editor that was opened for the diagram, may be null

alignBoxRelativeAnchors

public void alignBoxRelativeAnchors(org.eclipse.graphiti.mm.pictograms.AnchorContainer ac)
Align the BoxRelativeAnchors on one container to a sensible position. This method places all BoxRelativeAnchors with incoming connections on the left side. All BoxRelativeAnchors with outgoing connections are placed on the right side. BoxRelativeAnchors with no connections are placed equally on the side with less connections.

Parameters:
ac - the anchor container.

alignBoxRelativeAnchors

public void alignBoxRelativeAnchors(org.eclipse.graphiti.mm.pictograms.AnchorContainer ac,
                                    de.cau.cs.kieler.core.model.graphiti.ui.AbstractInitGraphitiDiagramHandler.LayoutDirection dir)
Align the BoxRelativeAnchors according to the layout direction.

Parameters:
ac - the anchor container.
dir - the direction.

alignPortsOnSide

protected void alignPortsOnSide(List<org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor> ports,
                                de.cau.cs.kieler.core.model.graphiti.ui.AbstractInitGraphitiDiagramHandler.LayoutDirection side)
Distribute the ports equally on the specified side.

Parameters:
ports - the list of ports to distribute
side - the side on which to align the ports

findVisibleGa

protected org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm findVisibleGa(org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm graphicsAlgorithm)
Find a visible GraphicsAlgorithm to stick the ports on.

Parameters:
graphicsAlgorithm - parent GA
Returns:
a visible GA

determineSideForAnchors

protected void determineSideForAnchors(List<org.eclipse.graphiti.mm.pictograms.Anchor> anchors,
                                       List<org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor> inPorts,
                                       List<org.eclipse.graphiti.mm.pictograms.BoxRelativeAnchor> outPorts)
Determine on which side to place a port. Ports with more incoming than outgoing edges are placed on the left. Ports with more outgoing than incoming edges are placed on the right. A port with equal number of incoming and outgoing edges is placed on the side which has the least number of ports.

Parameters:
anchors - the anchors to distribute
inPorts - the ports on the left
outPorts - the ports on the right

linkModelToDiagram

protected void linkModelToDiagram(org.eclipse.graphiti.ui.editor.DiagramEditor editor)
                           throws InterruptedException,
                                  RollbackException
Link the model to the newly created diagram inside the editor.

Parameters:
editor - the editor
Throws:
RollbackException - if the transaction was rolled back
InterruptedException - if the transaction was interrupted

isConnection

protected abstract boolean isConnection(EObject eObj)
The given domain model element represents a connection which should be dealt with after all other elements are added. This is necessary since connection require their source and target to be already present while adding.

Parameters:
eObj - the domain model element
Returns:
true if the element represents a connection

getConnectionSource

protected abstract EObject getConnectionSource(EObject connection)
Get the source element of a connection.

Parameters:
connection - the connection
Returns:
the source of the connection

getConnectionTarget

protected abstract EObject getConnectionTarget(EObject connection)
Get the target element for a connection.

Parameters:
connection - the connection
Returns:
the target of the connection

processConnection

protected org.eclipse.graphiti.features.context.impl.AddConnectionContext processConnection(Map<EObject,org.eclipse.graphiti.mm.pictograms.PictogramElement> elementsParam,
                                                                                            EObject connection)
Process a single connection. This method should be overridden if the standard implementation doesn't produce the desired results. When the method is called it can be guaranteed that all other elements have already been added to the diagram.

Parameters:
elementsParam - the map of already added elements.
connection - the domain model element of the connection to be added
Returns:
the context to execute for adding

addChildrenRecursively

protected boolean addChildrenRecursively(EObject eObj)
If true all contained elements will be added recursively. If false it is assumed that the graphical elements for all children were already added when the parent element is added.

Parameters:
eObj - the model element
Returns:
true if the method should be called again for all children