de.cau.cs.kieler.core.ui.errorhandler
Class ModelingUtil

java.lang.Object
  extended by de.cau.cs.kieler.core.ui.errorhandler.ModelingUtil

public final class ModelingUtil
extends Object

Utility class with static methods to handle EMF models and GEF EditParts. FIXME: This is a direct copy of de.cau.cs.kieler.core.model.util.ModelingUtil in order to avoid the dependency of kieler.core.ui to kieler.core.model (which would always pull in all the modeling stuff like Xtend/Xpand). This should be handled in some other way, e.g. the ErrorHandler should be extensible by other plugins or something like that.

Rating red

Method Summary
static Collection<EObject> getAllAncestorsByType(EClassifier eObjectClass, EObject rootObject)
          Get all objects that are direct or indirect parents of the given root EObject if they are of the given type.
static Collection<EObject> getAllByType(EClassifier eObjectClass, EditPart rootEditPart)
          Get all objects that are direct or indirect children of the given root EObject corresponding to the given EditPart if they are of the specified type.
static Collection<EObject> getAllByType(EClassifier eObjectClass, EObject rootObject)
          Get all objects that are direct or indirect children of the given root EObject if they are of the specified type.
static EditPart getEditPart(EObject eObject)
          Find an GEF EditPart that corresponds to an semantic model EObject.
static EditPart getEditPart(EObject eObject, EditPart rootEditPart)
          Find an GEF EditPart that corresponds to an semantic model EObject.
static List<EditPart> getEditParts(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart dep, EObject theElement)
          Finds ALL edit parts connected to the given semantic element.
static List<EObject> getModelElementsFromSelection()
          Returns a list of the EObjects currently selected in the diagram.
static
<T> Collection<T>
iterator2Collection(Iterator<T> iter)
          Convert an Iterator to a Collection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getEditPart

public static EditPart getEditPart(EObject eObject,
                                   EditPart rootEditPart)
Find an GEF EditPart that corresponds to an semantic model EObject. EObjects are used to address objects that are exchanged between the plugins of the View Management as well as other plugins. EObjects provide the ability for semantical addressing of other objects such as children of an object or similar cases.

Parameters:
eObject - the semantic object
rootEditPart - the root EditPart so start the search. May be null, then the current active editor is used
Returns:
the corresponding EditPart

getEditParts

public static List<EditPart> getEditParts(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart dep,
                                          EObject theElement)
Finds ALL edit parts connected to the given semantic element.

Parameters:
dep - the root edit part
theElement - the element to look for
Returns:
the list of results, may be empty

getAllByType

public static Collection<EObject> getAllByType(EClassifier eObjectClass,
                                               EObject rootObject)
Get all objects that are direct or indirect children of the given root EObject if they are of the specified type.

Parameters:
eObjectClass - The type of object
rootObject - The root object
Returns:
Collection of found EObject matching the type

getAllAncestorsByType

public static Collection<EObject> getAllAncestorsByType(EClassifier eObjectClass,
                                                        EObject rootObject)
Get all objects that are direct or indirect parents of the given root EObject if they are of the given type.

Parameters:
eObjectClass - The type of object
rootObject - The root object to start the search
Returns:
Collection of found EObject matching the type

getAllByType

public static Collection<EObject> getAllByType(EClassifier eObjectClass,
                                               EditPart rootEditPart)
Get all objects that are direct or indirect children of the given root EObject corresponding to the given EditPart if they are of the specified type.

Parameters:
eObjectClass - The type of object
rootEditPart - The root object
Returns:
Collection of found EObject matching the type

iterator2Collection

public static <T> Collection<T> iterator2Collection(Iterator<T> iter)
Convert an Iterator to a Collection. Useful if some method returns only an iterator but some other method takes a Collection as input to iterate over that collection. However, it has linear runtime and many such transformations should be avoided.

Type Parameters:
T - the base type
Parameters:
iter - The input Iterator
Returns:
A Collection containing all elements of the Iterator.

getModelElementsFromSelection

public static List<EObject> getModelElementsFromSelection()
Returns a list of the EObjects currently selected in the diagram.

Returns:
A List of EObjects

getEditPart

public static EditPart getEditPart(EObject eObject)
Find an GEF EditPart that corresponds to an semantic model EObject.

Parameters:
eObject - the semantic object
Returns:
the corresponding EditPart TODO: search of transition edit parts iterates all edit parts and will take linear time. You should improve this, by maybe build a local cache hash map