de.cau.cs.kieler.kiml.ui.layout
Class DiagramLayoutManager

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

public abstract class DiagramLayoutManager
extends Object

Abstract superclass for managers of diagram layout.

Rating proposed yellow
(2009-12-11) msp

Field Summary
static int MAX_PROGRESS_LEVELS
          maximal number of recursion levels for which progress is displayed.
 
Constructor Summary
DiagramLayoutManager()
           
 
Method Summary
 void applyAndZoom(boolean animate, boolean cacheLayout, int nodeCount)
          Apply layout with zoom and animation.
 void applyAnimatedLayout(boolean animate, boolean cacheLayout, int nodeCount)
          Apply layout with or without animation.
protected abstract  void applyLayout()
          Applies the transferred layout to the original diagram.
abstract  KNode buildLayoutGraph(IWorkbenchPart workbenchPart, EditPart editPart, boolean layoutAncestors)
          Builds a KGraph instance for the given editor or edit part.
static int calcAnimationTime(int graphSize)
          Calculates animation time for the given graph size.
abstract  IGraphicalFrameworkBridge getBridge()
          Returns the graphical framework bridge for this layout manager.
protected abstract  ICachedLayout getCachedLayout()
          Returns the cached layout for the last layout run.
 EditPart getEditPart(KNode knode)
          Returns the edit part associated with the given layout node.
protected  ILayoutConfig getExternalConfig()
          Returns the layout configuration that was set externally for this layout manager.
abstract  ILayoutConfig getLayoutConfig(EditPart editPart)
          Returns a layout configuration for the given edit part.
abstract  KNode getLayoutGraph()
          Returns the last built layout graph.
 KNode getLayoutNode(EditPart editPart)
          Returns the layout node associated with the given edit part.
 int getPriority()
          Return the manager priority.
 IKielerProgressMonitor getProgressMonitor()
          Returns the last used progress monitor.
 IStatus layout(IKielerProgressMonitor progressMonitor)
          Performs layout on the given editor or edit part using this layout manager and a specific progress monitor.
 void layout(IWorkbenchPart workbenchPart, EditPart editPart, boolean animate, boolean progressBar, boolean layoutAncestors, boolean cacheLayout)
          Performs layout on the given editor or edit part using this layout manager.
 void layout(IWorkbenchPart workbenchPart, EditPart editPart, boolean animate, boolean progressBar, boolean layoutAncestors, boolean cacheLayout, boolean zoom)
          Performs layout on the given editor or edit part using this layout manager.
 void setLayoutConfig(ILayoutConfig layoutConfig)
          Set an external layout configuration to use with this layout manager.
 void setPriority(int thepriority)
          Set the manager priority.
protected abstract  boolean supports(EditPart editPart)
          Determines whether this layout manager is able to perform layout for the given edit part.
protected abstract  boolean supports(IWorkbenchPart workbenchPart)
          Determines whether this layout manager is able to perform layout for the given editor.
protected abstract  void transferLayout(boolean cacheLayout)
          Transfers all layout data from the last created KGraph instance to the original diagram.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_PROGRESS_LEVELS

public static final int MAX_PROGRESS_LEVELS
maximal number of recursion levels for which progress is displayed.

See Also:
Constant Field Values
Constructor Detail

DiagramLayoutManager

public DiagramLayoutManager()
Method Detail

getPriority

public final int getPriority()
Return the manager priority.

Returns:
the priority

setPriority

public final void setPriority(int thepriority)
Set the manager priority.

Parameters:
thepriority - the priority to set

setLayoutConfig

public final void setLayoutConfig(ILayoutConfig layoutConfig)
Set an external layout configuration to use with this layout manager. Giving null as parameter resets the configuration to the standard.

Parameters:
layoutConfig - a layout configuration, or null

getExternalConfig

protected final ILayoutConfig getExternalConfig()
Returns the layout configuration that was set externally for this layout manager.

