private Collection<Resource> getAllSemanticResourcesInSession(EObject any) { Session session = SessionManager.INSTANCE.getSession(any); if (session != null) { return session.getSemanticResources(); } return Collections.emptyList(); }
/** * Builds the command which will execute the user-specified operations to create a new operand. * * @param nodeContainer the container in which to create the operand. * @param tool the tool to use to create the operand. * @param startingEndPredecessor the event end graphically preceding the starting position of the * new Operand. * @param finishingEndPredecessor the event end graphically preceding the finishing position of * the new Operand. * @return a command to create the execution. */ public static org.eclipse.emf.common.command.Command buildCreateOperantCommandFromTool( DDiagramElementContainer nodeContainer, final OperandCreationTool tool, final EventEnd startingEndPredecessor, final EventEnd finishingEndPredecessor) { CommandBuilder builder = new OperandCreationCommandBuilder( tool, nodeContainer, startingEndPredecessor, finishingEndPredecessor); Session session = SessionManager.INSTANCE.getSession(nodeContainer.getTarget()); return getCommand(builder, session); }
/** * Builds the command which will execute the user-specified operations to create a new state. * * @param node the node on which to create the new state. * @param tool the tool to use to create the state. * @param startingEndPredecessor the event end graphically preceding the starting position of the * new state. * @param finishingEndPredecessor the event end graphically preceding the finishing position of * the new state. * @return a command to create the state. */ public static Command buildCreateStateCommandFromTool( final DNode node, final StateCreationTool tool, final EventEnd startingEndPredecessor, final EventEnd finishingEndPredecessor) { CommandBuilder builder = new StateCreationCommandBuilder( tool, node, startingEndPredecessor, finishingEndPredecessor); Session session = SessionManager.INSTANCE.getSession(node.getTarget()); return getCommand(builder, session); }
/** * Builds the command which will execute the user-specified operations to create a new observation * point. * * @param diagramElement the clicked diagram element. * @param tool the tool to use to create the execution. * @param startingEndPredecessor the event end graphically preceding the starting position of the * new execution. * @param finishingEndPredecessor the event end graphically preceding the finishing position of * the new execution. * @return a command to create the execution. */ public static Command buildCreateObservationPointCommandFromTool( final DDiagramElement diagramElement, final ObservationPointCreationTool tool, final EventEnd startingEndPredecessor, final EventEnd finishingEndPredecessor) { NodeCreationCommandBuilder builder = new ObservationPointCreationCommandBuilder( tool, diagramElement, startingEndPredecessor, finishingEndPredecessor); Session session = SessionManager.INSTANCE.getSession(diagramElement.getTarget()); return getCommand(builder, session); }
/** * Drop a semantic element and create the corresponding view in the given container * * @param newContainer Semantic container * @param semanticElement Element to drop * @param containerView Container view */ public void dropFromModel( final Element newContainer, final Element semanticElement, final DSemanticDecorator containerView) { final Session session = SessionManager.INSTANCE.getSession(semanticElement); markForAutosize(semanticElement); showView( semanticElement, containerView, session, "[self.getContainerView(newContainerView)/]"); //$NON-NLS-1$ }
/** * Builds the command which will execute the user-specified operations with a selection tool. * * @param tool the selection tool. * @param dContainer the clicked diagram element. * @param selectedElement the selected elements * @param endBefore the event end graphically preceding the position * @param location the clicked location. * @return a command to execute the tool. */ public static Command buildSequenceSelectionWizardCommandFromTool( SelectionWizardDescription tool, DSemanticDecorator dContainer, Collection<EObject> selectedElement, EventEnd endBefore, Point location) { CommandBuilder builder = new SequenceSelectionWizardCommandBuilder( tool, dContainer, selectedElement, endBefore, location); Session session = SessionManager.INSTANCE.getSession(dContainer.getTarget()); return getCommand(builder, session); }
/** * Check if a semantic element can be represented in a given container view. * * @param container Semantic container * @param semanticElement Element to test * @param containerView Container view * @return True if element is valid for the current container view */ public boolean isValidElementForContainerView( final Element container, final Element semanticElement, final DSemanticDecorator containerView) { final Session session = SessionManager.INSTANCE.getSession(container); // Get all available mappings applicable for the selected element in the // current container final List<DiagramElementMapping> semanticElementMappings = getMappings(semanticElement, containerView, session); return semanticElementMappings.size() > 0; }
public Collection<EObject> allRootsForBinding(EObject any) { Collection<EObject> roots = new ArrayList<EObject>(); Session session = SessionManager.INSTANCE.getSession(any); if (session != null) { for (Resource childRes : session.getSemanticResources()) { roots.addAll(childRes.getContents()); } } return roots; }
private void computeMappings(final DDiagram diagram, final Layer layer) { final DiagramMappingsManager manager = diagramMappingsManagers.get(diagram); if (manager != null) { boolean needToRecomputeDescMappings = false; if (layer != null && layer.eContainer() instanceof DiagramExtensionDescription) { needToRecomputeDescMappings = true; } Session sess = SessionManager.INSTANCE.getSession(((DSemanticDiagram) diagram).getTarget()); if (sess != null) { manager.computeMappings(sess.getSelectedViewpoints(false), needToRecomputeDescMappings); } else { manager.computeMappings(null, needToRecomputeDescMappings); } } }
/** * {@inheritDoc} * * @see org.eclipse.sirius.business.api.helper.task.ICommandTask#execute() */ public void execute() { if (semanticElement != null) { try { if (monitor == null) { monitor = new NullProgressMonitor(); } String name = askDiagramName(semanticElement); DialectManager.INSTANCE.createRepresentation( name, semanticElement, description, SessionManager.INSTANCE.getSession(semanticElement), monitor); } catch (final InterruptedException e) { // the user pressed "cancel", let's do nothing } } }
/** Construct a new {@link DiagramMappingsManagerRegistryImpl} instance. */ private DiagramMappingsManagerRegistryImpl() { diagramMappingsManagers = new HashMap<DDiagram, DiagramMappingsManager>(); SessionManager.INSTANCE.addSessionsListener( new SessionManagerListener.Stub() { @Override public void notifyRemoveSession(final Session removedSession) { // In normal condition this clean was already done during the // closing of the session (see the notify method above). cleanDiagramMappingsManagers(removedSession); } @Override public void notify(Session closingSession, int notification) { if (notification == SessionListener.CLOSING) { cleanDiagramMappingsManagers(closingSession); } } }); }
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; }
/** @not-generated */ @Override public void refresh() { removeDecoration(); View view = (View) getDecoratorTarget().getAdapter(View.class); Resource viewResource = null; if (view != null) { viewResource = view.eResource(); } if (viewResource == null) { return; } EditPart editPart = (EditPart) getDecoratorTarget().getAdapter(EditPart.class); if (editPart == null || editPart.getParent() == null || editPart.getViewer() == null) { return; } // query for all the validation markers of the current resource String elementId = SiriusGMFHelper.getViewId(view); if (elementId == null) { return; } // Directly retrieve the main Session resource // (session.getSessionResource()) as we know we put the marker on // it. Session currentSession = null; ResourceSet currentRs = viewResource.getResourceSet(); for (Session session : SessionManager.INSTANCE.getSessions()) { if (currentRs == session.getTransactionalEditingDomain().getResourceSet()) { currentSession = session; break; } } Resource markedResource = currentSession == null ? null : currentSession.getSessionResource(); IResource resource = WorkspaceSynchronizer.getFile(markedResource); if (resource == null || !resource.exists()) { return; } IMarker[] markers = null; try { markers = resource.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE); } catch (CoreException e) { DiagramPlugin.getDefault() .logError(Messages.StatusDecorator_validationMarkersFailureMsg, e); } if (markers == null || markers.length == 0) { return; } int severity = IMarker.SEVERITY_INFO; IMarker foundMarker = null; Label toolTip = null; for (int i = 0; i < markers.length; i++) { IMarker marker = markers[i]; String attribute = marker.getAttribute( org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); // $NON-NLS-1$ if (attribute.equals(elementId)) { int nextSeverity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); Image nextImage = getImage(nextSeverity); if (foundMarker == null) { foundMarker = marker; toolTip = new Label( marker.getAttribute(IMarker.MESSAGE, ""), // $NON-NLS-1$ nextImage); } else { if (toolTip.getChildren().isEmpty()) { Label comositeLabel = new Label(); FlowLayout fl = new FlowLayout(false); fl.setMinorSpacing(0); comositeLabel.setLayoutManager(fl); comositeLabel.add(toolTip); toolTip = comositeLabel; } toolTip.add( new Label( marker.getAttribute(IMarker.MESSAGE, ""), // $NON-NLS-1$ nextImage)); } severity = (nextSeverity > severity) ? nextSeverity : severity; } } if (foundMarker == null) { return; } // add decoration if (editPart instanceof org.eclipse.gef.GraphicalEditPart) { IDecoration decoration = null; if (view instanceof Diagram) { // There is not yet defined decorator for a diagram } else if (view instanceof Edge) { decoration = getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true); } else { int margin = -1; margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart) editPart).getFigure()) .DPtoLP(margin); decoration = getDecoratorTarget() .addShapeDecoration( getImage(severity), IDecoratorTarget.Direction.NORTH_EAST, margin, true); } if (decoration != null) { setDecoration(decoration); // getDecaration() returns a {@link Decoration} instead of a // {@link IDecoration} getDecoration().setToolTip(toolTip); } } }
/** * Drop a semantic element and create the corresponding view in the given container * * @param newContainer Semantic container * @param semanticElement Element to drop * @param containerView Container view * @param moveSemanticElement True to move the dropped semantic element or false to just show the * element on a diagram */ private void drop( final Element newContainer, final Element semanticElement, final DSemanticDecorator containerView, boolean moveSemanticElement) { final Session session = SessionManager.INSTANCE.getSession(newContainer); final Element oldContainer = semanticElement.getOwner(); if (moveSemanticElement && oldContainer != newContainer) { // Manage stereotypes and profiles final List<Stereotype> stereotypesToApply = Lists.newArrayList(); for (final Stereotype stereotype : semanticElement.getAppliedStereotypes()) { stereotypesToApply.add(stereotype); } // Move the semantic element to the selected container final TransactionalEditingDomain domain = session.getTransactionalEditingDomain(); // The feature is set to null because the domain will deduce it Command cmd = AddCommand.create(domain, newContainer, null, semanticElement); if (cmd.canExecute()) { cmd.execute(); } cmd = RemoveCommand.create(domain, oldContainer, null, semanticElement); if (cmd.canExecute()) { cmd.execute(); } if (semanticElement instanceof UseCase) { // Reset the current element as subject cmd = SetCommand.create( domain, semanticElement, UMLPackage.Literals.USE_CASE__SUBJECT, SetCommand.UNSET_VALUE); if (cmd.canExecute()) { cmd.execute(); } final List<Element> subjects = new ArrayList<Element>(); subjects.add(newContainer); cmd = SetCommand.create( domain, semanticElement, UMLPackage.Literals.USE_CASE__SUBJECT, subjects); if (cmd.canExecute()) { cmd.execute(); } } // Apply stereotypes on dropped element and apply the necessary // profiles automatically StereotypeServices.INSTANCE.applyAllStereotypes(semanticElement, stereotypesToApply); // Check if profile should be unapplied for (final Stereotype stereotype : stereotypesToApply) { StereotypeServices.INSTANCE.unapplyProfile(oldContainer, stereotype); } } // Show the semantic element on the diagram showView( semanticElement, containerView, session, "[self.getContainerView(newContainerView)/]"); //$NON-NLS-1$ }
@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); }