Exemplo n.º 1
0
  private String getDescr(Fig f) {
    if (f == null) {
      return null;
    }
    String className = f.getClass().getName();
    StringBuffer descr = new StringBuffer(className.substring(className.lastIndexOf(".") + 1));
    //        descr.append(" - paints=").append(f.getPaintCount());
    //        descr.append(" - damages=").append(f.getDamageCount());
    descr.append(
        " - bounds=[" + f.getX() + "," + f.getY() + "," + f.getWidth() + "," + f.getHeight() + "]");
    if (!f.isVisible()) {
      descr.append(" - INVISIBLE");
    }
    if (f.isFilled()) {
      descr.append(" - FILLED");
    }
    descr.append(
        " - fill=["
            + f.getFillColor().getRed()
            + ","
            + f.getFillColor().getGreen()
            + ","
            + f.getFillColor().getBlue()
            + "]");
    if (f.getOwner() != null) {
      descr.append(" - owner=").append(f.getOwner());
    }
    if (f instanceof FigText) {
      descr.append(" \"").append(((FigText) f).getText()).append("\"");
    }

    descr.append(" - lay=").append(toString(f.getLayer()));
    descr.append(" - grp=").append(toString(f.getGroup()));
    return descr.toString();
  }
  /** @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */
  public void actionPerformed(ActionEvent ae) {
    super.actionPerformed(ae);
    try {
      /*Here the actions to delete a region.
      We assume the only figs enclosed in a concurrent composite state
      are concurrent region figs*/
      Fig f = (Fig) TargetManager.getInstance().getFigTarget();
      Fig encloser = null;

      int height = 0;
      Rectangle encBound;
      Project p = ProjectManager.getManager().getCurrentProject();

      if (Model.getFacade().isAConcurrentRegion(f.getOwner())) encloser = f.getEnclosingFig();

      Vector nodesInside;
      nodesInside = ((Vector) encloser.getEnclosedFigs().clone());
      int index = nodesInside.indexOf(f);
      Rectangle r = f.getBounds();
      encBound = encloser.getBounds();
      if (Model.getFacade().isAConcurrentRegion(f.getOwner())) p.moveToTrash(f.getOwner());
      // It wasnt the last region
      if (index < nodesInside.size() - 1) {
        Rectangle rFig = ((Fig) nodesInside.elementAt(index + 1)).getBounds();
        height = rFig.y - r.y;
        for (int i = ++index; i < nodesInside.size(); i++)
          ((FigNodeModelElement) nodesInside.elementAt(i)).displace(0, -height);
      }
      // It was the last region
      else height = r.height + 4;

      /*When only one concurrent region remains it must be erased and the
      composite state sets non concurent*/
      if (((Vector) encloser.getEnclosedFigs()).size() == 1) {
        f = ((Fig) encloser.getEnclosedFigs().elementAt(0));
        nodesInside = ((Vector) f.getEnclosedFigs());
        Model.getStateMachinesHelper().setConcurrent(encloser.getOwner(), false);
        if (!nodesInside.isEmpty()) {
          for (int i = 0; i < nodesInside.size(); i++) {
            FigStateVertex curFig = (FigStateVertex) nodesInside.elementAt(i);
            curFig.setEnclosingFig(encloser);
          }
        }
        p.moveToTrash(f.getOwner());
      }

    } catch (Exception ex) {
      LOG.error(ex);
    }
  }
Exemplo n.º 3
0
 /** @see org.tigris.gef.presentation.Fig#setEnclosingFig(org.tigris.gef.presentation.Fig) */
 public void setEnclosingFig(Fig encloser) {
   if (encloser == null
       || (encloser != null && !Model.getFacade().isAInstance(encloser.getOwner()))) {
     super.setEnclosingFig(encloser);
   }
   if (!(Model.getFacade().isAModelElement(getOwner()))) return;
   if (encloser != null && (Model.getFacade().isAComponent(encloser.getOwner()))) {
     Object component = /*(MComponent)*/ encloser.getOwner();
     Object in = /*(MInterface)*/ getOwner();
     Model.getCoreHelper().setContainer(resident, component);
     Model.getCoreHelper().setResident(resident, in);
   } else {
     Model.getCoreHelper().setContainer(resident, null);
     Model.getCoreHelper().setResident(resident, null);
   }
 }
