Ejemplo n.º 1
0
  /**
   * Adds the given execution statement to the lifeline view it covers.
   *
   * @param executionStatement the {@link ExecutionStatement} to add
   */
  private void addStatementView(ExecutionStatement executionStatement) {
    Lifeline lifeline = executionStatement.getCovered().get(0);
    LifelineView lifelineView = lifelines.get(lifeline);
    int modelIndex = getModelIndex(executionStatement);

    // Currently we assume that the statements specification is always an opaque expression.
    // If this changes we need to adaptively get the actual value.
    TextView textView =
        new TextView(executionStatement, RamPackage.Literals.EXECUTION_STATEMENT__SPECIFICATION);
    textView.setNoFill(false);
    textView.setNoStroke(false);
    textView.setFillColor(Colors.MESSAGE_STATEMENT_FILL_COLOR);

    ITextViewHandler textViewHandler =
        HandlerFactoryMessageView.INSTANCE.getExecutionStatementHandler();

    textView.registerTapProcessor(textViewHandler);
    textView.registerInputProcessor(
        new TapAndHoldProcessor(RamApp.getApplication(), Constants.TAP_AND_HOLD_DURATION));
    textView.addGestureListener(TapAndHoldProcessor.class, textViewHandler);
    textView.addGestureListener(
        TapAndHoldProcessor.class,
        new TapAndHoldVisualizer(RamApp.getApplication(), RamApp.getActiveScene().getCanvas()));
    textView.setPlaceholderText(Strings.PH_SPECIFY_STATEMENT);
    addChild(textView);

    lifelineView.addStatement(textView, executionStatement, modelIndex);
    fragments.put(executionStatement, textView);

    layoutMessageView();
  }
Ejemplo n.º 2
0
  /**
   * Adds a new view for the given lifeline to this view.
   *
   * @param lifeline the {@link Lifeline} a view is required for
   */
  private void addLifelineView(Lifeline lifeline) {
    LayoutElement layoutElement = layout.getValue().get(lifeline);

    LifelineView lifelineView = new LifelineView(this, lifeline, layoutElement);
    addChild(lifelineView);
    lifelineView.setHandler(HandlerFactoryMessageView.INSTANCE.getLifelineViewHandler());

    lifelines.put(lifeline, lifelineView);
  }
Ejemplo n.º 3
0
  /**
   * Creates a view for the given assignment statement and adds it to the lifeline view it covers.
   *
   * @param assignmentStatement the {@link AssignmentStatement} to add
   */
  private void addAssignmentStatement(AssignmentStatement assignmentStatement) {
    Lifeline lifeline = assignmentStatement.getCovered().get(0);
    LifelineView lifelineView = lifelines.get(lifeline);
    int modelIndex = getModelIndex(assignmentStatement);

    AssignmentStatementView assignmentView = new AssignmentStatementView(assignmentStatement);
    addChild(assignmentView);
    assignmentView.setHandler(HandlerFactoryMessageView.INSTANCE.getAssignmentStatementHandler());

    lifelineView.addAssignment(assignmentView, assignmentStatement, modelIndex);
    fragments.put(assignmentStatement, assignmentView);

    layoutMessageView();
  }
Ejemplo n.º 4
0
  /**
   * Adds a new view for the given message to this view. A message is represented by a view on each
   * end and a view representing the actual call. The end views are added to the corresponding
   * lifelines. In case an end is a gate and not placed on a lifeline, a {@link GateView} is used
   * instead and added to this view at the left side.
   *
   * @param message the {@link Message} to add
   */
  private void addMessageView(Message message) {
    LifelineView toView = null;
    LifelineView fromView = null;
    RamRectangleComponent sendEventView = null;
    RamRectangleComponent receiveEventView = null;
    MessageEnd sendEvent = message.getSendEvent();
    MessageEnd receiveEvent = message.getReceiveEvent();

    Operation signature = message.getSignature();
    boolean messageViewDefined = false;

    if (signature != null && specifies != signature) {
      Aspect aspect = EMFModelUtil.getRootContainerOfType(signature, RamPackage.Literals.ASPECT);
      /**
       * Make sure that the signature still exists in the aspect. It could have been deleted and
       * would then cause problems here.
       */
      if (aspect != null) {
        messageViewDefined = RAMModelUtil.isMessageViewDefined(aspect, signature);
      }
    }

    if (sendEvent instanceof MessageOccurrenceSpecification) {
      MessageOccurrenceSpecification event = (MessageOccurrenceSpecification) sendEvent;

      fromView = lifelines.get(event.getCovered().get(0));
      int modelIndex = event.getContainer().getFragments().indexOf(sendEvent);

      if (fromView != null) {
        boolean allowMessageCreation = false;
        // Allow creation after sending a message where no return is expected.
        if (signature != null && signature.getReturnType() != null) {
          Type returnType = signature.getReturnType();
          allowMessageCreation =
              message.getMessageSort() != MessageSort.REPLY
                  && !message.isSelfMessage()
                  && (returnType.eClass() == RamPackage.Literals.RVOID
                      || message.getMessageSort() == MessageSort.CREATE_MESSAGE
                      || signature.eContainer() instanceof ImplementationClass
                      // When a message view is defined, there will be no reply, so we need to allow
                      // it.
                      || messageViewDefined);
        }

        sendEventView = fromView.addMessageEnd(event, modelIndex, allowMessageCreation);
      }
    }

    if (receiveEvent instanceof MessageOccurrenceSpecification) {
      MessageOccurrenceSpecification event = (MessageOccurrenceSpecification) receiveEvent;

      toView = lifelines.get(event.getCovered().get(0));
      int modelIndex = event.getContainer().getFragments().indexOf(receiveEvent);

      if (toView != null) {
        if (message.getMessageSort() == MessageSort.CREATE_MESSAGE) {
          receiveEventView = toView;
        } else {
          boolean allowMessageCreation = message.getMessageSort() != MessageSort.DELETE_MESSAGE;
          if (signature != null) {
            // Don't allow message creation if the receiving end is on an implementation class.
            // If it is a self message it cannot be on an implementation class and is allowed.
            allowMessageCreation =
                allowMessageCreation
                    && !(signature.eContainer() instanceof ImplementationClass)
                    && (!messageViewDefined || message.isSelfMessage());
          }

          receiveEventView = toView.addMessageEnd(event, modelIndex, allowMessageCreation);
        }
      }
    }

    if (sendEventView == null) {
      Vector3D oppositePosition = receiveEventView.getPosition(TransformSpace.GLOBAL);
      sendEventView = new GateView(0, oppositePosition.getY(), BOX_WIDTH, BOX_HEIGHT);
      addChild(sendEventView);
    } else if (receiveEventView == null) {
      Vector3D oppositePosition = sendEventView.getPosition(TransformSpace.GLOBAL);
      receiveEventView = new GateView(0, oppositePosition.getY(), BOX_WIDTH, BOX_HEIGHT);
      addChild(receiveEventView);
    }

    MessageCallView messageCallView = new MessageCallView(message, sendEventView, receiveEventView);
    addChild(messageCallView);
    messageCallView.setHandler(HandlerFactoryMessageView.INSTANCE.getMessageHandler());
    messages.put(message, messageCallView);

    layoutMessageView();

    messageCallView.updateLines();
  }