Search in sources :

Example 1 with DRepresentationDescriptor

use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor 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 2 with DRepresentationDescriptor

use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor 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 3 with DRepresentationDescriptor

use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor in project InformationSystem by ObeoNetwork.

the class BusinessProjectImporter method getImpactedReferences.

public Collection<ReferenceData> getImpactedReferences(IProgressMonitor parentMonitor) throws CoreException {
    SubMonitor monitor = SubMonitor.convert(parentMonitor, 2);
    saveAndCloseEditorsOnTargetProject(monitor.newChild(1));
    initializeImportData();
    // Compute the target existing roots that will be replaced
    Collection<EObject> existingTargetSemanticRoots = getAllImpactedTargetSemanticRoots();
    // Collect representations related to the existing target semantic content
    Collection<DRepresentationDescriptor> existingTargetRepresentationDescriptors = ImporterUtil.getRelatedRepresentationDescriptors(targetSession, ImporterUtil.getAllElementsWithChildren(existingTargetSemanticRoots));
    Collection<DRepresentation> existingTargetRepresentations = new ArrayList<DRepresentation>();
    for (DRepresentationDescriptor existingTargetRepresentationDescriptor : existingTargetRepresentationDescriptors) {
        existingTargetRepresentations.add(existingTargetRepresentationDescriptor.getRepresentation());
    }
    // Collect references
    Collection<ReferenceData> allReferences = ImporterUtil.getReferencingElements(existingTargetSemanticRoots, targetSession);
    // Filter references not impacted by the removal
    Collection<ReferenceData> filteredReferences = filterOutOfConcernReferences(allReferences, existingTargetSemanticRoots, existingTargetRepresentations);
    monitor.worked(1);
    monitor.done();
    return filteredReferences;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) SubMonitor(org.eclipse.core.runtime.SubMonitor) ArrayList(java.util.ArrayList) DRepresentationDescriptor(org.eclipse.sirius.viewpoint.DRepresentationDescriptor) DRepresentation(org.eclipse.sirius.viewpoint.DRepresentation)

Example 4 with DRepresentationDescriptor

use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor in project InformationSystem by ObeoNetwork.

the class BusinessProjectImporter method importElementsIntoTargetProject.

