Search in sources :

Example 6 with RecordingCommand

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

the class LinkRequirementsDialog method okPressed.

@Override
protected void okPressed() {
    TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(this.selectedEObject);
    RecordingCommand cmd = new // $NON-NLS-1$
    RecordingCommand(// $NON-NLS-1$
    editingDomain, // $NON-NLS-1$
    "Link Requirements") {

        protected void doExecute() {
            // Clear all requirements links
            for (Requirement requirement : RequirementService.getLinkedRequirements(LinkRequirementsDialog.this.selectedEObject)) {
                requirement.getReferencedObject().remove(LinkRequirementsDialog.this.selectedEObject);
            }
            // Add new requirements links
            for (Object checkedElement : LinkRequirementsDialog.this.checkboxTreeViewer.getCheckedElements()) {
                if (checkedElement instanceof Requirement) {
                    Requirement requirement = (Requirement) checkedElement;
                    requirement.getReferencedObject().add(LinkRequirementsDialog.this.selectedEObject);
                }
            }
        }
    };
    editingDomain.getCommandStack().execute(cmd);
    super.okPressed();
}
Also used : Requirement(org.obeonetwork.dsl.requirement.Requirement) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) EObject(org.eclipse.emf.ecore.EObject)

Example 7 with RecordingCommand

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

the class ProjectLibraryImporter method executeInRecordingCommand.

private void executeInRecordingCommand(final Session session, final Runnable runnable) {
    final TransactionalEditingDomain ted = session.getTransactionalEditingDomain();
    ted.getCommandStack().execute(new RecordingCommand(ted) {

        @Override
        protected void doExecute() {
            runnable.run();
        }
    });
}
Also used : TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand)

Example 8 with RecordingCommand

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

the class UnlinkRequirementAction method run.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.jface.action.Action#run()
 */
@Override
public void run() {
    MessageDialog dialog = new MessageDialog(linksView.getSite().getShell(), // $NON-NLS-1$
    RequirementLinkerPlugin.getInstance().getString("DeleteRequirementLinkAction_ConfirmDialog_title"), null, // $NON-NLS-1$
    RequirementLinkerPlugin.getInstance().getString("DeleteRequirementLinkAction_ConfirmDialog_msg"), MessageDialog.CONFIRM, new String[] { IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL }, 1);
    boolean openConfirm = dialog.open() == Window.OK;
    if (openConfirm) {
        Session session = new EObjectQuery(linksView.getInput()).getSession();
        if (session != null) {
            TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
            RecordingCommand cmd = new // $NON-NLS-1$
            RecordingCommand(// $NON-NLS-1$
            editingDomain, // $NON-NLS-1$
            "UnLink Requirements") {

                protected void doExecute() {
                    for (EObjectLink link : linksView.getSelectedEntries()) {
                        if (link instanceof RequirementLink) {
                            RequirementLink reqLink = (RequirementLink) link;
                            reqLink.getRequirement().getReferencedObject().remove(linksView.getInput());
                        }
                    }
                }
            };
            editingDomain.getCommandStack().execute(cmd);
        }
        linksView.refresh();
    }
}
Also used : EObjectQuery(org.eclipse.sirius.business.api.query.EObjectQuery) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) EObjectLink(org.obeonetwork.tools.linker.EObjectLink) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) RequirementLink(org.obeonetwork.tools.requirement.core.RequirementLink) Session(org.eclipse.sirius.business.api.session.Session)

Example 9 with RecordingCommand

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

the class ManifestServices method executeInRecordingCommand.

private void executeInRecordingCommand(final Session session, final Runnable runnable) {
    final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
    final Command cmd = new RecordingCommand(domain) {

        @Override
        protected void doExecute() {
            runnable.run();
        }
    };
    domain.getCommandStack().execute(cmd);
}
Also used : 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)

Example 10 with RecordingCommand

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

the class CreateStateMachineDiagramAction method run.

@Override
public void run() {
    if (context == null) {
        return;
    }
    final Shell shell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
    // TransactionalEditingDomain editingDomain = EditingDomainService.getInstance().getEditingDomainProvider().getEditingDomain();
    Session session = SessionManager.INSTANCE.getSession(context);
    if (session == null) {
        return;
    }
    TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
    if (editingDomain == null) {
        return;
    }
    RecordingCommand cmd = new RecordingCommand(editingDomain, "Create Sequence diagram") {

        protected void doExecute() {
            // Get Session
            Session session = SessionManager.INSTANCE.getSession(context);
            if (session != null) {
                // Ask the user to provide a name for the diagram
                InputDialog dialog = new InputDialog(shell, "New representation", "New representation name", "new State machine diagram", null);
                int buttonPressed = dialog.open();
                if (buttonPressed == InputDialog.OK) {
                    String diagramName = dialog.getValue();
                    // Create a new state machine instance
                    StateMachine statemachine = StateMachineFactory.eINSTANCE.createStateMachine();
                    statemachine.setName(diagramName);
                    context.getBehaviours().add(statemachine);
                    Collection<RepresentationDescription> descs = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), statemachine);
                    for (RepresentationDescription desc : descs) {
                        Viewpoint viewpoint = (Viewpoint) desc.eContainer();
                        if (StateMachineAnalysisContextMenuActionProvider.isStateMachineViewpoint(viewpoint) && "State Machine Diagram".equals(desc.getName())) {
                            // Create the new diagram
                            if (DialectManager.INSTANCE.canCreate(statemachine, desc)) {
                                DRepresentation stateMachineDiagram = DialectManager.INSTANCE.createRepresentation(diagramName, statemachine, desc, session, new NullProgressMonitor());
                                if (stateMachineDiagram != null) {
                                    DialectUIManager.INSTANCE.openEditor(session, stateMachineDiagram, new NullProgressMonitor());
                                }
                            }
                        }
                    }
                }
            }
        }
    };
    editingDomain.getCommandStack().execute(cmd);
}
Also used : RepresentationDescription(org.eclipse.sirius.viewpoint.description.RepresentationDescription) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) InputDialog(org.eclipse.jface.dialogs.InputDialog) StateMachine(org.obeonetwork.dsl.statemachine.StateMachine) Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) Shell(org.eclipse.swt.widgets.Shell) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) DRepresentation(org.eclipse.sirius.viewpoint.DRepresentation) Session(org.eclipse.sirius.business.api.session.Session)

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