Search in sources :

Example 1 with DRepresentation

use of org.eclipse.sirius.viewpoint.DRepresentation in project Palladio-Editors-Sirius by PalladioSimulator.

the class OpenRepresentation method execute.

@Override
public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {
    EObject semantic = (EObject) parameters.get("element");
    Session session = SessionManager.INSTANCE.getSession(semantic);
    String viewpointName = (String) parameters.get("Viewpoint");
    String representationDescriptionName = (String) parameters.get("RepresentationDescription");
    String diagramName = (String) parameters.get("Diagram name");
    // Select viewpoint
    List<String> selectedViewpoints = new ArrayList<String>();
    selectedViewpoints.add(viewpointName);
    SiriusCustomUtil.selectViewpoints(session, selectedViewpoints, false, new NullProgressMonitor());
    // Getting selected viewpoint and representation
    Viewpoint viewpoint = SiriusCustomUtil.getSelectedViewpointByName(session, viewpointName);
    RepresentationDescription description = SiriusCustomUtil.findDescription(viewpoint, representationDescriptionName);
    // Find representations
    Collection<DRepresentation> representations = DialectManager.INSTANCE.getRepresentations(semantic, session);
    // create a new representation if none exists and open it
    if (representations.isEmpty()) {
        String representationName = null;
        if (diagramName != null && !diagramName.isEmpty()) {
            representationName = diagramName;
        } else {
            representationName = ((description.getLabel() == null) ? description.getName() : description.getLabel());
        }
        DRepresentation representation = SiriusCustomUtil.createRepresentation(session, representationName, description, semantic, new NullProgressMonitor());
        DialectUIManager.INSTANCE.openEditor(session, representation, new NullProgressMonitor());
    } else {
        // open available representations
        for (DRepresentation representation : representations) {
            DialectUIManager.INSTANCE.openEditor(session, representation, new NullProgressMonitor());
        }
    }
}
Also used : RepresentationDescription(org.eclipse.sirius.viewpoint.description.RepresentationDescription) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) DRepresentation(org.eclipse.sirius.viewpoint.DRepresentation) Session(org.eclipse.sirius.business.api.session.Session)

Example 2 with DRepresentation

use of org.eclipse.sirius.viewpoint.DRepresentation in project Palladio-Editors-Sirius by PalladioSimulator.

the class NewModelWizard method createModel.

private void createModel(final IProject project, final boolean createRepresentation, final String representationName, final IProgressMonitor monitor) throws CoreException {
    monitor.beginTask("Creating Model File", 6000);
    if (!project.hasNature(ModelingProject.NATURE_ID)) {
        ModelingProjectManager.INSTANCE.convertToModelingProject(project, SubMonitor.convert(monitor, "Converting to Modeling Project", 1000));
    }
    final URI representationsURI = SiriusCustomUtil.getRepresentationsURI(project);
    final Session session = SessionManager.INSTANCE.getSession(representationsURI, SubMonitor.convert(monitor, "Getting Session", 1000));
    createResource(session, SubMonitor.convert(monitor, "Creating Resource", 1000));
    HashSet<Viewpoint> selectedViewpoints = new HashSet<Viewpoint>();
    selectedViewpoints.add(viewpoint);
    SiriusCustomUtil.selectViewpoints(session, selectedViewpoints, false, SubMonitor.convert(monitor, "Selecting Viewpoint", 1000));
    // Apparently the selected viewpoint's instance is not the same as the passed instance
    // We retrieve here the actually selected Viewpoint
    Viewpoint selectedViewpoint = SiriusCustomUtil.getSelectedViewpointByName(session, viewpoint.getName());
    RepresentationDescription actualRepresentationDescription = SiriusCustomUtil.findDescription(selectedViewpoint, representationDescription.getName());
    if (createRepresentation) {
        final DRepresentation createdRepresentation = SiriusCustomUtil.createRepresentation(session, representationName, actualRepresentationDescription, this.modelObject, SubMonitor.convert(monitor, "Creating Representation", 1000));
        DialectUIManager.INSTANCE.openEditor(session, createdRepresentation, SubMonitor.convert(monitor, "Opening representation", 1000));
    }
    monitor.done();
}
Also used : RepresentationDescription(org.eclipse.sirius.viewpoint.description.RepresentationDescription) Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) URI(org.eclipse.emf.common.util.URI) DRepresentation(org.eclipse.sirius.viewpoint.DRepresentation) Session(org.eclipse.sirius.business.api.session.Session) HashSet(java.util.HashSet)

Example 3 with DRepresentation

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

the class BindingService method openBindingEditor.

public BindingInfo openBindingEditor(BindingInfo bindingInfo) {
    DBindingEditor editor = null;
    final Session session = SessionManager.INSTANCE.getSession(bindingInfo);
    // Find an editor to open
    Collection<DRepresentation> representations = DialectManager.INSTANCE.getRepresentations(bindingInfo, session);
    for (DRepresentation representation : representations) {
        if (representation instanceof DBindingEditor) {
            editor = (DBindingEditor) representation;
            break;
        }
    }
    // Create an editor if needed
    if (editor == null) {
        RepresentationDescription representationDescription = getBindingEditorRepresentation(session);
        if (representationDescription != null) {
            DRepresentation representation = DialectManager.INSTANCE.createRepresentation(computeBindingEditorName(bindingInfo), bindingInfo, representationDescription, session, new NullProgressMonitor());
            if (representation != null && representation instanceof DBindingEditor) {
                editor = (DBindingEditor) representation;
            }
        }
    }
    // Open the editor
    if (editor != null) {
        UserSession.from(session).openRepresentation(new StructuredSelection(editor));
    }
    return bindingInfo;
}
Also used : RepresentationDescription(org.eclipse.sirius.viewpoint.description.RepresentationDescription) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DBindingEditor(org.obeonetwork.dsl.environment.bindingdialect.DBindingEditor) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DRepresentation(org.eclipse.sirius.viewpoint.DRepresentation) UserSession(org.eclipse.sirius.ui.business.api.session.UserSession) Session(org.eclipse.sirius.business.api.session.Session)

Example 4 with DRepresentation

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

use of org.eclipse.sirius.viewpoint.DRepresentation 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

DRepresentation (org.eclipse.sirius.viewpoint.DRepresentation)7 Session (org.eclipse.sirius.business.api.session.Session)5 RepresentationDescription (org.eclipse.sirius.viewpoint.description.RepresentationDescription)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 Viewpoint (org.eclipse.sirius.viewpoint.description.Viewpoint)4 ArrayList (java.util.ArrayList)2 EObject (org.eclipse.emf.ecore.EObject)2 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)2 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)2 InputDialog (org.eclipse.jface.dialogs.InputDialog)2 Shell (org.eclipse.swt.widgets.Shell)2 HashSet (java.util.HashSet)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 URI (org.eclipse.emf.common.util.URI)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 DSemanticDiagram (org.eclipse.sirius.diagram.DSemanticDiagram)1 DDiagramEditor (org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor)1 ISiriusEditor (org.eclipse.sirius.ui.business.api.editor.ISiriusEditor)1 IEditingSession (org.eclipse.sirius.ui.business.api.session.IEditingSession)1 UserSession (org.eclipse.sirius.ui.business.api.session.UserSession)1