Returns:
the external layout configuration, or null

layout

public final void layout(IWorkbenchPart workbenchPart,
                         EditPart editPart,
                         boolean animate,
                         boolean progressBar,
                         boolean layoutAncestors,
                         boolean cacheLayout)
Performs layout on the given editor or edit part using this layout manager. A progress bar indicating progress of the layout algorithm is optionally shown to the user.

Parameters:
workbenchPart - the workbench part for which layout is performed, or null if the diagram is not part of an editor
editPart - the parent edit part for which layout is performed, or null if the whole diagram shall be layouted
animate - if true, Draw2D animation is activated
progressBar - if true, a progress bar is displayed
layoutAncestors - if true, layout is not only performed for the selected edit part, but also for its ancestors
cacheLayout - if true, the layout result is cached for the underlying model

layout

public final void layout(IWorkbenchPart workbenchPart,
                         EditPart editPart,
                         boolean animate,
                         boolean progressBar,
                         boolean layoutAncestors,
                         boolean cacheLayout,
                         boolean zoom)
Performs layout on the given editor or edit part using this layout manager. A progress bar indicating progress of the layout algorithm is optionally shown to the user.

Parameters:
workbenchPart - the workbench part for which layout is performed, or null if the diagram is not part of an editor
editPart - the parent edit part for which layout is performed, or null if the whole diagram shall be layouted
animate - if true, Draw2D animation is activated
progressBar - if true, a progress bar is displayed
layoutAncestors - if true, layout is not only performed for the selected edit part, but also for its ancestors
cacheLayout - if true, the layout result is cached for the underlying model
zoom - if true, automatic zoom-to-fit is activated

applyAndZoom

public final void applyAndZoom(boolean animate,
                               boolean cacheLayout,
                               int nodeCount)
Apply layout with zoom and animation.

Parameters:
animate - if true, activate Draw2D animation
cacheLayout - if true, the layout result is cached for the underlying model
nodeCount - the number of nodes in the layouted diagram

applyAnimatedLayout

public final void applyAnimatedLayout(boolean animate,
                                      boolean cacheLayout,
                                      int nodeCount)
Apply layout with or without animation.

Parameters:
animate - if true, activate Draw2D animation
cacheLayout - if true, the layout result is cached for the underlying model
nodeCount - the number of nodes in the layouted diagram

layout

public IStatus layout(IKielerProgressMonitor progressMonitor)
Performs layout on the given editor or edit part using this layout manager and a specific progress monitor. The layout graph must be built before this method is called, and the layout must be applied after this method returns.

Parameters:
progressMonitor - a progress monitor to which progress of the layout algorithm is reported
Returns:
a status indicating success or failure; if successful, the status contains the number of layouted nodes as code value

getProgressMonitor

public IKielerProgressMonitor getProgressMonitor()
Returns the last used progress monitor.

Returns:
the last used progress monitor

calcAnimationTime

public static int calcAnimationTime(int graphSize)
Calculates animation time for the given graph size.

Parameters:
graphSize - total number of nodes in the graph
Returns:
number of milliseconds to animate

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.

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.

Parameters:
editPart - an edit part of the currently layouted diagram
Returns:
the corresponding layout node, or null

supports

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

Parameters:
workbenchPart - a workbench part
Returns:
true if this layout manager supports the editor part

supports

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

Parameters:
editPart - an edit part
Returns:
true if this layout manager supports the edit part

buildLayoutGraph

public abstract 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.

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

getBridge

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

Returns:
a framework bridge that is suitable for diagrams that are managed by this layout manager

getLayoutConfig

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

Parameters:
editPart - an edit part
Returns:
a layout configuration for the edit part, or a generic configuration

transferLayout

protected abstract 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.

Parameters:
cacheLayout - if true, the layout result is cached for the underlying model

applyLayout

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


getLayoutGraph

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

Returns:
the last built layout graph

getCachedLayout

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

Returns:
the last cached layout