Search in sources :

Example 11 with StructuredType

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

the class StructuredTypeImpl method isCyclicInheritance.

/**
 * Checks that there is no cyclic inheritance if the given type becomes the
 * super type of this type.
 *
 * @param superTypeCandidate
 *            the super type candidate.
 * @return <code>true</true> if a cyclic inheritance appears if <code>superTypeCandidate</code>
 *         becomes the super type of this type.
 */
private boolean isCyclicInheritance(final StructuredType superTypeCandidate) {
    // quick tests
    if (superTypeCandidate == null) {
        return false;
    }
    if (superTypeCandidate == this) {
        return true;
    }
    // checks that this is not a super type of superTypeCandidate.
    final Set<StructuredType> superTypesOfSuperTypeCandidate = new HashSet<StructuredType>();
    StructuredType currentSuperType = superTypeCandidate.getSupertype();
    while (currentSuperType != null && superTypesOfSuperTypeCandidate.add(currentSuperType)) {
        if (currentSuperType == this) {
            // cycle
            return true;
        }
        // Iterate on supertypes
        currentSuperType.getSupertype();
    }
    // it's ok, no cycle.
    return false;
}
Also used : StructuredType(org.obeonetwork.dsl.environment.StructuredType) HashSet(java.util.HashSet)

Example 12 with StructuredType

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

the class UseCaseServices method allDomainClasses.

/**
 * Collect all domain classes referenced by a use case
 * @param uc
 * @return
 */
public List<DomainClass> allDomainClasses(UseCase uc) {
    Set<DomainClass> classes = new HashSet<DomainClass>();
    // Add domain classes directly references
    classes.addAll(uc.getDomainClasses());
    // Search for domain classes in referenced namespaces
    for (Namespace ns : uc.getNamespaces()) {
        collectClasses(ns, classes);
    }
    // This reference exists for compatibility with old metamodel version (before DomainClass)
    for (StructuredType type : uc.getTypes()) {
        if (type instanceof DomainClass) {
            classes.add((DomainClass) type);
        }
    }
    // Convert set to list
    List<DomainClass> result = new ArrayList<>(classes);
    // and sort by fully qualified names
    Collections.sort(result, new Comparator<DomainClass>() {

        @Override
        public int compare(DomainClass arg0, DomainClass arg1) {
            // Use a primary collator to ignore accents and case
            Collator collator = Collator.getInstance();
            collator.setStrength(Collator.PRIMARY);
            return collator.compare(fullQualifiedName(arg0), fullQualifiedName(arg1));
        }
    });
    return result;
}
Also used : DomainClass(org.obeonetwork.graal.DomainClass) ArrayList(java.util.ArrayList) Namespace(org.obeonetwork.dsl.environment.Namespace) HashSet(java.util.HashSet) StructuredType(org.obeonetwork.dsl.environment.StructuredType) Collator(java.text.Collator)

Example 13 with StructuredType

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

the class BindingService method getAllBindableElements.

public Collection<StructuredType> getAllBindableElements(DSemanticDiagram diagram, StructuredType structuredType) {
    // Collect all structured types
    Collection<StructuredType> bindableElements = new ArrayList<StructuredType>();
    // First get all structured types
    bindableElements.addAll(getAllStructuredTypes(structuredType));
    // Remove the target element
    bindableElements.remove(structuredType);
    // Remove elements already bound with the target
    for (BindingInfo bindingInfo : getAllBindingInfosOnDiagram(diagram)) {
        if (bindingInfo.getLeft() == structuredType) {
            bindableElements.remove(bindingInfo.getRight());
        }
        if (bindingInfo.getRight() == structuredType) {
            bindableElements.remove(bindingInfo.getLeft());
        }
    }
    return bindableElements;
}
Also used : BindingInfo(org.obeonetwork.dsl.environment.BindingInfo) ArrayList(java.util.ArrayList) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 14 with StructuredType

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

the class BindingService method getRelatedBindingInfos.

public Collection<BindingInfo> getRelatedBindingInfos(Namespace namespace) {
    // Use of LinkedHashSet to keep order and avoid potential lock/unlock
    // loops problems
    Set<BindingInfo> results = new LinkedHashSet<BindingInfo>();
    for (BindingRegistry bindingRegistry : namespace.getBindingRegistries()) {
        results.addAll(bindingRegistry.getBindingInfos());
    }
    for (Type containedType : namespace.getTypes()) {
        if (containedType instanceof StructuredType) {
            StructuredType containedStructuredType = (StructuredType) containedType;
            results.addAll(getRelatedBindingInfos(containedStructuredType));
        }
    }
    return results;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) StructuredType(org.obeonetwork.dsl.environment.StructuredType) Type(org.obeonetwork.dsl.environment.Type) BindingInfo(org.obeonetwork.dsl.environment.BindingInfo) BindingRegistry(org.obeonetwork.dsl.environment.BindingRegistry) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 15 with StructuredType

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

the class DesignServices method isExistingDependency.

/**
 * Checks whether a dependency should be displayed between 2 namespaces
 * @param source
 * @param target
 * @return
 */
public static boolean isExistingDependency(Namespace source, Namespace target) {
    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())) {
                return true;
            }
            // Check references
            for (Reference reference : structuredType.getOwnedReferences()) {
                StructuredType referencedType = reference.getReferencedType();
                if (referencedType != null && target.equals(referencedType.eContainer())) {
                    return true;
                }
            }
            // Check attributes
            for (Attribute attribute : structuredType.getOwnedAttributes()) {
                DataType datatype = attribute.getType();
                if (datatype instanceof Enumeration && target.equals(datatype.eContainer())) {
                    return true;
                }
            }
        }
    }
    return false;
}
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)

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