Search in sources :

Example 16 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class DesignServices method getNbDependencies.

/**
 * Returns the number of dependencies between 2 namespaces
 * @param source
 * @param target
 * @return
 */
public static int getNbDependencies(Namespace source, Namespace target) {
    int count = 0;
    for (Type type : source.getTypes()) {
        if (type instanceof StructuredType) {
            StructuredType structuredType = (StructuredType) type;
            // Check inheritance
            StructuredType supertype = structuredType.getSupertype();
            if (supertype != null && target.equals(supertype.eContainer())) {
                count += 1;
            }
            // Check references
            for (Reference reference : structuredType.getOwnedReferences()) {
                StructuredType referencedType = reference.getReferencedType();
                if (referencedType != null && target.equals(referencedType.eContainer())) {
                    count += 1;
                }
            }
            // Check attributes
            for (Attribute attribute : structuredType.getOwnedAttributes()) {
                DataType datatype = attribute.getType();
                if (datatype instanceof Enumeration && target.equals(datatype.eContainer())) {
                    count += 1;
                }
            }
        }
    }
    return count;
}
Also used : StructuredType(org.obeonetwork.dsl.environment.StructuredType) DataType(org.obeonetwork.dsl.environment.DataType) Type(org.obeonetwork.dsl.environment.Type) Enumeration(org.obeonetwork.dsl.environment.Enumeration) Attribute(org.obeonetwork.dsl.environment.Attribute) Reference(org.obeonetwork.dsl.environment.Reference) DataType(org.obeonetwork.dsl.environment.DataType) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 17 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class ReferencesService method getOppositeReferences.

public List<Reference> getOppositeReferences(DSemanticDiagram diagram) {
    Collection<StructuredType> structuredTypes = DesignServices.getDisplayedStructuredTypes(diagram);
    Set<Reference> references = Sets.newLinkedHashSet();
    for (StructuredType structuredType : structuredTypes) {
        references.addAll(structuredType.getOwnedReferences());
    }
    Map<String, Reference> map = new HashMap<String, Reference>();
    for (Reference ref : references) {
        if (ref.getOppositeOf() != null) {
            String key1 = ref.getOppositeOf().hashCode() + "" + ref.hashCode();
            String key2 = ref.hashCode() + "" + ref.getOppositeOf().hashCode();
            if (map.get(key1) == null && map.get(key2) == null) {
                map.put(key1, ref);
            }
        }
    }
    return new ArrayList<Reference>(map.values());
}
Also used : HashMap(java.util.HashMap) Reference(org.obeonetwork.dsl.environment.Reference) ArrayList(java.util.ArrayList) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 18 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class TypesServices method getAllReferencedStructuredTypes.

public Collection<StructuredType> getAllReferencedStructuredTypes(Namespace namespace, DSemanticDiagram diagram) {
    Set<StructuredType> types = DesignServices.getDisplayedStructuredTypes(diagram);
    types.retainAll(namespace.getTypes());
    Collection<StructuredType> referencedTypes = new HashSet<StructuredType>();
    for (StructuredType existingType : types) {
        referencedTypes.add(existingType.getSupertype());
        for (Reference reference : existingType.getOwnedReferences()) {
            referencedTypes.add(reference.getReferencedType());
        }
        referencedTypes.addAll(getAllReferencingStructuredTypes(existingType));
    }
    referencedTypes.removeAll(namespace.getTypes());
    return referencedTypes;
}
Also used : Reference(org.obeonetwork.dsl.environment.Reference) StructuredType(org.obeonetwork.dsl.environment.StructuredType) HashSet(java.util.HashSet)

Example 19 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class TypesServices method getAllStructuredTypes.

public Collection<StructuredType> getAllStructuredTypes(EObject context, String typeName) {
    Collection<StructuredType> types = new ArrayList<StructuredType>();
    Collection<Resource> resources = ModelServices.getAllResources(context);
    for (Resource resource : resources) {
        for (EObject object : resource.getContents()) {
            if (object instanceof ObeoDSMObject) {
                types.addAll(internalGetAllChildrenStructuredTypes((ObeoDSMObject) object, typeName));
            }
        }
    }
    return types;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 20 with StructuredType

use of org.obeonetwork.dsl.environment.StructuredType in project InformationSystem by ObeoNetwork.

the class TypesServices method getAllSelectableExternalStructuredTypesWithAncestors.

public Collection<EObject> getAllSelectableExternalStructuredTypesWithAncestors(Namespace namespace, DSemanticDiagram diagram, String typeName) {
    Collection<EObject> result = new HashSet<EObject>();
    Collection<StructuredType> selectableTypes = getAllSelectableExternalStructuredTypes(namespace, diagram, typeName);
    result.addAll(selectableTypes);
    for (StructuredType selectableType : selectableTypes) {
        result.addAll(ModelServices.getAncestors(selectableType));
    }
    return result;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) HashSet(java.util.HashSet) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Aggregations

StructuredType (org.obeonetwork.dsl.environment.StructuredType)22 ArrayList (java.util.ArrayList)11 Reference (org.obeonetwork.dsl.environment.Reference)9 EObject (org.eclipse.emf.ecore.EObject)8 HashSet (java.util.HashSet)5 Attribute (org.obeonetwork.dsl.environment.Attribute)3 Type (org.obeonetwork.dsl.environment.Type)3 HashMap (java.util.HashMap)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 EObjectFlatComboSettings (org.eclipse.emf.eef.runtime.ui.widgets.eobjflatcombo.EObjectFlatComboSettings)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 BindingInfo (org.obeonetwork.dsl.environment.BindingInfo)2 DataType (org.obeonetwork.dsl.environment.DataType)2 Enumeration (org.obeonetwork.dsl.environment.Enumeration)2 Namespace (org.obeonetwork.dsl.environment.Namespace)2 Collator (java.text.Collator)1 LinkedHashSet (java.util.LinkedHashSet)1 NotificationChain (org.eclipse.emf.common.notify.NotificationChain)1 EClass (org.eclipse.emf.ecore.EClass)1