示例#1
0
  /**
   * 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);
        }
      }
    }
  }
示例#2
0
  /** 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);
        }
      }
    }
  }