Search in sources :

Example 1 with Reference

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

the class ReferencesService method getReferences.

public List<Reference> getReferences(DSemanticDiagram diagram) {
    Set<StructuredType> types = DesignServices.getDisplayedStructuredTypes(diagram);
    List<Reference> references = new ArrayList<Reference>();
    for (StructuredType type : types) {
        references.addAll(type.getOwnedReferences());
    }
    return references;
}
Also used : Reference(org.obeonetwork.dsl.environment.Reference) ArrayList(java.util.ArrayList) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 2 with Reference

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

the class ReferencesService method reconnectBidiReferenceSource.

public Reference reconnectBidiReferenceSource(Reference reference, StructuredType source, StructuredType target) {
    Reference oppositeOf = reference.getOppositeOf();
    // Change container of reference
    reference.setContainingType(target);
    // Change referencedType for opposite reference
    oppositeOf.setReferencedType(target);
    reference.setOppositeOf(oppositeOf);
    return reference;
}
Also used : Reference(org.obeonetwork.dsl.environment.Reference)

Example 3 with Reference

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

the class TypesServices method getAllReferencingStructuredTypes.

private Collection<StructuredType> getAllReferencingStructuredTypes(StructuredType referencedType) {
    Collection<StructuredType> referencingTypes = new HashSet<StructuredType>();
    Session session = new EObjectQuery(referencedType).getSession();
    Collection<Setting> inverseReferences = null;
    ECrossReferenceAdapter xReferencer = null;
    if (session != null) {
        xReferencer = session.getSemanticCrossReferencer();
    }
    if (xReferencer != null) {
        inverseReferences = xReferencer.getInverseReferences(referencedType);
    } else {
        if (referencedType.eResource() != null && referencedType.eResource().getResourceSet() != null) {
            inverseReferences = UsageCrossReferencer.find(referencedType, referencedType.eResource().getResourceSet());
        }
    }
    if (inverseReferences != null) {
        for (Setting setting : inverseReferences) {
            if (setting.getEObject() instanceof StructuredType && setting.getEStructuralFeature() == EnvironmentPackage.Literals.STRUCTURED_TYPE__SUPERTYPE) {
                referencingTypes.add((StructuredType) setting.getEObject());
            } else if (setting.getEObject() instanceof Reference && setting.getEStructuralFeature() == EnvironmentPackage.Literals.REFERENCE__REFERENCED_TYPE) {
                referencingTypes.add(((Reference) setting.getEObject()).getContainingType());
            }
        }
    }
    return referencingTypes;
}
Also used : EObjectQuery(org.eclipse.sirius.business.api.query.EObjectQuery) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Reference(org.obeonetwork.dsl.environment.Reference) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) StructuredType(org.obeonetwork.dsl.environment.StructuredType) HashSet(java.util.HashSet) Session(org.eclipse.sirius.business.api.session.Session)

Example 4 with Reference

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

the class TypesServices method createTypesFromOtherTypes.

public Collection<StructuredType> createTypesFromOtherTypes(Namespace namespace, Collection<StructuredType> types, Collection<Reference> references, String sourceTypeName, String targetTypeName) {
    String uri = PACKAGES_URI.get(targetTypeName);
    EFactory factory = getEFactory(uri);
    EPackage ePackage = factory.getEPackage();
    EClass eClass = (EClass) ePackage.getEClassifier(targetTypeName);
    Map<StructuredType, StructuredType> mappingsTypes = new HashMap<StructuredType, StructuredType>();
    Map<Reference, Reference> mappingsReferences = new HashMap<Reference, Reference>();
    Collection<StructuredType> result = new ArrayList<StructuredType>();
    // Create types
    for (StructuredType type : types) {
        EObject eObject = factory.create(eClass);
        if (eObject instanceof StructuredType) {
            StructuredType type2 = (StructuredType) eObject;
            type2.setName(type.getName());
            type2.getAssociatedTypes().add(type);
            type2.setDescription(type.getDescription());
            namespace.getTypes().add(type2);
            mappingsTypes.put(type, type2);
            result.add(type2);
        }
    }
    // Create references
    for (Reference reference : references) {
        StructuredType sourceType = mappingsTypes.get(reference.getContainingType());
        StructuredType targetType = mappingsTypes.get(reference.getReferencedType());
        Reference newReference = EnvironmentFactory.eINSTANCE.createReference();
        sourceType.getOwnedReferences().add(newReference);
        newReference.setReferencedType(targetType);
        newReference.setDescription(reference.getDescription());
        newReference.setIsComposite(reference.isIsComposite());
        newReference.setIsIdentifier(reference.isIsIdentifier());
        newReference.setMultiplicity(reference.getMultiplicity());
        newReference.setName(reference.getName());
        newReference.setNavigable(reference.isNavigable());
        mappingsReferences.put(reference, newReference);
    }
    // Set opposite references
    for (Reference reference : references) {
        if (reference.getOppositeOf() != null) {
            Reference newReference = mappingsReferences.get(reference);
            if (newReference.getOppositeOf() == null) {
                Reference newOppositeReference = mappingsReferences.get(reference.getOppositeOf());
                newReference.setOppositeOf(newOppositeReference);
            }
        }
    }
    return result;
}
Also used : EFactory(org.eclipse.emf.ecore.EFactory) EClass(org.eclipse.emf.ecore.EClass) HashMap(java.util.HashMap) Reference(org.obeonetwork.dsl.environment.Reference) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) EPackage(org.eclipse.emf.ecore.EPackage) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 5 with Reference

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

the class DBoundElementContentProvider method getDelegatedChildren.

private EObject[] getDelegatedChildren(EObject object) {
    if (object instanceof StructuredType) {
        StructuredType structuredType = (StructuredType) object;
        List<Property> properties = new ArrayList<Property>();
        properties.addAll(structuredType.getAttributes());
        for (StructuredType associatedType : structuredType.getAssociatedTypes()) {
            properties.addAll(associatedType.getAttributes());
        }
        properties.addAll(structuredType.getReferences());
        return (EObject[]) properties.toArray(new EObject[] {});
    } else if (object instanceof Reference) {
        Reference entityReference = (Reference) object;
        if (entityReference.getReferencedType() != null) {
            return getDelegatedChildren(entityReference.getReferencedType());
        } else {
            return new EObject[] {};
        }
    }
    return new EObject[] {};
}
Also used : Reference(org.obeonetwork.dsl.environment.Reference) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Property(org.obeonetwork.dsl.environment.Property) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

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