Search in sources :

Example 11 with RecordingCommand

use of org.eclipse.emf.transaction.RecordingCommand 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 12 with RecordingCommand

use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.

the class ScaffoldingOperation method execute.

@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
    if (scaffoldInfo.eResource() == null) {
        // We have to create a scaffold model
        Resource scaffoldResource = createScaffoldResource();
        EObject newInfo = scaffoldResource.getContents().get(0);
        if (newInfo instanceof ScaffoldInfo) {
            scaffoldInfo = (ScaffoldInfo) newInfo;
        }
    }
    final Transformation transformation = createTransformation();
    try {
        RecordingCommand transformCommand = new RecordingCommand(session.getTransactionalEditingDomain(), "Scaffolding transformation") {

            @Override
            protected void doExecute() {
                success = transformation.transform(scaffoldInfo, scaffoldType);
            }
        };
        session.getTransactionalEditingDomain().getCommandStack().execute(transformCommand);
    } catch (RuntimeException e) {
        logError("An error occured during the transformation", e);
        return;
    }
}
Also used : Transformation(fr.gouv.mindef.safran.database.transfo.Transformation) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) EObject(org.eclipse.emf.ecore.EObject) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) CDOResource(org.eclipse.emf.cdo.eresource.CDOResource) ScaffoldInfo(fr.gouv.mindef.safran.database.scaffold.ScaffoldInfo)

Example 13 with RecordingCommand

use of org.eclipse.emf.transaction.RecordingCommand in project InformationSystem by ObeoNetwork.

the class ViewQueryChangeTrigger method localChangesAboutToCommit.

@Override
public Option<Command> localChangesAboutToCommit(Collection<Notification> notifications) {
    Iterable<Notification> querySetNotification = Iterables.filter(notifications, IS_QUERY_SET);
    for (Notification notification : querySetNotification) {
        view = (View) notification.getNotifier();
        query = view.getQuery();
        final Session session = SessionManager.INSTANCE.getSession(view);
        final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
        if (!Strings.isNullOrEmpty(query)) {
            final Command result = new RecordingCommand(domain) {

                @Override
                protected void doExecute() {
                    if (view.getColumns() != null) {
                        view.getColumns().clear();
                    }
                    if (view.getTables() != null) {
                        view.getTables().clear();
                    }
                    // Parse new query
                    ViewContentProvider viewContentProvider = new ViewContentProvider();
                    viewContentProvider.parseViewQuery(query);
                    List<ColObject> listOfColumns = viewContentProvider.getColumns();
                    if (listOfColumns != null) {
                        for (ColObject column : listOfColumns) {
                            ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
                            elem.setName(column.getName());
                            elem.setAlias(column.getAlias());
                            view.getColumns().add(elem);
                        }
                    }
                    List<String> listOfTables = viewContentProvider.getTables();
                    if (listOfTables != null) {
                        for (String table : listOfTables) {
                            ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
                            elem.setName(table);
                            view.getTables().add(elem);
                        }
                    }
                }
            };
            return Options.newSome(result);
        } else if (Strings.isNullOrEmpty(query)) {
            final Command result = new RecordingCommand(domain) {

                @Override
                protected void doExecute() {
                    if (view.getColumns() != null) {
                        view.getColumns().clear();
                    }
                    if (view.getTables() != null) {
                        view.getTables().clear();
                    }
                }
            };
            return Options.newSome(result);
        }
    }
    return Options.newNone();
}
Also used : ColObject(org.obeonetwork.dsl.database.view.parser.ColObject) ViewElement(org.obeonetwork.dsl.database.ViewElement) Notification(org.eclipse.emf.common.notify.Notification) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Command(org.eclipse.emf.common.command.Command) ViewContentProvider(org.obeonetwork.dsl.database.view.parser.ViewContentProvider) Session(org.eclipse.sirius.business.api.session.Session)

Example 14 with RecordingCommand

use of org.eclipse.emf.transaction.RecordingCommand 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 15 with RecordingCommand

use of org.eclipse.emf.transaction.RecordingCommand in project gemoc-studio by eclipse.

the class FsmTraceStateManager method restoreState.

@Override
public void restoreState(State<?, ?> state) {
    if (modelResource != null && state instanceof fsmTrace.States.SpecificState) {
        try {
            final TransactionalEditingDomain ed = TransactionUtil.getEditingDomain(modelResource);
            if (ed != null) {
                final RecordingCommand command = new RecordingCommand(ed, "") {

                    protected void doExecute() {
                        restoreStateExecute((fsmTrace.States.SpecificState) state);
                    }
                };
                CommandExecution.execute(ed, command);
            }
        } catch (Exception e) {
            throw e;
        }
    }
}
Also used : TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand)

Aggregations

RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)15 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)14 Session (org.eclipse.sirius.business.api.session.Session)8 EObject (org.eclipse.emf.ecore.EObject)4 Command (org.eclipse.emf.common.command.Command)3 DRepresentationDescriptor (org.eclipse.sirius.viewpoint.DRepresentationDescriptor)3 Viewpoint (org.eclipse.sirius.viewpoint.description.Viewpoint)3 Collection (java.util.Collection)2 List (java.util.List)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)2 InputDialog (org.eclipse.jface.dialogs.InputDialog)2 ModelAccessor (org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor)2 IEditingSession (org.eclipse.sirius.ui.business.api.session.IEditingSession)2 DRepresentation (org.eclipse.sirius.viewpoint.DRepresentation)2 RepresentationDescription (org.eclipse.sirius.viewpoint.description.RepresentationDescription)2 Shell (org.eclipse.swt.widgets.Shell)2 Interaction (org.obeonetwork.dsl.interaction.Interaction)2 Requirement (org.obeonetwork.dsl.requirement.Requirement)2