de.cau.cs.kieler.kiml.gmf
Class GmfDiagramLayoutManager

java.lang.Object
  extended by de.cau.cs.kieler.kiml.ui.layout.DiagramLayoutManager
      extended by de.cau.cs.kieler.kiml.gmf.GmfDiagramLayoutManager
Direct Known Subclasses:
GraphsDiagramLayoutManager, MultiPartDiagramLayoutManager

public class GmfDiagramLayoutManager
extends DiagramLayoutManager

Diagram layout manager that is able to generically layout diagrams generated by GMF. The internal KGraph graph structure is built from the structure of edit parts in the diagram. The new layout is applied to the diagram using GmfLayoutEditPolicy, which creates a GmfLayoutCommand to directly manipulate data in the GMF notation model, where layout information is stored persistently.

Rating proposed yellow
(2009-12-11) msp

Field Summary
 
Fields inherited from class de.cau.cs.kieler.kiml.ui.layout.DiagramLayoutManager
MAX_PROGRESS_LEVELS
 
Constructor Summary
GmfDiagramLayoutManager()
           
 
Method Summary
protected  void applyLayout()
          Applies the transferred layout to the original diagram.
 KNode buildLayoutGraph(IWorkbenchPart workbenchPart, EditPart editPart, boolean layoutAncestors)
          Builds a KGraph instance for the given editor or edit part.
protected  void cleanupAncestryPath(KNode topNode)
          Cleans the path from the ancestry target node to the top level node, including all parallel paths.
protected  KNode doBuildLayoutGraph(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart rootPart)
          Builds the layout graph for the given root edit part.
 IGraphicalFrameworkBridge getBridge()
          Returns the graphical framework bridge for this layout manager.
protected  ICachedLayout getCachedLayout()
          Returns the cached layout for the last layout run.
protected  org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart getDiagramEditPart()
          Returns the diagram edit part.
 EditPart getEditPart(KNode knode)
          Returns the edit part associated with the given layout node.
protected  Map<org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart,KGraphElement> getEditPart2GraphElemMap()
          Returns the map of graphical edit parts to corresponding layout graph elements.
protected  Map<KGraphElement,org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart> getGraphElem2EditPartMap()
          Returns the map of layout graph elements to corresponding edit parts.
protected  Command getLayoutCommand()
          Returns the command that is calculated by transferLayout(boolean) to apply the layout.
 ILayoutConfig getLayoutConfig(EditPart editPart)
          Returns a layout configuration for the given edit part.
 KNode getLayoutGraph()
          Returns the last built layout graph.
 KNode getLayoutNode(EditPart editPart)
          Returns the layout node associated with the given edit part.
protected  void processEdgeLabels(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart connection, KEdge edge, EdgeLabelPlacement placement, float offsetx, float offsety, ILayoutConfig layoutConfig)
          Process the labels of an edge.
protected  void setEdgeLayout(KEdgeLayout edgeLayout, org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart connection, float offsetx, float offsety)
          Stores the layout information of the given connection edit part into an edge layout.
protected  void setLayoutCommand(Command thelayoutCommand)
          Sets the given command as new layout command.
protected  boolean supports(EditPart editPart)
          Determines whether this layout manager is able to perform layout for the given edit part.
protected  boolean supports(IWorkbenchPart workbenchPart)
          Determines whether this layout manager is able to perform layout for the given editor.
protected  void transferLayout(boolean cacheLayout)
          Transfers all layout data from the last created KGraph instance to the original diagram.
 
Methods inherited from class de.cau.cs.kieler.kiml.ui.layout.DiagramLayoutManager
applyAndZoom, applyAnimatedLayout, calcAnimationTime, getExternalConfig, getPriority, getProgressMonitor, layout, layout, layout, setLayoutConfig, setPriority
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GmfDiagramLayoutManager

public GmfDiagramLayoutManager()
Method Detail

getGraphElem2EditPartMap

protected Map<KGraphElement,org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart> getGraphElem2EditPartMap()
Returns the map of layout graph elements to corresponding edit parts.

Returns:
the graphElem2EditPartMap

getEditPart2GraphElemMap

protected Map<org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart,KGraphElement> getEditPart2GraphElemMap()
Returns the map of graphical edit parts to corresponding layout graph elements.

Returns:
the editPart2GraphElemMap

getDiagramEditPart

protected org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart getDiagramEditPart()
Returns the diagram edit part.

Returns:
the diagram edit part

getLayoutCommand

protected Command getLayoutCommand()
Returns the command that is calculated by transferLayout(boolean) to apply the layout.

Returns:
the apply layout command

setLayoutCommand

protected void setLayoutCommand(Command thelayoutCommand)
Sets the given command as new layout command.

Parameters:
thelayoutCommand - the apply layout command

supports

