Search in sources :

Example 1 with RecordingCommand

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

the class AddAdditionalObjectsWizard method performFinish.

/* (non-Javadoc)
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
public boolean performFinish() {
    final Collection<EObject> newAdditionalObjects1 = additionalResourcesPage.getAdditionalObjects1();
    final Collection<EObject> newAdditionalObjects2 = additionalResourcesPage.getAdditionalObjects2();
    final boolean hasBeenModified1 = hasBeenModified(scaffoldInfo.getLeftToRightAdditionalObjects(), newAdditionalObjects1);
    final boolean hasBeenModified2 = hasBeenModified(scaffoldInfo.getRightToLeftAdditionalObjects(), newAdditionalObjects2);
    if (hasBeenModified1 || hasBeenModified2) {
        Session session = SessionManager.INSTANCE.getSession(scaffoldInfo);
        TransactionalEditingDomain editingDomain = session.getTransactionalEditingDomain();
        RecordingCommand updatingCmd = new RecordingCommand(editingDomain, "Updating additional objects") {

            @Override
            protected void doExecute() {
                if (hasBeenModified1) {
                    ScaffoldType leftToRightScaffoldType = scaffoldInfo.getLeftToRightTransformationType();
                    scaffoldInfo.clearAdditionalObjectsForTransformation(leftToRightScaffoldType);
                    for (EObject newObject : newAdditionalObjects1) {
                        scaffoldInfo.addAdditionalObjectsForTransformation(newObject, leftToRightScaffoldType);
                    }
                }
                if (hasBeenModified2) {
                    ScaffoldType rightToleftScaffoldType = scaffoldInfo.getRightToLeftTransformationType();
                    scaffoldInfo.clearAdditionalObjectsForTransformation(rightToleftScaffoldType);
                    for (EObject newObject : newAdditionalObjects2) {
                        scaffoldInfo.addAdditionalObjectsForTransformation(newObject, rightToleftScaffoldType);
                    }
                }
            }
        };
        editingDomain.getCommandStack().execute(updatingCmd);
    }
    return true;
}
Also used : ScaffoldType(fr.gouv.mindef.safran.database.scaffold.ScaffoldType) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) EObject(org.eclipse.emf.ecore.EObject) Session(org.eclipse.sirius.business.api.session.Session)

Example 2 with RecordingCommand

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

the class UIConfigurationServices method saveUIConfiguration.

/**
 * Save the configuration on the specified viewpoint analysis
 * @param configuration Configuration to be saved
 * @param analysis Viewpoint analysis concerned by the configuration
 */
public static void saveUIConfiguration(final UIConfiguration configuration, final DAnalysis analysis) {
    if (!analysis.equals(configuration.getViewpointAnalysis())) {
        configuration.setViewpointAnalysis(analysis);
    }
    final Session session = getSessionFromAnalysis(analysis);
    if (session != null) {
        final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(analysis);
        final Command cmd = new RecordingCommand(domain) {

            @Override
            protected void doExecute() {
                FeatureExtensionsManager.INSTANCE.saveFeatureExtensionData(GraalFeatureExtension.FEATURE_EXTENSION_NAME, session, analysis, configuration);
            }
        };
        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) Session(org.eclipse.sirius.business.api.session.Session)

Example 3 with RecordingCommand

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

the class CreateSequenceDiagramAction method run.

@Override
public void run() {
    if (context == null) {
        return;
    }
    final Shell shell = Activator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
    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 Sequence diagram", null);
                int buttonPressed = dialog.open();
                if (buttonPressed == InputDialog.OK) {
                    String diagramName = dialog.getValue();
                    // Create a new interaction instance
                    Interaction interaction = InteractionFactory.eINSTANCE.createInteraction();
                    interaction.setName(diagramName);
                    context.getBehaviours().add(interaction);
                    Collection<RepresentationDescription> descs = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), interaction);
                    for (RepresentationDescription desc : descs) {
                        Viewpoint viewpoint = (Viewpoint) desc.eContainer();
                        if (InteractionAnalysisContextMenuActionProvider.isInteractionViewpoint(viewpoint) && "Sequence Diagram".equals(desc.getName())) {
                            // Create the new diagram
                            if (DialectManager.INSTANCE.canCreate(interaction, desc)) {
                                DRepresentation sequenceDiagram = DialectManager.INSTANCE.createRepresentation(diagramName, interaction, desc, session, new NullProgressMonitor());
                                if (sequenceDiagram != null) {
                                    DialectUIManager.INSTANCE.openEditor(session, sequenceDiagram, 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) Interaction(org.obeonetwork.dsl.interaction.Interaction) 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)

Example 4 with RecordingCommand

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

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

the class Activator method refreshDecorationsOnDiagram.

private void refreshDecorationsOnDiagram(final DSemanticDiagram diagram, final Session session) {
    EList<AdditionalLayer> activatedTransientLayers = diagram.getActivatedTransientLayers();
    for (final AdditionalLayer additionalLayer : activatedTransientLayers) {
        // We want the "EObjectWithRequirement" layer
        if (REQUIREMENTS_DECORATION_LAYER_NAME.equals(additionalLayer.getName())) {
            TransactionalEditingDomain ted = session.getTransactionalEditingDomain();
            ted.getCommandStack().execute(new RecordingCommand(ted) {

                @Override
                protected void doExecute() {
                    // Due to a bug in Sirius we have to remove the existing decorations before calling the update method
                    for (DDiagramElement diagElement : diagram.getDiagramElements()) {
                        Iterator<Decoration> it = diagElement.getTransientDecorations().iterator();
                        while (it.hasNext()) {
                            Decoration decoration = it.next();
                            if (REQUIREMENTS_DECORATION_NAME.equals(decoration.getDescription().getName())) {
                                it.remove();
                            }
                        }
                    }
                    List<Layer> layersToRefresh = Arrays.asList((Layer) additionalLayer);
                    new DecorationHelper(diagram).updateDecorations(layersToRefresh);
                }
            });
        }
    }
}
Also used : DecorationHelper(org.eclipse.sirius.diagram.business.api.helper.decoration.DecorationHelper) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Iterator(java.util.Iterator) EList(org.eclipse.emf.common.util.EList) List(java.util.List) AdditionalLayer(org.eclipse.sirius.diagram.description.AdditionalLayer) DDiagramElement(org.eclipse.sirius.diagram.DDiagramElement) Layer(org.eclipse.sirius.diagram.description.Layer) AdditionalLayer(org.eclipse.sirius.diagram.description.AdditionalLayer) Decoration(org.eclipse.sirius.viewpoint.Decoration)

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