示例#1
0
  @Override
  public void notifyChanged(Notification notification) {
    EObject notifier = (EObject) notification.getNotifier();
    Object feature = notification.getFeature();

    Interaction interaction =
        EMFModelUtil.getRootContainerOfType(notifier, RamPackage.Literals.INTERACTION);

    // Notification could come from the interaction or an operand.
    if (notifier == specification || interaction == specification) {
      if (feature == RamPackage.Literals.FRAGMENT_CONTAINER__FRAGMENTS) {
        if (notification.getEventType() == Notification.ADD) {
          EObject newValue = (EObject) notification.getNewValue();

          RamSwitch<Object> switcher =
              new RamSwitch<Object>() {
                @Override
                public Object caseExecutionStatement(ExecutionStatement object) {
                  addStatementView(object);
                  return Boolean.TRUE;
                }

                @Override
                public Object caseCombinedFragment(CombinedFragment object) {
                  addCombinedFragment(object);
                  return Boolean.TRUE;
                }

                @Override
                public Object caseAssignmentStatement(AssignmentStatement object) {
                  addAssignmentStatement(object);
                  return Boolean.TRUE;
                };
              };

          switcher.doSwitch(newValue);
        } else if (notification.getEventType() == Notification.REMOVE) {
          EObject oldValue = (EObject) notification.getOldValue();

          RamSwitch<Object> switcher =
              new RamSwitch<Object>() {
                @Override
                public Object caseExecutionStatement(ExecutionStatement object) {
                  removeInteractionFragment(object);
                  return Boolean.TRUE;
                }

                @Override
                public Object caseCombinedFragment(CombinedFragment object) {
                  removeCombinedFragment(object);
                  return Boolean.TRUE;
                }

                @Override
                public Object caseAssignmentStatement(AssignmentStatement object) {
                  removeInteractionFragment(object);
                  return Boolean.TRUE;
                }
              };

          switcher.doSwitch(oldValue);
        }
      } else if (feature == RamPackage.Literals.INTERACTION__LIFELINES) {
        switch (notification.getEventType()) {
          case Notification.ADD:
            Lifeline lifeline = (Lifeline) notification.getNewValue();
            addLifelineView(lifeline);
            break;
          case Notification.REMOVE:
            lifeline = (Lifeline) notification.getOldValue();
            removeLifelineView(lifeline);
            break;
        }
      } else if (feature == RamPackage.Literals.INTERACTION__MESSAGES) {
        switch (notification.getEventType()) {
          case Notification.ADD:
            Message message = (Message) notification.getNewValue();
            addMessageView(message);
            break;
          case Notification.REMOVE:
            message = (Message) notification.getOldValue();
            removeMessageView(message);
            break;
        }
      }
    } else if (notifier == layout) {
      if (feature == RamPackage.Literals.CONTAINER_MAP__VALUE) {
        if (notification.getEventType() == Notification.ADD) {
          ElementMapImpl elementMap = (ElementMapImpl) notification.getNewValue();
          LifelineView lifelineView = lifelines.get(elementMap.getKey());
          lifelineView.setLayoutElement(elementMap.getValue());
        }
      }
    }
  }