Search in sources :

Example 1 with StructuredType

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

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

the class TypesServices method getAllSelectableExternalStructuredTypes.

public Collection<StructuredType> getAllSelectableExternalStructuredTypes(Namespace namespace, DSemanticDiagram diagram, String typeName) {
    Collection<StructuredType> notReferencedTypes = getAllNotReferencedStructuredTypes(namespace, diagram);
    // Remove already displayed types
    Set<StructuredType> types = DesignServices.getDisplayedStructuredTypes(diagram);
    notReferencedTypes.removeAll(types);
    Collection<StructuredType> selectableTypes = new ArrayList<StructuredType>();
    // Keep only types of the specified typeName
    for (StructuredType structuredType : notReferencedTypes) {
        if (typeName == null || typeName.isEmpty() || typeName.equals(structuredType.eClass().getName())) {
            selectableTypes.add(structuredType);
        }
    }
    return selectableTypes;
}
Also used : ArrayList(java.util.ArrayList) StructuredType(org.obeonetwork.dsl.environment.StructuredType)

Example 3 with StructuredType

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

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

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

the class TypesServices method internalGetAllChildrenStructuredTypes.

private Collection<StructuredType> internalGetAllChildrenStructuredTypes(ObeoDSMObject parent, String typeName) {
    Collection<StructuredType> types = new ArrayList<StructuredType>();
    TreeIterator<EObject> eAllContents = parent.eAllContents();
    while (eAllContents.hasNext()) {
        EObject eObject = (EObject) eAllContents.next();
        if (eObject instanceof StructuredType) {
            // If the type is not specified we do not check on the type
            if (typeName == null || typeName.isEmpty() || typeName.equals(eObject.eClass().getName())) {
                types.add((StructuredType) eObject);
            }
        }
    }
    return types;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) 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