Exemplo n.º 4
0
 public void setEnclosingFig(Fig encloser) {
   if (encloser == getEncloser()) {
     return;
   }
   if (encloser == null
       || (encloser != null && !Model.getFacade().isAInstance(encloser.getOwner()))) {
     super.setEnclosingFig(encloser);
   }
   if (!(Model.getFacade().isAUMLElement(getOwner()))) {
     return;
   }
   if (encloser != null && (Model.getFacade().isAComponent(encloser.getOwner()))) {
     moveIntoComponent(encloser);
     super.setEnclosingFig(encloser);
   }
 }
Exemplo n.º 5
0
 private void fixModel() {
   Fig sourceFig = getSourceFigNode();
   Fig destFig = getDestFigNode();
   Object source = sourceFig.getOwner();
   Object dest = destFig.getOwner();
   LOG.error(
       "Missing Generalization for figure in PGML -"
           + " attempting to recreate between "
           + source
           + " and "
           + dest);
   if (Model.getFacade().isAGeneralizableElement(source)
       && Model.getFacade().isAGeneralizableElement(dest)) {
     setOwner(Model.getCoreFactory().buildGeneralization(source, dest));
   }
 }
  /**
   * Updates the classifiers the edge is attached to.
   *
   * <p>Calls a helper method (layoutThisToSelf) to avoid this edge disappearing if the new source
   * and dest are the same node.
   *
   * @return boolean whether or not the update was sucessful
   */
  protected boolean updateClassifiers() {
    Object owner = getOwner();
    if (owner == null || getLayer() == null) {
      LOG.error("The FigEdge has no owner or its layer is null");
      return false;
    }

    Object newSource = getSource();
    Object newDest = getDestination();

    Fig currentSourceFig = getSourceFigNode();
    Fig currentDestFig = getDestFigNode();
    Object currentSource = null;
    Object currentDestination = null;
    if (currentSourceFig != null && currentDestFig != null) {
      currentSource = currentSourceFig.getOwner();
      currentDestination = currentDestFig.getOwner();
    }
    if (newSource != currentSource || newDest != currentDestination) {
      Fig newSourceFig = getNoEdgePresentationFor(newSource);
      Fig newDestFig = getNoEdgePresentationFor(newDest);
      if (newSourceFig != currentSourceFig) {
        setSourceFigNode((FigNode) newSourceFig);
        setSourcePortFig(newSourceFig);
      }
      if (newDestFig != currentDestFig) {
        setDestFigNode((FigNode) newDestFig);
        setDestPortFig(newDestFig);
      }
      ((FigNode) newSourceFig).updateEdges();
      ((FigNode) newDestFig).updateEdges();
      calcBounds();

      // adapted from SelectionWButtons from line 280
      // calls a helper method to avoid this edge disappearing
      // if the new source and dest are the same node.
      if (newSourceFig == newDestFig) {

        layoutThisToSelf();
      }
    }

    return true;
  }
  /**
   * If the selected Fig is a FigAssociation (an edge) then convert it to a FigNodeAssociation.
   *
   * @param fig the select end Fig
   * @return the fig converted to a FigNode
   */
  private FigNode convertToFigNode(Fig fig) {
    if (fig instanceof FigEdgePort) {
      fig = fig.getGroup();
    }
    if (!(fig instanceof FigAssociation)) {
      return (FigNode) fig;
    }
    final FigAssociation figAssociation = (FigAssociation) fig;
    final int x = figAssociation.getEdgePort().getX();
    final int y = figAssociation.getEdgePort().getY();
    final Object association = fig.getOwner();
    final FigNode originalEdgePort = figAssociation.getEdgePort();

    // Detach any edges (such as comment edges) already attached
    // to the FigAssociation before the FigAssociation is removed.
    // They'll later be re-attached to the new FigNodeAssociation
    final Collection<FigEdge> existingEdges = originalEdgePort.getEdges();
    for (FigEdge edge : existingEdges) {
      originalEdgePort.removeFigEdge(edge);
    }
    figAssociation.removeFromDiagram();

    // Create the new FigNodeAssociation and locate it.
    final MutableGraphModel gm = (MutableGraphModel) editor.getGraphModel();
    gm.addNode(association);
    final LayerPerspective lay = (LayerPerspective) editor.getLayerManager().getActiveLayer();
    final List associationFigs = lay.presentationsFor(association);
    associationFigs.remove(figAssociation);
    final FigNodeAssociation figNode = (FigNodeAssociation) associationFigs.get(0);

    figNode.setLocation(x - figNode.getWidth() / 2, y - figNode.getHeight() / 2);
    editor.add(figNode);
    editor.getSelectionManager().deselectAll();

    // Add the association ends to the graph model
    final Collection<Object> associationEnds = Model.getFacade().getConnections(association);
    for (Object associationEnd : associationEnds) {
      gm.addEdge(associationEnd);
    }
    // Add the edges (such as comment edges) that were on the old
    // FigAssociation to our new FigNodeAssociation and make sure they are
    // positioned correctly.
    for (FigEdge edge : existingEdges) {
      if (edge.getDestFigNode() == originalEdgePort) {
        edge.setDestFigNode(figNode);
        edge.setDestPortFig(figNode);
      }
      if (edge.getSourceFigNode() == originalEdgePort) {
        edge.setSourceFigNode(figNode);
        edge.setSourcePortFig(figNode);
      }
    }
    figNode.updateEdges();

    return figNode;
  }
  /**
   * Create an edge of the given type and connect it to the given nodes.
   *
   * @param graphModel the graph model in which to create the connection element
   * @param edgeType the UML object type of the connection
   * @param sourceFig the FigNode for the source element
   * @param destFig the FigNode for the destination element
   * @return The FigEdge representing the newly created model element
   */
  @Override
  protected FigEdge buildConnection(
      MutableGraphModel graphModel, Object edgeType, Fig sourceFig, Fig destFig) {
    try {
      Object associationEnd =
          Model.getUmlFactory()
              .buildConnection(
                  edgeType, sourceFig.getOwner(), null, destFig.getOwner(), null, null, null);

      final FigNode sourceFigNode = convertToFigNode(sourceFig);
      final FigNode destFigNode = convertToFigNode(destFig);

      graphModel.addEdge(associationEnd);

      setNewEdge(associationEnd);

      // Calling connect() will add the edge to the GraphModel and
      // any LayerPersectives on that GraphModel will get a
      // edgeAdded event and will add an appropriate FigEdge
      // (determined by the GraphEdgeRenderer).

      if (getNewEdge() != null) {
        sourceFigNode.damage();
        destFigNode.damage();
        Layer lay = editor.getLayerManager().getActiveLayer();
        FigEdge fe = (FigEdge) lay.presentationFor(getNewEdge());
        _newItem.setLineColor(Color.black);
        fe.setFig(_newItem);
        fe.setSourcePortFig(sourceFigNode);
        fe.setSourceFigNode(sourceFigNode);
        fe.setDestPortFig(destFigNode);
        fe.setDestFigNode(destFigNode);
        return fe;
      } else {
        return null;
      }
    } catch (IllegalModelElementConnectionException e) {
      // We have already confirmed the connection is valid
      return null;
    }
  }
