Skip to content

Commit

Permalink
[2181] Exception on selecting package
Browse files Browse the repository at this point in the history
we check if the selected element is graphical object

Bug: 2181
Change-Id: I8eabbb8f9b68a8feded0984544e2710435058a25
Signed-off-by: Joacquim Esabe <joacquim.esabe@laposte.net>
  • Loading branch information
Joacquim Esabe committed Sep 12, 2018
1 parent a9098c3 commit f3fb78f
Showing 1 changed file with 67 additions and 32 deletions.
Expand Up @@ -47,10 +47,15 @@ public static Set<EObject> getAll(EObject currentElement, EClass targetType) {
}

/**
* This method retrieves all Object of metaClass 'metaClass' who have a EReference 'eRef' toward the Object 'eObjectRef'
* @param eObjectRef : EObject
* @param metaClass : EClass
* @param eRef : EReference relation
* This method retrieves all Object of metaClass 'metaClass' who have a EReference 'eRef' toward the Object
* 'eObjectRef'
*
* @param eObjectRef
* : EObject
* @param metaClass
* : EClass
* @param eRef
* : EReference relation
* @return
*/
public static List<EObject> getReferencers(EObject eObjectRef, EClass metaClass, EReference eRef) {
Expand All @@ -65,7 +70,9 @@ public static List<EObject> getReferencers(EObject eObjectRef, EClass metaClass,

/**
* This method retrieves all Object who have a EReference toward the EObject 'eObjectRef'
* @param eObjectRef : EObject
*
* @param eObjectRef
* : EObject
* @return The list of referencing elements
*/
public static List<EObject> getReferencers(EObject eObjectRef) {
Expand All @@ -79,8 +86,11 @@ public static List<EObject> getReferencers(EObject eObjectRef) {

/**
* This method retrieves all Object who have a EReference 'eRef' toward the EObject 'eObjectRef'
* @param eObjectRef : EObject
* @param eRef : EReference relation
*
* @param eObjectRef
* : EObject
* @param eRef
* : EReference relation
* @return The list of referencing elements
*/
public static <T extends EObject> List<T> getReferencers(EObject eObjectRef, EReference eRef) {
Expand All @@ -94,21 +104,28 @@ public static <T extends EObject> List<T> getReferencers(EObject eObjectRef, ERe

/**
* This method retrieves all Object who have a EReference 'eRef' toward the Object 'eObjectRef'
* @param eObjectRef : EObject
* @param eRef : EReference relation (if null, all references are considered)
* @param editingDomain : SemanticEditingDomain
* @param ignoreDerivedFeature : whether derived feature is ignored while finding referencing objects
*
* @param eObjectRef
* : EObject
* @param eRef
* : EReference relation (if null, all references are considered)
* @param editingDomain
* : SemanticEditingDomain
* @param ignoreDerivedFeature
* : whether derived feature is ignored while finding referencing objects
* @return The list of referencing elements
*/
public static <T extends EObject> List<T> getReferencers(EObject eObjectRef, EReference eRef, SemanticEditingDomain editingDomain, boolean ignoreDerivedFeature) {
public static <T extends EObject> List<T> getReferencers(EObject eObjectRef, EReference eRef,
SemanticEditingDomain editingDomain, boolean ignoreDerivedFeature) {
List<T> result = new ArrayList<T>();

SemanticCrossReferencer crossReferencer = editingDomain.getCrossReferencer();
if (eRef == null) {
Collection<Setting> inverseReferences = crossReferencer.getInverseReferences(eObjectRef, editingDomain.getCrossReferencer().isResolveProxyEnabled());
Collection<Setting> inverseReferences = crossReferencer.getInverseReferences(eObjectRef,
editingDomain.getCrossReferencer().isResolveProxyEnabled());
for (Setting setting : inverseReferences) {
if (ignoreDerivedFeature && setting.getEStructuralFeature().isDerived())
continue;
if (ignoreDerivedFeature && setting.getEStructuralFeature().isDerived())
continue;
if (!result.contains(setting.getEObject())) {
result.add((T) setting.getEObject());
}
Expand All @@ -131,19 +148,27 @@ public static <T extends EObject> List<T> getReferencers(EObject eObjectRef, ERe

/**
* This method retrieves all Object who have a EReference 'eRef' toward the Object 'eObjectRef'
* @param eObjectRef : EObject
* @param eRef : EReference relation (if null, all references are considered)
* @param editingDomain : SemanticEditingDomain
*
* @param eObjectRef
* : EObject
* @param eRef
* : EReference relation (if null, all references are considered)
* @param editingDomain
* : SemanticEditingDomain
* @return The list of referencing elements
*/
public static <T extends EObject> List<T> getReferencers(EObject eObjectRef, EReference eRef, SemanticEditingDomain editingDomain) {
return getReferencers(eObjectRef, eRef, editingDomain, false);
public static <T extends EObject> List<T> getReferencers(EObject eObjectRef, EReference eRef,
SemanticEditingDomain editingDomain) {
return getReferencers(eObjectRef, eRef, editingDomain, false);
}

/**
* This method retrieves all Object who have any EReference from 'eRefs' toward the Object 'eObjectRef'
* @param eObjectRef : EObject
* @param eRefs : EReference relations list
*
* @param eObjectRef
* : EObject
* @param eRefs
* : EReference relations list
* @return
*/
public static List<EObject> getReferencers(EObject eObjectRef, List<EReference> eRefs) {
Expand All @@ -158,6 +183,7 @@ public static List<EObject> getReferencers(EObject eObjectRef, List<EReference>

/**
* True if the given element is instance of at least one of the given eClasses
*
* @param elt
* @param expectedContainerType
* @return
Expand All @@ -175,12 +201,17 @@ public static boolean isInstanceOf(EObject elt, List<EClass> expectedContainerTy
}

/**
* @param eObjects a collection of EObject(s) from which the resource set will be retrieved
* @return if all EObject(s) belong to the same resource set, this resource set is returned. Otherwise null is returned.
* @param eObjects
* a collection of EObject(s) from which the resource set will be retrieved
* @return if all EObject(s) belong to the same resource set, this resource set is returned. Otherwise null is
* returned.
*/
public static ResourceSet getCommonResourceSet(Collection<? extends EObject> eObjects) {
ResourceSet resourceSet = null;
for (EObject obj : eObjects) {
if (obj == null) {
return null;
}
Resource eResource = obj.eResource();
if (eResource != null) {
if (null == resourceSet) {
Expand All @@ -196,8 +227,10 @@ public static ResourceSet getCommonResourceSet(Collection<? extends EObject> eOb
}

/**
* @param resources a collection of resources from which the resource set will be retrieved
* @return if all resources belong to the same resource set, this resource set is returned. Otherwise null is returned.
* @param resources
* a collection of resources from which the resource set will be retrieved
* @return if all resources belong to the same resource set, this resource set is returned. Otherwise null is
* returned.
*/
public static ResourceSet getCommonResourceSet(List<Resource> resources) {
ResourceSet rs = null;
Expand Down Expand Up @@ -225,9 +258,10 @@ public static String getText(EObject object) {
}
return label;
}

/**
* Get the generated item provider for given object.
*
* @param object
* @return<code>null</code> if one of parameters is <code>null</code> or if no provider is found.
*/
Expand All @@ -236,18 +270,19 @@ protected static IItemLabelProvider getItemLabelProvider(EObject object) {
if (null == object) {
return null;
}

EditingDomain editingDomain = TransactionHelper.getEditingDomain(object);

// Precondition.
if (null == editingDomain) {
editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(object);
}

// Precondition.
if (null == editingDomain || !(editingDomain instanceof AdapterFactoryEditingDomain)) {
return null;
}
return (IItemLabelProvider) ((AdapterFactoryEditingDomain) editingDomain).getAdapterFactory().adapt(object, IItemLabelProvider.class);
return (IItemLabelProvider) ((AdapterFactoryEditingDomain) editingDomain).getAdapterFactory().adapt(object,
IItemLabelProvider.class);
}
}

0 comments on commit f3fb78f

Please sign in to comment.