/** @was-generated */ @Override public void activate() { if (viewId == null) { return; } // add self to global decorators registry List list = (List) allDecorators.get(viewId); if (list == null) { list = new ArrayList(2); list.add(this); allDecorators.put(viewId, list); } else if (!list.contains(this)) { list.add(this); } // start listening to changes in resources View view = (View) getDecoratorTarget().getAdapter(View.class); if (view == null) { return; } Diagram diagramView = view.getDiagram(); if (diagramView == null) { return; } if (fileObserver == null) { FileChangeManager.getInstance() .addFileObserver(fileObserver = new MarkerObserver(diagramView)); } }
/** * Get the snap back hint for the view. * * @param view the view to snap back. * @return the snap back hint. */ private String getSnapBackHint(View view) { String diagramType = view.getDiagram().getType(); String parentType = ViewUtil.getViewContainer(view).getType(); String labelType = view.getType(); return diagramType + "_" + parentType + "-" + labelType; }
/** @generated */ public final Map<EObject, View> getElement2ViewMap() { if (element2ViewMap == null) { element2ViewMap = new HashMap<EObject, View>(); // map possible notation elements to itself as these can't be found by view.getElement() for (EObject element : elementSet) { if (element instanceof View) { View view = (View) element; if (view.getDiagram() == scope.getDiagram()) { element2ViewMap.put(element, view); // take only those that part of our diagram } } } buildElement2ViewMap(scope, element2ViewMap, elementSet); } return element2ViewMap; }
/** * Creates an edge for a given eObject and with a given type and connects it between a given * source and a given target * * @param source The edge's source view * @param target The edge's target view * @param eObject The edge view object context * @param type The edge view type, check {@link ViewType} for predefined values * @param preferencesHint The preference hint that is to be used to find the appropriate * preference store from which to retrieve diagram preference values. The preference hint is * mapped to a preference store in the preference registry <@link DiagramPreferencesRegistry>. * @return A newly created <code>Edge</code> */ public static Edge createEdge( View source, View target, EObject eObject, String type, PreferencesHint preferencesHint) { assert source != null : "The source is null"; // $NON-NLS-1$ assert target != null : "The target is null"; // $NON-NLS-1$ assert source.getDiagram() != null : "The source is detached"; // $NON-NLS-1$ assert target.getDiagram() != null : "The target is detached"; // $NON-NLS-1$ IAdaptable viewModel = (eObject != null) ? new EObjectAdapter(eObject) : null; Edge edge = (Edge) ViewService.getInstance() .createEdge(viewModel, source.getDiagram(), type, ViewUtil.APPEND, preferencesHint); if (edge != null) { edge.setSource(source); edge.setTarget(target); } return edge; }
/** @generated */ public final Map getElement2ViewMap() { if (element2ViewMap == null) { element2ViewMap = new HashMap(); // map possible notation elements to itself as these can't be found by view.getElement() for (Iterator it = elementSet.iterator(); it.hasNext(); ) { EObject element = (EObject) it.next(); if (element instanceof View) { View view = (View) element; if (view.getDiagram() == scope.getDiagram()) { element2ViewMap.put(element, element); // take only those that part of our diagram } } } buildElement2ViewMap(scope, element2ViewMap, elementSet); } return element2ViewMap; }
/** * Updates the css state of the element associated with this edit policy * * @param state The css states to be added or removed from the current state * @param addedOrRemoved Indicates wheter states have to be added or removed (Possible values are * IMarkerEventListener.MARKER_ADDED and IMarkerEventListener.MARKER_REMOVED) */ public void updateState(Set<String> state, int addedOrRemoved) { MarkerEventListenerEditPolicy primaryEditPolicy = getPrimaryEditPolicy(); if (primaryEditPolicy == this) { View view = getSemanticView(); if (view.getDiagram() instanceof CSSDiagram) { Element domElement = ((CSSDiagram) view.getDiagram()).getEngine().getElement(view); if (domElement instanceof StatefulView) { if (addedOrRemoved == IMarkerEventListener.MARKER_ADDED) { ((StatefulView) domElement).addStates(state); } else { ((StatefulView) domElement).removeStates(state); } } } } else if (primaryEditPolicy != null) { primaryEditPolicy.updateState(state, addedOrRemoved); } }
/** @generated */ public static String getModelID(View view) { View diagram = view.getDiagram(); while (view != diagram) { EAnnotation annotation = view.getEAnnotation("Shortcut"); // $NON-NLS-1$ if (annotation != null) { return (String) annotation.getDetails().get("modelID"); // $NON-NLS-1$ } view = (View) view.eContainer(); } return diagram != null ? diagram.getType() : null; }
/** * Clean all shortcuts to the host element from the same diagram * * @generated */ protected void addDestroyShortcutsCommand(ICompositeCommand cmd, View view) { assert view.getEAnnotation("Shortcut") == null; // $NON-NLS-1$ for (Iterator it = view.getDiagram().getChildren().iterator(); it.hasNext(); ) { View nextView = (View) it.next(); if (nextView.getEAnnotation("Shortcut") == null || !nextView.isSetElement() || nextView.getElement() != view.getElement()) { // $NON-NLS-1$ continue; } cmd.add(new DeleteCommand(getEditingDomain(), nextView)); } }
@Override public synchronized boolean provides(IOperation operation) { if (operation instanceof CreateGraphicEditPartOperation) { View view = ((IEditPartOperation) operation).getView(); // Ensure current diagram is a Componentdef Diagram if (!ComponentdefDiagramEditPart.DIAGRAM_ID.equals(view.getDiagram().getType())) { return false; } // Test supported inherited types EObject eobject = view.getElement(); /** Nodes (and ChildLabelNodes) *********** */ if (eobject instanceof org.eclipse.uml2.uml.Class) { return true; } if (eobject instanceof org.eclipse.uml2.uml.Port) { return true; } if (eobject instanceof org.eclipse.uml2.uml.Comment) { return true; } if (eobject instanceof org.eclipse.uml2.uml.Constraint) { return true; } if (eobject instanceof org.eclipse.uml2.uml.Property) { return true; } if (eobject instanceof org.eclipse.uml2.uml.Package) { return true; } // Additional test needed here to decide whether to support Feature type links. // As feature type link are not related to a MetaClass from the domain model // they are not already handled by previous tests. String hint = view.getType(); /** Edges (Feature) : CONSTRAINT_CONSTRAINED_ELEMENT *********** */ if (ComponentdefDiagramElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT .getSemanticHint() .equals(hint)) { return true; } /** Edges (Feature) : COMMENT_ANNOTATED_ELEMENT *********** */ if (ComponentdefDiagramElementTypes.COMMENT_ANNOTATED_ELEMENT .getSemanticHint() .equals(hint)) { return true; } } return false; }
/** @generated */ protected Command createCommand() { TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(oldTarget.getDiagram().getElement()); CompoundCommand result = new CompoundCommand(); result.append(new ReconnectNotationalEdgeTargetCommand(edge, newTarget)); result.append( SetCommand.create( editingDomain, edge.getElement(), imagindata.imagindataPackage.eINSTANCE.getTransition_End(), newTarget.getElement())); return result; }
/** * @return the current diagram or null if not found. TODO : throw appropriate exception if not * found ? */ protected Diagram getCurrentDiagram() { IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); if (editorPart instanceof IMultiDiagramEditor) { editorPart = ((IMultiDiagramEditor) editorPart).getActiveEditor(); if (editorPart instanceof DiagramEditor) { host = ((DiagramEditor) editorPart).getDiagramEditPart(); View view = (View) host.getModel(); Diagram diagram = view.getDiagram(); return diagram; } } return null; }
/** @generated */ protected void addDestroyShortcutsCommand(CompoundCommand command) { View view = (View) getHost().getModel(); if (view.getEAnnotation("Shortcut") != null) { // $NON-NLS-1$ return; } for (Iterator it = view.getDiagram().getChildren().iterator(); it.hasNext(); ) { View nextView = (View) it.next(); if (nextView.getEAnnotation("Shortcut") == null || !nextView.isSetElement() || nextView.getElement() != view.getElement()) { // $NON-NLS-1$ continue; } command.add(getDestroyElementCommand(nextView)); } }
/** * initialize the status of the compartment for the node (Showed or hidden) * * @param view the element to initialize * @param store the preference store * @param elementName the name to the element */ public static void initCompartmentsStatusFromPrefs( View view, final IPreferenceStore store, String elementName) { EList<?> children = view.getPersistedChildren(); if (children != null) { for (Object object : children) { // we look for the name of the compartment for this view EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View) object); IGraphicalEditPart epp = (IGraphicalEditPart) dummyEP; IFigure fig1 = epp.getFigure(); if (fig1 instanceof ResizableCompartmentFigure) { String compartmentName = ((ResizableCompartmentFigure) fig1).getCompartmentTitle(); if (compartmentName != null) { String diagramKind = view.getDiagram().getType(); String preferenceKey = PreferenceConstantHelper.getCompartmentElementConstant( diagramKind + "_" + elementName, compartmentName, PreferenceConstantHelper.COMPARTMENT_VISIBILITY); // $NON-NLS-1$ boolean value = store.getBoolean(preferenceKey); if (!value) { // the default value is true : nothing to // do ENamedElement namedElement = PackageUtil.getElement("notation.View.visible"); // $NON-NLS-1$ ViewUtil.setStructuralFeatureValue( (View) object, (EStructuralFeature) namedElement, value); } String compartmentNameVisibilityPreference = PreferenceConstantHelper.getCompartmentElementConstant( diagramKind + "_" + elementName, compartmentName, PreferenceConstantHelper.COMPARTMENT_NAME_VISIBILITY); // $NON-NLS-1$ boolean showCompartmentName = store.getBoolean(compartmentNameVisibilityPreference); View childView = (View) object; TitleStyle style = (TitleStyle) childView.getStyle(NotationPackage.eINSTANCE.getTitleStyle()); if (style != null) { style.setShowTitle(showCompartmentName); } } } dummyEP = null; } } }
/** @generated */ public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) { if (aSelection == null || aSelection.isEmpty()) { return; } if (false == aSelection.getFirstElement() instanceof MIDAbstractNavigatorItem) { return; } MIDAbstractNavigatorItem abstractNavigatorItem = (MIDAbstractNavigatorItem) aSelection.getFirstElement(); View navigatorView = null; if (abstractNavigatorItem instanceof MIDNavigatorItem) { navigatorView = ((MIDNavigatorItem) abstractNavigatorItem).getView(); } else if (abstractNavigatorItem instanceof MIDNavigatorGroup) { MIDNavigatorGroup navigatorGroup = (MIDNavigatorGroup) abstractNavigatorItem; if (navigatorGroup.getParent() instanceof MIDNavigatorItem) { navigatorView = ((MIDNavigatorItem) navigatorGroup.getParent()).getView(); } else if (navigatorGroup.getParent() instanceof IAdaptable) { navigatorView = (View) ((IAdaptable) navigatorGroup.getParent()).getAdapter(View.class); } } if (navigatorView == null) { return; } IEditorInput editorInput = getEditorInput(navigatorView.getDiagram()); IEditorPart editor = aPage.findEditor(editorInput); if (editor == null) { return; } aPage.bringToTop(editor); if (editor instanceof DiagramEditor) { DiagramEditor diagramEditor = (DiagramEditor) editor; ResourceSet diagramEditorResourceSet = diagramEditor.getEditingDomain().getResourceSet(); EObject selectedView = diagramEditorResourceSet.getEObject(EcoreUtil.getURI(navigatorView), true); if (selectedView == null) { return; } GraphicalViewer graphicalViewer = (GraphicalViewer) diagramEditor.getAdapter(GraphicalViewer.class); EditPart selectedEditPart = (EditPart) graphicalViewer.getEditPartRegistry().get(selectedView); if (selectedEditPart != null) { graphicalViewer.select(selectedEditPart); } } }
/** @generated */ public View createView( IAdaptable semanticAdapter, View containerView, String semanticHint, int index, boolean persisted, PreferencesHint preferencesHint) { Node view = (Node) super.createView( semanticAdapter, containerView, semanticHint, index, persisted, preferencesHint); Location location = (Location) view.getLayoutConstraint(); IMapMode mapMode = MeasurementUnitHelper.getMapMode(containerView.getDiagram().getMeasurementUnit()); location.setX(mapMode.DPtoLP(0)); location.setY(mapMode.DPtoLP(5)); return view; }
/** @generated */ protected boolean prepare() { final boolean[] resultHolder = new boolean[1]; // To validate the reconnection against constraints, the current link should be deleted. Of // course, we must then undo its deletion. final TransactionalEditingDomain domainModelEditDomain = TransactionUtil.getEditingDomain(oldTarget.getDiagram().getElement()); Command command = new AbstractCommand() { private Command deleteCommand = createDomainModelRemoveCommand(domainModelEditDomain); public boolean canExecute() { return deleteCommand.canExecute(); } public boolean canUndo() { return true; } public void redo() {} public void undo() {} public void execute() { deleteCommand.execute(); try { resultHolder[0] = canReconnect(); } finally { deleteCommand.undo(); } } }; if (!command.canExecute()) { return false; } new WrappingCommand(domainModelEditDomain, command).execute(); if (!resultHolder[0]) { return false; } return super.prepare(); }
/** * initialize the status of each label for the node or for the link (Showed or hidden) * * @param view the element to initialize * @param store the preference store * @param elementName the name to the element */ public static void initLabelVisibilityFromPrefs( View view, final IPreferenceStore store, String elementName) { EList<?> children = view.getPersistedChildren(); if (children != null) { for (Object object : children) { // we look for the name of the label for this view EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View) object); if (dummyEP instanceof ILabelRoleProvider) { String role = ((ILabelRoleProvider) dummyEP).getLabelRole(); String diagramKind = view.getDiagram().getType(); String key = PreferenceConstantHelper.getLabelElementConstant( diagramKind + "_" + elementName, role, PreferenceConstantHelper.LABEL_VISIBILITY); // $NON-NLS-1$ ((View) object).setVisible(store.getBoolean(key)); } dummyEP = null; } } }
/** @was-generated */ public static void refreshDecorators(View view) { refreshDecorators(ViewUtil.getIdStr(view), view.getDiagram()); }
public Object execute(ExecutionEvent event) { ISelection selection; try { selection = ServiceUtilsForHandlers.getInstance() .getNestedActiveIEditorPart(event) .getSite() .getSelectionProvider() .getSelection(); if (selection.isEmpty()) { return null; } } catch (ServiceException ex) { Activator.log.error(ex); return null; } if (!(selection instanceof IStructuredSelection)) { return null; } IStructuredSelection sSelection = (IStructuredSelection) selection; Object element = sSelection.getFirstElement(); View view = NotationHelper.findView(element); if (view == null) { Activator.log.warn( "Cannot create a Style from the selected element ; the element is not a View"); return null; } Shell parentShell = ((Event) event.getTrigger()).widget.getDisplay().getActiveShell(); if (view.getElement() == null || view instanceof Diagram) { MessageDialog.open( MessageDialog.WARNING, parentShell, "Style error", "The selected element's style cannot be exported", SWT.NONE); return null; } Map<Declaration, Boolean> declarations = handleStyles(view); Map<Attribute, Boolean> conditions = handleSemantic(view); String selectorName = view.getElement().eClass().getName(); AbstractStyleDialog dialog = createStyleDialog(parentShell, declarations, conditions, selectorName, view); if (dialog.open() != Window.OK) { return null; } Ruleset ruleset = getRuleset(dialog); SimpleSelector selector = CssFactory.eINSTANCE.createSimpleSelector(); if (dialog.useSelectorName()) { selector.setElementName(selectorName); } else { selector.setElementName("*"); // $NON-NLS-1$ } if (dialog.getDiagramRestriction()) { String diagramType = getDiagramType(view.getDiagram()); CompositeSelector compositeSelector = CssFactory.eINSTANCE.createCompositeSelector(); compositeSelector.setRight(selector); SimpleSelector diagramSelector = CssFactory.eINSTANCE.createSimpleSelector(); diagramSelector.setElementName(diagramType); compositeSelector.setLeft(diagramSelector); ruleset.getSelectors().add(compositeSelector); } else { ruleset.getSelectors().add(selector); } if (dialog.getCSSClass() != null) { String cssClass = dialog.getCSSClass(); org.eclipse.papyrus.infra.gmfdiag.css.Class classCondition = CssFactory.eINSTANCE.createClass(); classCondition.setClass(cssClass); selector.getCondition().add(classCondition); } for (SelectorCondition condition : conditions.keySet()) { if (conditions.get(condition)) { selector.getCondition().add(condition); } } for (Declaration declaration : declarations.keySet()) { if (declarations.get(declaration)) { ruleset.getProperties().add(declaration); } } Stylesheet xtextStylesheet = getStyleSheet(dialog, view); if (xtextStylesheet == null) { return null; } Resource resource = xtextStylesheet.eResource(); if (!xtextStylesheet.getContents().contains(ruleset)) { xtextStylesheet.getContents().add(ruleset); } try { resource.save(new HashMap<Object, Object>()); BaseCSSEngine.INSTANCE.reset(); DiagramHelper.setNeedsRefresh(); DiagramHelper.refreshDiagrams(); } catch (IOException ex) { Activator.log.error(ex); MessageDialog.open( MessageDialog.ERROR, parentShell, "Style error", "An unexpected error occured while trying to save the Stylesheet", SWT.NONE); } catch (Exception ex) { Activator.log.error(ex); MessageDialog.open( MessageDialog.ERROR, parentShell, "Style error", "An unexpected error occured while trying to save the Stylesheet", SWT.NONE); } return null; }
public static String getpreferenceKey(View view, String elementName, int pref) { return PreferenceConstantHelper.getElementConstant( view.getDiagram().getType() + "_" + elementName, pref); // $NON-NLS-1$ }