Exemplo n.º 9
0
  /**
   * Add a classier to the current diagram.
   *
   * @param classifier The new class or interface to add to the editor.
   * @param minimise minimise the class fig by hiding compartments (of attributes and operations)
   */
  private void addClassifier(Object classifier, boolean minimise) {

    String name = Model.getFacade().getName(classifier);

    // if the classifier is not in the current diagram, add it:
    if (currentGM.canAddNode(classifier)) {
      FigClassifierBox newFig;
      if (Model.getFacade().isAClass(classifier)) {
        newFig = new FigClass(currentGM, classifier);
      } else if (Model.getFacade().isAInterface(classifier)) {
        newFig = new FigInterface(currentGM, classifier);
      } else {
        return;
      }

      /*
       * The following calls are ORDER DEPENDENT. Not sure why, but the
       * layer add must come before the model add or we'll end up with
       * duplicate figures in the diagram. - tfm
       */
      currentLayer.add(newFig);
      currentGM.addNode(classifier);
      currentLayer.putInPosition(newFig);

      newFig.setOperationsVisible(!minimise);
      if (Model.getFacade().isAClass(classifier)) {
        ((FigClass) newFig).setAttributesVisible(!minimise);
      }

      newFig.setSize(newFig.getMinimumSize());
    } else {
      // the class is in the diagram
      // so we are on a second pass,
      // find the fig for this class can update its visible state.
      FigClassifierBox existingFig = null;
      List figs = currentLayer.getContentsNoEdges();
      for (int i = 0; i < figs.size(); i++) {
        Fig fig = (Fig) figs.get(i);
        if (classifier == fig.getOwner()) {
          existingFig = (FigClassifierBox) fig;
        }
      }
      existingFig.renderingChanged();
    }

    // add edges
    // for a 2-pass r.e. process we might have already added the
    // class but not its edges
    currentGM.addNodeRelatedEdges(classifier);
  }
