Search in sources :

Example 1 with Session

use of org.eclipse.sirius.business.api.session.Session 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 Session

use of org.eclipse.sirius.business.api.session.Session in project Palladio-Editors-Sirius by PalladioSimulator.

the class AddLinkingResourceAction method execute.

@Override
public void execute(final Collection<? extends EObject> selections, final Map<String, Object> parameters) {
    final Object parameter = parameters.get(NEW_COMMUNICATION_LINK_RESOURCE_SPECIFICATION);
    if (parameter == null || !(parameter instanceof CommunicationLinkResourceSpecification)) {
        return;
    }
    final CommunicationLinkResourceSpecification communicationLinkResourceSpecification = (CommunicationLinkResourceSpecification) parameter;
    // latency
    final PCMRandomVariable latency = getRandomVariableFromStoExDialog(LATENCY_DISPLAY_TITLE);
    if (latency == null) {
        return;
    }
    communicationLinkResourceSpecification.setLatency_CommunicationLinkResourceSpecification(latency);
    // throughput
    final PCMRandomVariable throughput = getRandomVariableFromStoExDialog(THROUGHPUT_DISPLAY_TITLE);
    if (throughput == null) {
        return;
    }
    communicationLinkResourceSpecification.setThroughput_CommunicationLinkResourceSpecification(throughput);
    // Communication Link
    Session session = SessionManager.INSTANCE.getSession(communicationLinkResourceSpecification);
    URI uri = URI.createURI("pathmap://PCM_MODELS/Palladio.resourcetype");
    Resource palladioResources = SiriusCustomUtil.getResourceByURI(uri, session);
    if (palladioResources != null) {
        ResourceRepository rep = (ResourceRepository) palladioResources.getContents().iterator().next();
        for (EObject o : rep.eContents()) {
            if ((o instanceof CommunicationLinkResourceType) && ((CommunicationLinkResourceType) o).getEntityName().equals("LAN")) {
                communicationLinkResourceSpecification.setCommunicationLinkResourceType_CommunicationLinkResourceSpecification((CommunicationLinkResourceType) o);
                break;
            }
        }
    }
}
Also used : CommunicationLinkResourceSpecification(org.palladiosimulator.pcm.resourceenvironment.CommunicationLinkResourceSpecification) EObject(org.eclipse.emf.ecore.EObject) CommunicationLinkResourceType(org.palladiosimulator.pcm.resourcetype.CommunicationLinkResourceType) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) ResourceRepository(org.palladiosimulator.pcm.resourcetype.ResourceRepository) URI(org.eclipse.emf.common.util.URI) PCMRandomVariable(org.palladiosimulator.pcm.core.PCMRandomVariable) Session(org.eclipse.sirius.business.api.session.Session)

Example 3 with Session

use of org.eclipse.sirius.business.api.session.Session 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 4 with Session

use of org.eclipse.sirius.business.api.session.Session in project Palladio-Editors-Sirius by PalladioSimulator.

the class NewPalladioProjectWizard method activateViewpoints.

/**
 * Activate viewpoints.
 */
private void activateViewpoints(final IProject projectHandle, final SubMonitor subMonitor) {
    final URI representationsURI = SiriusCustomUtil.getRepresentationsURI(projectHandle);
    final Session session = SessionManager.INSTANCE.getSession(representationsURI, subMonitor);
    final Set<Viewpoint> registry = ViewpointRegistry.getInstance().getViewpoints();
    final HashSet<Viewpoint> viewpoints = new HashSet<>();
    final List<String> extensions = getExtensions(session);
    for (final Viewpoint viewpoint : registry) {
        final String ext = viewpoint.getModelFileExtension();
        if (extensions.contains(ext)) {
            viewpoints.add(viewpoint);
        }
    }
    SiriusCustomUtil.selectViewpoints(session, viewpoints, true, subMonitor);
}
Also used : Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) URI(org.eclipse.emf.common.util.URI) Session(org.eclipse.sirius.business.api.session.Session) HashSet(java.util.HashSet)

Example 5 with Session

use of org.eclipse.sirius.business.api.session.Session in project Palladio-Editors-Sirius by PalladioSimulator.

the class ActivateViewpoint method execute.

@Override
public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {
    EObject element = (EObject) parameters.get("element");
    Session session = SessionManager.INSTANCE.getSession(element);
    String viewpointName = (String) parameters.get("Viewpoint");
    List<String> selectedViewpoints = new ArrayList<String>();
    selectedViewpoints.add(viewpointName);
    SiriusCustomUtil.selectViewpoints(session, selectedViewpoints, true, new NullProgressMonitor());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) Session(org.eclipse.sirius.business.api.session.Session)

Aggregations

Session (org.eclipse.sirius.business.api.session.Session)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 URI (org.eclipse.emf.common.util.URI)4 EObject (org.eclipse.emf.ecore.EObject)4 ArrayList (java.util.ArrayList)3 Viewpoint (org.eclipse.sirius.viewpoint.description.Viewpoint)3 HashSet (java.util.HashSet)2 DRepresentation (org.eclipse.sirius.viewpoint.DRepresentation)2 RepresentationDescription (org.eclipse.sirius.viewpoint.description.RepresentationDescription)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IFile (org.eclipse.core.resources.IFile)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IPath (org.eclipse.core.runtime.IPath)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 AbstractTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand)1 Allocation (org.palladiosimulator.pcm.allocation.Allocation)1 PCMRandomVariable (org.palladiosimulator.pcm.core.PCMRandomVariable)1