/**
  * Build a returnparameter. Removes all current return parameters from the operation and adds the
  * supplied parameter. The directionkind of the parameter will be return. The name will be equal
  * to the name of the last found return parameter or the default value "return" if no return
  * parameter was present in the operation.
  *
  * @param operation
  * @param newReturnParameter
  */
 public void setReturnParameter(MOperation operation, MParameter newReturnParameter) {
   Iterator params = operation.getParameters().iterator();
   String name = "return";
   while (params.hasNext()) {
     MParameter parameter = (MParameter) params.next();
     if ((parameter.getKind()).equals(MParameterDirectionKind.RETURN)) {
       operation.removeParameter(parameter);
       if (parameter.getName() != null || parameter.getName() == "") {
         name = parameter.getName();
       }
     }
   }
   newReturnParameter.setName(name);
   newReturnParameter.setKind(MParameterDirectionKind.RETURN);
   operation.addParameter(0, newReturnParameter);
   // we set the listeners to the figs here too
   // it would be better to do that in the figs themselves
   Project p = ProjectBrowser.TheInstance.getProject();
   Iterator it = p.findFigsForMember(operation).iterator();
   while (it.hasNext()) {
     MElementListener listener = (MElementListener) it.next();
     // UmlModelEventPump.getPump().removeModelEventListener(listener, newReturnParameter);
     UmlModelEventPump.getPump().addModelEventListener(listener, newReturnParameter);
   }
 }
Example #2
0
  /**
   * Sets the target of the style tab.
   *
   * @param t is the new target
   */
  public void setTarget(Object t) {
    if (target != null) {
      target.removePropertyChangeListener(this);
      if (target instanceof FigEdge) {
        // In this case, the bounds are determined by the FigEdge
        ((FigEdge) target).getFig().removePropertyChangeListener(this);
      }
      if (target instanceof FigAssociationClass) {
        // In this case, the bounds (of the box) are determined
        // by the FigClassAssociationClass
        FigClassAssociationClass ac = ((FigAssociationClass) target).getAssociationClass();
        // A newly created AssociationClass may not have all its parts
        // created by the time we are called
        if (ac != null) {
          ac.removePropertyChangeListener(this);
        }
      }
    }

    // TODO: Defer most of this work if the panel isn't visible - tfm

    // the responsibility of determining if the given target is a
    // correct one for this tab has been moved from the
    // DetailsPane to the member tabs of the details pane. Reason for
    // this is that the details pane is configurable and cannot
    // know what's the correct target for some tab.
    if (!(t instanceof Fig)) {
      if (Model.getFacade().isAModelElement(t)) {
        ArgoDiagram diagram = DiagramUtils.getActiveDiagram();
        if (diagram != null) {
          t = diagram.presentationFor(t);
        }
        if (!(t instanceof Fig)) {
          Project p = ProjectManager.getManager().getCurrentProject();
          Collection col = p.findFigsForMember(t);
          if (col == null || col.isEmpty()) {
            return;
          }
          t = col.iterator().next();
        }
        if (!(t instanceof Fig)) {
          return;
        }
      } else {
        return;
      }
    }

    target = (Fig) t;
    if (target != null) {
      target.addPropertyChangeListener(this);
      // TODO: This shouldn't know about the specific type of Fig that
      // is being displayed.  That couples it too strongly to things it
      // shouldn't need to know about - tfm - 20070924
      if (target instanceof FigEdge) {
        // In this case, the bounds are determined by the FigEdge
        ((FigEdge) target).getFig().addPropertyChangeListener(this);
      }
      if (target instanceof FigAssociationClass) {
        // In this case, the bounds (of the box) are determined
        // by the FigClassAssociationClass
        FigClassAssociationClass ac = ((FigAssociationClass) target).getAssociationClass();
        // A newly created AssociationClass may not have all its parts
        // created by the time we are called
        if (ac != null) {
          ac.addPropertyChangeListener(this);
        }
      }
    }
    if (lastPanel != null) {
      remove(lastPanel);
      if (lastPanel instanceof TargetListener) {
        removeTargetListener((TargetListener) lastPanel);
      }
    }
    if (t == null) {
      add(blankPanel, BorderLayout.NORTH);
      shouldBeEnabled = false;
      lastPanel = blankPanel;
      return;
    }
    shouldBeEnabled = true;
    stylePanel = null;
    Class targetClass = t.getClass();

    stylePanel = findPanelFor(targetClass);

    if (stylePanel != null) {
      removeTargetListener(stylePanel);
      addTargetListener(stylePanel);
      stylePanel.setTarget(target);
      add(stylePanel, BorderLayout.NORTH);
      shouldBeEnabled = true;
      lastPanel = stylePanel;
    } else {
      add(blankPanel, BorderLayout.NORTH);
      shouldBeEnabled = false;
      lastPanel = blankPanel;
    }
    validate();
    repaint();
  }