Exemplo n.º 10
0
 @Override
 public Object getOwner() {
   if (super.getOwner() != null) {
     return super.getOwner();
   }
   Fig group = this;
   while (group != null && !(group instanceof FigEdge)) {
     group = group.getGroup();
   }
   if (group == null) {
     return null;
   } else {
     return group.getOwner();
   }
 }
Exemplo n.º 11
0
 /**
  * A version of GEF's presentationFor() method which
  *
  * @param element ModelElement to return presentation for
  * @return the Fig representing the presentation
  */
 private Fig getNoEdgePresentationFor(Object element) {
   if (element == null) {
     throw new IllegalArgumentException("Can't search for a null owner");
   }
   List contents = getLayer().getContentsNoEdges();
   int figCount = contents.size();
   for (int figIndex = 0; figIndex < figCount; ++figIndex) {
     Fig fig = (Fig) contents.get(figIndex);
     if (fig.getOwner() == element) {
       return fig;
     }
   }
   throw new IllegalStateException(
       "Can't find a FigNode representing " + Model.getFacade().getName(element));
 }
Exemplo n.º 12
0
 /**
  * If there are interfaces that are not inside a component the returned ListSet is not null. Then
  * in the ListSet are the UMLDeploymentDiagram and all FigInterfaces with no enclosing
  * FigComponent
  *
  * @param dd the diagram to check
  * @return the set of offenders
  */
 public ListSet computeOffenders(UMLDeploymentDiagram dd) {
   Collection figs = dd.getLayer().getContents();
   ListSet offs = null;
   Iterator figIter = figs.iterator();
   while (figIter.hasNext()) {
     Object obj = figIter.next();
     if (!(obj instanceof FigInterface)) continue;
     FigInterface fi = (FigInterface) obj;
     Fig enclosing = fi.getEnclosingFig();
     if (enclosing == null || (!(Model.getFacade().isAComponent(enclosing.getOwner())))) {
       if (offs == null) {
         offs = new ListSet();
         offs.add(dd);
       }
       offs.add(fi);
     }
   }
   return offs;
 }
  public void setEnclosingFig(Fig encloser) {

    if (encloser != null && encloser.getOwner() instanceof MNodeInstance && getOwner() != null) {
      MNodeInstance node = (MNodeInstance) encloser.getOwner();
      MComponentInstance comp = (MComponentInstance) getOwner();
      if (comp.getNodeInstance() != node) {
        comp.setNodeInstance(node);
      }
      super.setEnclosingFig(encloser);

      Vector figures = getEnclosedFigs();

      if (getLayer() != null) {
        // elementOrdering(figures);
        Vector contents = getLayer().getContents();
        int contentsSize = contents.size();
        for (int j = 0; j < contentsSize; j++) {
          Object o = contents.elementAt(j);
          if (o instanceof FigEdgeModelElement) {
            FigEdgeModelElement figedge = (FigEdgeModelElement) o;
            figedge.getLayer().bringToFront(figedge);
          }
        }
      }
    } else if (encloser == null && getEnclosingFig() != null) {
      if (getEnclosingFig() instanceof FigNodeModelElement)
        ((FigNodeModelElement) getEnclosingFig()).getEnclosedFigs().removeElement(this);
      _encloser = null;
    }
    /*
    super.setEnclosingFig(encloser);

    Vector figures = getEnclosedFigs();

    if (getLayer() != null) {
      // elementOrdering(figures);
      Vector contents = getLayer().getContents();
      int contentsSize = contents.size();
      for (int j=0; j<contentsSize; j++) {
        Object o = contents.elementAt(j);
        if (o instanceof FigEdgeModelElement) {
          FigEdgeModelElement figedge = (FigEdgeModelElement) o;
          figedge.getLayer().bringToFront(figedge);
        }
      }
    }

    if (!(getOwner() instanceof MModelElement)) return;
    if (getOwner() instanceof MComponentInstance) {
      MComponentInstance me = (MComponentInstance) getOwner();
      MNodeInstance mnode = null;

      if (encloser != null && (encloser.getOwner() instanceof MNodeInstance)) {
        mnode = (MNodeInstance) encloser.getOwner();
      }
      if (encloser != null && (encloser.getOwner() instanceof MComponentInstance)) {
        MComponentInstance comp = (MComponentInstance) encloser.getOwner();
        mnode = (MNodeInstance) comp.getNodeInstance();
      }
      try {
        if(mnode != null) {
          me.setNodeInstance(mnode);
        }
        else {
          if (me.getNodeInstance() != null) {
            me.setNodeInstance(null);
          }
        }
        setNode(figures);
      }
      catch (Exception e) {
        cat.error("could not set package", e);

      }
    }
    */
  }