protected boolean supports(IWorkbenchPart workbenchPart)
Determines whether this layout manager is able to perform layout for the given editor.

Specified by:
supports in class DiagramLayoutManager
Parameters:
workbenchPart - a workbench part
Returns:
true if this layout manager supports the editor part

supports

protected boolean supports(EditPart editPart)
Determines whether this layout manager is able to perform layout for the given edit part.

Specified by:
supports in class DiagramLayoutManager
Parameters:
editPart - an edit part
Returns:
true if this layout manager supports the edit part

getBridge

public IGraphicalFrameworkBridge getBridge()
Returns the graphical framework bridge for this layout manager.

Specified by:
getBridge in class DiagramLayoutManager
Returns:
a framework bridge that is suitable for diagrams that are managed by this layout manager

getLayoutConfig

public ILayoutConfig getLayoutConfig(EditPart editPart)
Returns a layout configuration for the given edit part. If editPart is null, a generic layout configuration is created.

Specified by:
getLayoutConfig in class DiagramLayoutManager
Parameters:
editPart - an edit part
Returns:
a layout configuration for the edit part, or a generic configuration

buildLayoutGraph

public KNode buildLayoutGraph(IWorkbenchPart workbenchPart,
                              EditPart editPart,
                              boolean layoutAncestors)
Builds a KGraph instance for the given editor or edit part. The resulting layout graph should reflect the structure of edit parts in the original diagram.

Specified by:
buildLayoutGraph in class DiagramLayoutManager
Parameters:
workbenchPart - the workbench part for which layout is performed, or null
editPart - the parent edit part for which layout is performed, or null if the whole diagram shall be layouted
layoutAncestors - if true, layout is not only performed for the selected edit part, but also for its ancestors
Returns:
a layout graph instance

transferLayout

protected void transferLayout(boolean cacheLayout)
Transfers all layout data from the last created KGraph instance to the original diagram. The diagram is not modified yet, but all required preparations are performed.

Specified by:
transferLayout in class DiagramLayoutManager
Parameters:
cacheLayout - if true, the layout result is cached for the underlying model

applyLayout

protected void applyLayout()
Applies the transferred layout to the original diagram. This final step is where the actual change to the diagram is done.

Specified by:
applyLayout in class DiagramLayoutManager

getLayoutGraph

public KNode getLayoutGraph()
Returns the last built layout graph.

Specified by:
getLayoutGraph in class DiagramLayoutManager
Returns:
the last built layout graph

getCachedLayout

protected ICachedLayout getCachedLayout()
Returns the cached layout for the last layout run.

Specified by:
getCachedLayout in class DiagramLayoutManager
Returns:
the last cached layout

getEditPart

public EditPart getEditPart(KNode knode)
Returns the edit part associated with the given layout node. This is only valid after #buildLayoutGraph(IEditorPart, EditPart, boolean) was called.

Overrides:
getEditPart in class DiagramLayoutManager
Parameters:
knode - a node from the layout graph
Returns:
the corresponding edit part, or null

getLayoutNode

public KNode getLayoutNode(EditPart editPart)
Returns the layout node associated with the given edit part. This is only valid after #buildLayoutGraph(IEditorPart, EditPart, boolean) was called.

Overrides:
getLayoutNode in class DiagramLayoutManager
Parameters:
editPart - an edit part of the currently layouted diagram
Returns:
the corresponding layout node, or null

doBuildLayoutGraph

protected KNode doBuildLayoutGraph(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart rootPart)
Builds the layout graph for the given root edit part.

Parameters:
rootPart - the root edit part for layout
Returns:
layout graph layout graph that represents the structure contained in the root edit part

setEdgeLayout

protected void setEdgeLayout(KEdgeLayout edgeLayout,
                             org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart connection,
                             float offsetx,
                             float offsety)
Stores the layout information of the given connection edit part into an edge layout.

Parameters:
edgeLayout - an edge layout
connection - a connection edit part
offsetx - horizontal offset to be subtracted from coordinates
offsety - vertical offset to be subtracted from coordinates

processEdgeLabels

protected void processEdgeLabels(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart connection,
                                 KEdge edge,
                                 EdgeLabelPlacement placement,
                                 float offsetx,
                                 float offsety,
                                 ILayoutConfig layoutConfig)
Process the labels of an edge.

Parameters:
connection - the connection edit part
edge - the layout edge
placement - predefined placement for all labels, or UNDEFINED if the placement shall be derived from the edit part
offsetx - the offset for horizontal coordinates
offsety - the offset for vertical coordinates
layoutConfig - layout configuration handler

cleanupAncestryPath

protected void cleanupAncestryPath(KNode topNode)
Cleans the path from the ancestry target node to the top level node, including all parallel paths.

Parameters:
topNode - the top level node