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

java.lang.Object
  extended by de.cau.cs.kieler.kiml.ui.layout.KimlUiUtil

public final class KimlUiUtil
extends Object

Utility methods used for the KIML UI.

Rating proposed yellow
(2009-12-11) msp

Method Summary
static KOption addKOption(LayoutOptionStyle optionStyle, LayoutOptionData optionData)
          Adds a KOption to the given layout option style.
static Insets calcInsets(IFigure parent, IFigure child)
          Determines the insets for a parent figure, relative to the given child.
static String getClassName(EditPart editPart, boolean forDomainModel)
          Returns the class name for which to store layout options for the given edit part.
static Object getDefault(LayoutOptionData optionData, LayoutProviderData providerData, EditPart editPart, EditPart containerEditPart, boolean hasChildren)
          Retrieves the default value for the given layout option.
static org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart getDiagramEditPart(EditPart editPart)
          Finds the diagram edit part of an edit part.
static KOption getKOption(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart editPart, String optionId)
          Returns the KOption with given key that is stored for the edit part.
static Object getOption(EditPart editPart, String optionId)
          Retrieves a layout option from the given edit part by querying the option for the edit part's class name and its domain model name.
static LayoutOptionData getOptionData(LayoutProviderData[] providerDataArray, String displayName)
          Retrieves a suitable layout option data instance that matches the given user friendly display name.
static boolean isNoLayout(EditPart editPart)
          Determines whether the given edit part should not be layouted.
static boolean isRelative(IFigure parent, IFigure child)
          Determines whether the position of the given child figure is relative to the position of the given parent figure.
static void removeKOption(LayoutOptionStyle optionStyle, String optionId)
          Removes the KOption with given identifier from the notation view.
static void removeOptionStyle(View view)
          Removes the LayoutOptionStyle from the notation view, if it exists.
static void runModelChange(Runnable runnable, TransactionalEditingDomain editingDomain, String label)
          Performs the model changes specified in the given runnable in a safe context.
static void setLayoutOptions(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart editPart, KLayoutData layoutData, boolean setUserOptions)
          Sets all predefined and user defined layout options for the given edit part.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

calcInsets

public static Insets calcInsets(IFigure parent,
                                IFigure child)
Determines the insets for a parent figure, relative to the given child.

Parameters:
parent - the figure of a parent edit part
child - the figure of a child edit part
Returns:
the insets to add to the relative coordinates of the child

isRelative

public static boolean isRelative(IFigure parent,
                                 IFigure child)
Determines whether the position of the given child figure is relative to the position of the given parent figure.

Parameters:
parent - the figure of a parent edit part
child - the figure of a child edit part
Returns:
true if the child position is relative to the parent

getDefault

public static Object getDefault(LayoutOptionData optionData,
                                LayoutProviderData providerData,
                                EditPart editPart,
                                EditPart containerEditPart,
                                boolean hasChildren)
Retrieves the default value for the given layout option.

Parameters:
optionData - a layout option data
providerData - the active layout provider data
editPart - the current edit part
containerEditPart - the edit part that contains the objects for which options are set
hasChildren - indicates whether the given edit part has children in the layout graph
Returns:
an object with the default value

setLayoutOptions

public static void setLayoutOptions(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart editPart,
                                    KLayoutData layoutData,
                                    boolean setUserOptions)
Sets all predefined and user defined layout options for the given edit part.

Parameters:
editPart - edit part for which options are set
layoutData - layout data where options are written
setUserOptions - if true, the user defined options are also set

getKOption

public static KOption getKOption(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart editPart,
                                 String optionId)
Returns the KOption with given key that is stored for the edit part.

Parameters:
editPart - the edit part for which the option shall be fetched
optionId - the identifier of the option
Returns:
the corresponding option, or null if there is no such option

runModelChange

public static void runModelChange(Runnable runnable,
                                  TransactionalEditingDomain editingDomain,
                                  String label)
Performs the model changes specified in the given runnable in a safe context.

Parameters:
runnable - a runnable that performs model changes
editingDomain - the editing domain for the changes
label - a user friendly label shown for the undo action

addKOption

public static KOption addKOption(LayoutOptionStyle optionStyle,
                                 LayoutOptionData optionData)
Adds a KOption to the given layout option style. This operation must be run in a safe context; use runModelChange(java.lang.Runnable, org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.String) to achieve this.

Parameters:
optionStyle - layout option style of a notation view
optionData - the layout option data for which the KOption shall be created
Returns:
the new KOption

removeKOption

public static void removeKOption(LayoutOptionStyle optionStyle,
                                 String optionId)
Removes the KOption with given identifier from the notation view. This operation must be run in a safe context; use runModelChange(java.lang.Runnable, org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.String) to achieve this.

Parameters:
optionStyle - layout option style of a notation view
optionId - the layout option identifier for which the KOption shall be removed

removeOptionStyle

public static void removeOptionStyle(View view)
Removes the LayoutOptionStyle from the notation view, if it exists. This operation must be run in a safe context; use runModelChange(java.lang.Runnable, org.eclipse.emf.transaction.TransactionalEditingDomain, java.lang.String) to achieve this.

Parameters:
view - the notation view from which to remove the layout option style

getDiagramEditPart

public static org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart getDiagramEditPart(EditPart editPart)
Finds the diagram edit part of an edit part.

Parameters:
editPart - an edit part
Returns:
the diagram edit part, or null if there is no containing diagram edit part

getClassName

public static String getClassName(EditPart editPart,
                                  boolean forDomainModel)
Returns the class name for which to store layout options for the given edit part.

Parameters:
editPart - an edit part
forDomainModel - if true the class of the edit part's domain model is taken, else the edit part class itself is taken
Returns:
the class name for layout options, or null if there is no such class name

getOption

public static Object getOption(EditPart editPart,
                               String optionId)
Retrieves a layout option from the given edit part by querying the option for the edit part's class name and its domain model name.

Parameters:
editPart - an edit part
optionId - layout option identifier
Returns:
the current value for the given option

isNoLayout

public static boolean isNoLayout(EditPart editPart)
Determines whether the given edit part should not be layouted.

Parameters:
editPart - an edit part
Returns:
true if no layout should be performed for the edit part

getOptionData

public static LayoutOptionData getOptionData(LayoutProviderData[] providerDataArray,
                                             String displayName)
Retrieves a suitable layout option data instance that matches the given user friendly display name.

Parameters:
providerDataArray - array of applicable layout provider data
displayName - display name of the layout option as seen by the user
Returns:
the most suitable layout option data