Search in sources :

Example 6 with ECrossReferenceAdapter

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

the class DeleteStateMachineHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    final StateMachine stateMachine = extractStateMachine(event);
    if (stateMachine == null) {
        return null;
    }
    boolean confirm = MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Delete State Machine", "Delete the selected state machine ?");
    if (confirm) {
        final Session session = SessionManager.INSTANCE.getSession(stateMachine);
        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(stateMachine, session);
                // Delete representations
                for (DRepresentationDescriptor representationDescriptor : representationDescriptors) {
                    closeEditor(session, representationDescriptor.getRepresentation());
                    DialectManager.INSTANCE.deleteRepresentation(representationDescriptor, session);
                }
                // Delete StateMachine
                modelAccessor.eDelete(stateMachine, semanticCrossReferencer);
            }
        });
    }
    return null;
}
Also used : ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) StateMachine(org.obeonetwork.dsl.statemachine.StateMachine) 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 7 with ECrossReferenceAdapter

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

the class DeleteServices method deleteObeoDSMObject.

public void deleteObeoDSMObject(StructuredType type) {
    // First we have to delete all references pointing towards this type
    Session session = getSession(type);
    ECrossReferenceAdapter crossReferencer = session.getSemanticCrossReferencer();
    Collection<Setting> inverseReferences = crossReferencer.getInverseReferences(type, true);
    for (Setting setting : inverseReferences) {
        if (EnvironmentPackage.Literals.REFERENCE__REFERENCED_TYPE == setting.getEStructuralFeature()) {
            delete((ObeoDSMObject) setting.getEObject(), session);
        }
    }
    delete(type);
}
Also used : ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) Session(org.eclipse.sirius.business.api.session.Session)

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