Search in sources :

Example 16 with Reference

use of org.obeonetwork.dsl.environment.Reference 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 Reference

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

the class ReferencesService method reconnectBidiReferenceTarget.

public Reference reconnectBidiReferenceTarget(Reference reference, StructuredType source, StructuredType target) {
    Reference oppositeOf = reference.getOppositeOf();
    reference.setReferencedType(target);
    oppositeOf.setContainingType(target);
    reference.setOppositeOf(oppositeOf);
    return reference;
}
Also used : Reference(org.obeonetwork.dsl.environment.Reference)

Example 18 with Reference

use of org.obeonetwork.dsl.environment.Reference 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 19 with Reference

use of org.obeonetwork.dsl.environment.Reference 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 20 with Reference

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

the class ReferenceSpec method setOppositeOf.

@Override
public void setOppositeOf(Reference newOppositeOf) {
    Reference oldOppositeOf = getOppositeOf();
    super.setOppositeOf(newOppositeOf);
    // If an opposite was specified, we have to unset it
    if (oldOppositeOf != null && (newOppositeOf == null || !newOppositeOf.eIsProxy()) && !oldOppositeOf.equals(newOppositeOf)) {
        oldOppositeOf.setOppositeOf(null);
    }
    // If a new opposite is specified, we have to ensure consistency
    if (newOppositeOf != null && !newOppositeOf.eIsProxy() && (newOppositeOf.getOppositeOf() == null || !newOppositeOf.getOppositeOf().equals(this))) {
        newOppositeOf.setOppositeOf(this);
    }
}
Also used : Reference(org.obeonetwork.dsl.environment.Reference)

Aggregations

Reference (org.obeonetwork.dsl.environment.Reference)21 StructuredType (org.obeonetwork.dsl.environment.StructuredType)9 ArrayList (java.util.ArrayList)7 EObject (org.eclipse.emf.ecore.EObject)6 Attribute (org.obeonetwork.dsl.environment.Attribute)5 ForeignKey (org.obeonetwork.dsl.database.ForeignKey)4 Entity (org.obeonetwork.dsl.entity.Entity)4 HashMap (java.util.HashMap)3 Table (org.obeonetwork.dsl.database.Table)3 HashSet (java.util.HashSet)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 EReference (org.eclipse.emf.ecore.EReference)2 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)2 CompositePropertiesEditionPart (org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart)2 Session (org.eclipse.sirius.business.api.session.Session)2 Column (org.obeonetwork.dsl.database.Column)2 Constraint (org.obeonetwork.dsl.database.Constraint)2 Index (org.obeonetwork.dsl.database.Index)2 IndexElement (org.obeonetwork.dsl.database.IndexElement)2