Search in sources :

Example 1 with ECrossReferenceAdapter

use of org.eclipse.emf.ecore.util.ECrossReferenceAdapter 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 2 with ECrossReferenceAdapter

use of org.eclipse.emf.ecore.util.ECrossReferenceAdapter in project InformationSystem by ObeoNetwork.

the class DeleteMappingCommand method doExecute.

@Override
protected void doExecute() {
    if (bindingEdge.getTarget() != null && bindingEdge.getTarget() instanceof BindingReference) {
        BindingReference bindingReference = (BindingReference) bindingEdge.getTarget();
        Session session = SessionManager.INSTANCE.getSession(bindingReference);
        ECrossReferenceAdapter crossReferencer = session.getSemanticCrossReferencer();
        BindingElement left = bindingReference.getLeft();
        BindingElement right = bindingReference.getRight();
        if (hasNoOtherReference(left)) {
            // Delete the useless element
            accessor.eDelete(left, crossReferencer);
        }
        if (hasNoOtherReference(right)) {
            // Delete the useless element
            accessor.eDelete(right, crossReferencer);
        } else {
        }
        accessor.eDelete(bindingReference, crossReferencer);
        accessor.eDelete(bindingEdge, crossReferencer);
        bindingEdge.setLeft(null);
        bindingEdge.setRight(null);
    } else {
        EcoreUtil.delete(bindingEdge);
        bindingEdge.setLeft(null);
        bindingEdge.setRight(null);
    }
}
Also used : ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) BindingElement(org.obeonetwork.dsl.environment.BindingElement) BindingReference(org.obeonetwork.dsl.environment.BindingReference) Session(org.eclipse.sirius.business.api.session.Session)

Example 3 with ECrossReferenceAdapter

use of org.eclipse.emf.ecore.util.ECrossReferenceAdapter in project InformationSystem by ObeoNetwork.

the class DBindingEditorCreationDescriptionImpl method getMappings.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.sirius.viewpoint.description.tool.impl.RepresentationCreationDescriptionImpl#getMappings()
 * @generated NOT
 */
@Override
public EList<RepresentationElementMapping> getMappings() {
    if (this.eResource() == null) {
        throw new UnsupportedOperationException();
    }
    ECrossReferenceAdapter crossReferencer = ECrossReferenceAdapter.getCrossReferenceAdapter(this.eResource().getResourceSet());
    if (crossReferencer == null) {
        throw new UnsupportedOperationException();
    }
    final List<RepresentationElementMapping> mappings = new LinkedList<RepresentationElementMapping>();
    final Collection<Setting> settings = crossReferencer.getInverseReferences(this, true);
    for (final Setting setting : settings) {
        final EObject eReferencer = setting.getEObject();
        final EStructuralFeature eFeature = setting.getEStructuralFeature();
        if (eReferencer instanceof RepresentationElementMapping && eFeature.equals(org.eclipse.sirius.viewpoint.description.DescriptionPackage.eINSTANCE.getRepresentationElementMapping_DetailDescriptions())) {
            mappings.add((RepresentationElementMapping) eReferencer);
        }
    }
    return new BasicEList<RepresentationElementMapping>(mappings);
}
Also used : ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) RepresentationElementMapping(org.eclipse.sirius.viewpoint.description.RepresentationElementMapping) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) BasicEList(org.eclipse.emf.common.util.BasicEList) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) LinkedList(java.util.LinkedList)

Example 4 with ECrossReferenceAdapter

use of org.eclipse.emf.ecore.util.ECrossReferenceAdapter in project InformationSystem by ObeoNetwork.

the class DeleteInteractionHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final Interaction interaction = extractInteraction(event);
    if (interaction == null) {
        return null;
    }
    boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Delete interaction", "Delete the selected interaction ?");
    if (confirm) {
        final Session session = SessionManager.INSTANCE.getSession(interaction);
        final ModelAccessor modelAccessor = session.getModelAccessor();
        final ECrossReferenceAdapter semanticCrossReferencer = session.getSemanticCrossReferencer();
        TransactionalEditingDomain transactionalEditingDomain = session.getTransactionalEditingDomain();
        transactionalEditingDomain.getCommandStack().execute(new RecordingCommand(transactionalEditingDomain) {

            @Override
            protected void doExecute() {
                // Retrieve associated representations
                Collection<DRepresentationDescriptor> representationDescriptors = DialectManager.INSTANCE.getRepresentationDescriptors(interaction, session);
                // Delete representations
                for (DRepresentationDescriptor representationDescriptor : representationDescriptors) {
                    closeEditor(session, representationDescriptor.getRepresentation());
                    DialectManager.INSTANCE.deleteRepresentation(representationDescriptor, session);
                }
                // Delete interaction
                modelAccessor.eDelete(interaction, semanticCrossReferencer);
            }
        });
    }
    return null;
}
Also used : ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Interaction(org.obeonetwork.dsl.interaction.Interaction) ModelAccessor(org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor) Collection(java.util.Collection) DRepresentationDescriptor(org.eclipse.sirius.viewpoint.DRepresentationDescriptor) Session(org.eclipse.sirius.business.api.session.Session) IEditingSession(org.eclipse.sirius.ui.business.api.session.IEditingSession)

Example 5 with ECrossReferenceAdapter

use of org.eclipse.emf.ecore.util.ECrossReferenceAdapter in project InformationSystem by ObeoNetwork.

the class RequirementService method getLinkedRequirements.

private static Set<Requirement> getLinkedRequirements(Session session, EObject eObject) {
    ECrossReferenceAdapter crossReferenceAdapter = session.getSemanticCrossReferencer();
    HashSet<Requirement> linkedRequirements = new HashSet<Requirement>();
    for (Setting setting : crossReferenceAdapter.getInverseReferences(eObject)) {
        if (setting.getEObject() instanceof Requirement) {
            Requirement requirement = (Requirement) setting.getEObject();
            // duplicates
            if (requirement.getReferencedObject().contains(eObject)) {
                linkedRequirements.add(requirement);
            }
        }
    }
    return linkedRequirements;
}
Also used : ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Requirement(org.obeonetwork.dsl.requirement.Requirement) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) HashSet(java.util.HashSet)

Aggregations

ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)7 Session (org.eclipse.sirius.business.api.session.Session)5 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)4 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)2 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)2 ModelAccessor (org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor)2 IEditingSession (org.eclipse.sirius.ui.business.api.session.IEditingSession)2 DRepresentationDescriptor (org.eclipse.sirius.viewpoint.DRepresentationDescriptor)2 LinkedList (java.util.LinkedList)1 BasicEList (org.eclipse.emf.common.util.BasicEList)1 EObject (org.eclipse.emf.ecore.EObject)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 InternalEObject (org.eclipse.emf.ecore.InternalEObject)1 EObjectQuery (org.eclipse.sirius.business.api.query.EObjectQuery)1 RepresentationElementMapping (org.eclipse.sirius.viewpoint.description.RepresentationElementMapping)1 BindingElement (org.obeonetwork.dsl.environment.BindingElement)1 BindingReference (org.obeonetwork.dsl.environment.BindingReference)1 Reference (org.obeonetwork.dsl.environment.Reference)1