/** {@inheritDoc} */ @Override protected void initAction() { super.initAction(); visibleRepresentations = new ArrayList<CompartmentEditPartRepresentation>(); for (IGraphicalEditPart current : this.selectedElements) { if (((View) current.getModel()).getElement() != null) { this.representations.add( new RootEditPartRepresentation(current, ((View) current.getModel()).getElement())); } } setContentProvider(new ContentProvider()); // setEditorLabelProvider(new EditorLabelProvider()); // this.domain = ((IGraphicalEditPart)this.selectedElements.get(0)).getEditingDomain(); // this.initialSelection = getInitialSelection(); }
/** * Adds listeners on * * <ul> * <li>Affixed Child Node * <li>graphical parent, when its a {@link Property} (we add the listener on its Type) * </ul> */ public void activate() { IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); assert gep != null; View view = ((View) gep.getModel()); if (view instanceof Node) { // the location of the decorator can change if it's an Affixed Child // Node if (isInherited((Node) view) && Util.isAffixedChildNode(gep)) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener(gep.getNotationView(), notificationListener); } } // if the graphical parent is a Property, we add a listener on the type // of the property, to refresh the decoration EObject parent = view.eContainer(); if (parent instanceof DecorationNode) { parent = parent.eContainer(); } if (parent instanceof View) { EObject el = ((View) parent).getElement(); if (el instanceof Property) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener( el, UMLPackage.eINSTANCE.getTypedElement_Type(), notificationListener); } } /* * We listen the changes on the UML parent, in order to know if the * element is changing of parent Adding a listener using the following * EReference doesn't work UMLPackage.eINSTANCE.getElement_Owner(); * UMLPackage.eINSTANCE.getProperty_Class(); * UMLPackage.eINSTANCE.getNamedElement_Namespace(); that's why we * listen the parent */ if (view.getElement() instanceof Element) { Element semanticElement = (Element) view.getElement(); /* * We need add a listener only if the element is an element which * can be inherited, like Property, Operation, Signal, Classifier... */ if (semanticElement != null && canBeInherited(semanticElement)) { // we listen if the container of the element changes! if (semanticElement.eContainer() != null) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener(semanticElement.eContainer(), notificationListener); } } } }
/** * @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; }
/** Removes the listeners and the decorations */ public void deactivate() { removeDecoration(); IGraphicalEditPart gep = (IGraphicalEditPart) getDecoratorTarget().getAdapter(IGraphicalEditPart.class); assert gep != null; DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener(gep.getNotationView(), notificationListener); View view = ((View) gep.getModel()); if (view instanceof Node) { // the location of the decorator can change if it's an Affixed Child // Node if (isInherited((Node) view) && Util.isAffixedChildNode(gep)) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener(gep.getNotationView(), notificationListener); } } EObject parent = view.eContainer(); if (parent instanceof View) { EObject el = ((View) parent).getElement(); if (el instanceof Property) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .removeNotificationListener( el, UMLPackage.eINSTANCE.getTypedElement_Type(), notificationListener); } } if (view.getElement() instanceof Element) { Element semanticElement = (Element) view.getElement(); if (semanticElement != null) { if (semanticElement.eContainer() != null) { DiagramEventBroker.getInstance(gep.getEditingDomain()) .addNotificationListener(semanticElement.eContainer(), notificationListener); } } } }