public void importElementsIntoTargetProject(IProgressMonitor parentMonitor) throws CoreException {
    final SubMonitor monitor = SubMonitor.convert(parentMonitor, 5);
    // Ensure project is closed
    saveAndCloseEditorsOnTargetProject(monitor.newChild(1));
    initializeImportData();
    final Map<String, List<EObject>> requirementReferencesCache = cacheRequirementReferences();
    // Create command
    TransactionalEditingDomain editingDomain = targetSession.getTransactionalEditingDomain();
    RecordingCommand command = new RecordingCommand(editingDomain) {

        @Override
        protected void doExecute() {
            // At the end of the import, if there is no "requirement.Repository" object in the target MOE project, then create one named after the MOE project.
            // This verification is done *before* importing models from the MOA otherwise they get added onto the session.
            boolean repositoryExistsBeforeImporting = false;
            for (Resource semanticResource : SessionManager.INSTANCE.getExistingSession(targetProject.getMainRepresentationsFileURI(monitor).get()).getSemanticResources()) {
                repositoryExistsBeforeImporting = repositoryExistsBeforeImporting || EcoreUtil.getObjectByType(semanticResource.getContents(), RequirementPackage.Literals.REPOSITORY) != null;
            }
            // Delete the content of the impacted resources and the related representations
            final Collection<EObject> existingTargetSemanticRoots = getAllImpactedTargetSemanticRoots();
            if (!existingTargetSemanticRoots.isEmpty()) {
                // Delete related representations
                final Collection<DRepresentationDescriptor> existingRepresentationDescriptors = ImporterUtil.getRelatedRepresentationDescriptors(targetSession, ImporterUtil.getAllElementsWithChildren(existingTargetSemanticRoots));
                if (!existingRepresentationDescriptors.isEmpty()) {
                    for (DRepresentationDescriptor dRepresentationDescriptor : existingRepresentationDescriptors) {
                        DialectManager.INSTANCE.deleteRepresentation(dRepresentationDescriptor, targetSession);
                    }
                }
                // Delete existing objects
                for (EObject semanticRoot : existingTargetSemanticRoots) {
                    if (semanticRoot instanceof Repository) {
                        for (Requirement req : ImporterUtil.getAllContentsOfType(semanticRoot, Requirement.class)) {
                            req.getReferencedObject().clear();
                            SiriusUtil.delete(req, targetSession);
                        }
                    }
                    SiriusUtil.delete(semanticRoot, targetSession);
                }
            }
            // Create semantic resources and their content
            for (EObject sourceRoot : importData.getSourceRoots()) {
                EObject copyRoot = importData.getCopyEObject(sourceRoot);
                String targetPath = getTargetResourcePath(sourceRoot);
                addToSemanticResource(copyRoot, targetPath);
            }
            // Add representations
            for (DRepresentationDescriptor sourceRepresentationDescriptor : importData.getSourceRepresentationDescriptors()) {
                DRepresentationDescriptor copyRepresentationDescriptor = (DRepresentationDescriptor) importData.getCopyEObject(sourceRepresentationDescriptor);
                Viewpoint viewpoint = getViewpoint(copyRepresentationDescriptor);
                addRepresentationDescriptor(copyRepresentationDescriptor, viewpoint);
            }
            // Restore the local requirement references
            restoreRequirementReferences(requirementReferencesCache);
            // }
            if (!repositoryExistsBeforeImporting) {
                Repository requirementsRepository = RequirementFactory.eINSTANCE.createRepository();
                addToSemanticResource(requirementsRepository, targetProject.getProject().getName() + "/" + targetProject.getProject().getName() + ".requirement");
            }
        }
    };
    // Execute the command
    editingDomain.getCommandStack().execute(command);
    monitor.worked(3);
    // Save project
    targetSession.save(monitor.newChild(1));
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) Resource(org.eclipse.emf.ecore.resource.Resource) DRepresentationDescriptor(org.eclipse.sirius.viewpoint.DRepresentationDescriptor) Requirement(org.obeonetwork.dsl.requirement.Requirement) Repository(org.obeonetwork.dsl.requirement.Repository) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 5 with DRepresentationDescriptor

use of org.eclipse.sirius.viewpoint.DRepresentationDescriptor in project InformationSystem by ObeoNetwork.

the class ImportData method initializeCopyElements.

private void initializeCopyElements() {
    Collection<EObject> sourceEObjects = new ArrayList<EObject>();
    sourceEObjects.addAll(sourceRoots);
    sourceEObjects.addAll(sourceRepresentationDescriptors);
    for (DRepresentationDescriptor dRepresentationDescriptor : sourceRepresentationDescriptors) {
        sourceEObjects.add(dRepresentationDescriptor.getRepresentation());
    }
    Copier copier = new Copier();
    copier.copyAll(sourceEObjects);
    copier.copyReferences();
    // Build the copy to source map
    copyToSourceMap = new HashMap<EObject, EObject>();
    for (EObject sourceEObject : sourceEObjects) {
        copyToSourceMap.put(copier.get(sourceEObject), sourceEObject);
    }
    // Save the copier as the source to copy map
    sourceToCopyMap = copier;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Copier(org.eclipse.emf.ecore.util.EcoreUtil.Copier) ArrayList(java.util.ArrayList) DRepresentationDescriptor(org.eclipse.sirius.viewpoint.DRepresentationDescriptor)

Aggregations

DRepresentationDescriptor (org.eclipse.sirius.viewpoint.DRepresentationDescriptor)5 ArrayList (java.util.ArrayList)3 EObject (org.eclipse.emf.ecore.EObject)3 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)3 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)3 Collection (java.util.Collection)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)2 Session (org.eclipse.sirius.business.api.session.Session)2 ModelAccessor (org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor)2 IEditingSession (org.eclipse.sirius.ui.business.api.session.IEditingSession)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 Copier (org.eclipse.emf.ecore.util.EcoreUtil.Copier)1 DRepresentation (org.eclipse.sirius.viewpoint.DRepresentation)1 Viewpoint (org.eclipse.sirius.viewpoint.description.Viewpoint)1 Interaction (org.obeonetwork.dsl.interaction.Interaction)1 Repository (org.obeonetwork.dsl.requirement.Repository)1 Requirement (org.obeonetwork.dsl.requirement.Requirement)1