Beispiel #1
0
 /**
  * If there are deps that are going from inside a FigComponent to inside a FigComponentInstance
  * the returned vector-set is not null. Then in the vector-set are the UMLDeploymentDiagram and
  * all FigDependencies with this characteristic and their FigObjects described over the supplier
  * and client.
  *
  * @param dd the diagram to check
  * @return the set of offenders
  */
 public ListSet computeOffenders(UMLDeploymentDiagram dd) {
   Collection figs = dd.getLayer().getContents();
   ListSet offs = null;
   for (Object obj : figs) {
     if (!(obj instanceof FigDependency)) {
       continue;
     }
     FigDependency figDependency = (FigDependency) obj;
     if (!(Model.getFacade().isADependency(figDependency.getOwner()))) {
       continue;
     }
     Object dependency = figDependency.getOwner();
     Collection suppliers = Model.getFacade().getSuppliers(dependency);
     int count = 0;
     if (suppliers != null) {
       for (Object moe : suppliers) {
         if (Model.getFacade().isAObject(moe)) {
           Object objSup = moe;
           if (Model.getFacade().getElementResidences(objSup) != null
               && (Model.getFacade().getElementResidences(objSup).size() > 0)) {
             count += 2;
           }
           if (Model.getFacade().getComponentInstance(objSup) != null) {
             count++;
           }
         }
       }
     }
     Collection clients = Model.getFacade().getClients(dependency);
     if (clients != null && (clients.size() > 0)) {
       for (Object moe : clients) {
         if (Model.getFacade().isAObject(moe)) {
           Object objCli = moe;
           if (Model.getFacade().getElementResidences(objCli) != null
               && (Model.getFacade().getElementResidences(objCli).size() > 0)) {
             count += 2;
           }
           if (Model.getFacade().getComponentInstance(objCli) != null) {
             count++;
           }
         }
       }
     }
     if (count == 3) {
       if (offs == null) {
         offs = new ListSet();
         offs.add(dd);
       }
       offs.add(figDependency);
       offs.add(figDependency.getSourcePortFig());
       offs.add(figDependency.getDestPortFig());
     }
   }
   return offs;
 }
  /** Return a Fig that can be used to represent the given edge */
  public FigEdge getFigEdgeFor(GraphModel gm, Layer lay, Object edge) {
    if (edge instanceof MDependency) {

      MDependency dep = (MDependency) edge;
      FigDependency depFig = new FigDependency(dep);

      MModelElement supplier = (MModelElement) ((dep.getSuppliers().toArray())[0]);
      MModelElement client = (MModelElement) ((dep.getClients().toArray())[0]);

      FigNode supFN = (FigNode) lay.presentationFor(supplier);
      FigNode cliFN = (FigNode) lay.presentationFor(client);

      depFig.setSourcePortFig(cliFN);
      depFig.setSourceFigNode(cliFN);
      depFig.setDestPortFig(supFN);
      depFig.setDestFigNode(supFN);
      depFig.getFig().setLayer(lay);
      depFig.getFig().setDashed(true);
      return depFig;
    }

    if (edge instanceof MAssociation) {
      MAssociation asc = (MAssociation) edge;
      FigAssociation ascFig = new FigAssociation(asc, lay);
      Collection connections = asc.getConnections();
      if (connections == null) System.out.println("null connections....");
      Object[] connArray = connections.toArray();
      MAssociationEnd fromEnd = (MAssociationEnd) connArray[0];
      MClassifier fromCls = (MClassifier) fromEnd.getType();
      MAssociationEnd toEnd = (MAssociationEnd) connArray[1];
      MClassifier toCls = (MClassifier) toEnd.getType();
      FigNode fromFN = (FigNode) lay.presentationFor(fromCls);
      FigNode toFN = (FigNode) lay.presentationFor(toCls);
      ascFig.setSourcePortFig(fromFN);
      ascFig.setSourceFigNode(fromFN);
      ascFig.setDestPortFig(toFN);
      ascFig.setDestFigNode(toFN);
      ascFig.getFig().setLayer(lay);
      return ascFig;
    }
    return null;
  }
  /**
   * Return a Fig that can be used to represent the given edge.
   *
   * <p>Generally the same code as for the ClassDiagram, since it's very related to it. Deal with
   * each of the edge types in turn.
   *
   * <p>
   *
   * @param gm The graph model for which we are rendering.
   * @param lay The layer in the graph on which we want this figure.
   * @param edge The edge to be rendered (an model element object)
   * @param styleAttributes an optional map of attributes to style the fig
   * @return The fig to be used, or <code>null</code> if we can't create one.
   * @see org.tigris.gef.graph.GraphEdgeRenderer#getFigEdgeFor( org.tigris.gef.graph.GraphModel,
   *     org.tigris.gef.base.Layer, java.lang.Object, java.util.Map)
   */
  public FigEdge getFigEdgeFor(GraphModel gm, Layer lay, Object edge, Map styleAttributes) {

    if (LOG.isDebugEnabled()) {
      LOG.debug("making figedge for " + edge);
    }

    if (edge == null) {
      throw new IllegalArgumentException("A model edge must be supplied");
    }

    FigEdgeModelElement newEdge = null;

    if (Model.getFacade().isAAssociation(edge)) {
      // If the edge is an association, we'll need a FigAssociation
      Object asc = /*(MAssociation)*/ edge;
      FigAssociation ascFig = new FigAssociation(asc, lay);

      newEdge = ascFig;
    } else if (Model.getFacade().isAGeneralization(edge)) {
      // Generalization needs a FigGeneralization
      Object gen = /*(MGeneralization)*/ edge;
      FigGeneralization genFig = new FigGeneralization(gen, lay);
      newEdge = genFig;
    } else if (Model.getFacade().isAExtend(edge)) {
      // Extend relationship
      Object ext = /*(MExtend)*/ edge;
      FigExtend extFig = new FigExtend(ext);

      // The nodes at the two ends

      Object base = Model.getFacade().getBase(ext);
      Object extension = Model.getFacade().getExtension(ext);

      // The figs for the two end nodes

      FigNode baseFN = (FigNode) lay.presentationFor(base);
      FigNode extensionFN = (FigNode) lay.presentationFor(extension);

      // Link the new extend relationship in to the ends. Remember we
      // draw from the extension use case to the base use case.

      extFig.setSourcePortFig(extensionFN);
      extFig.setSourceFigNode(extensionFN);

      extFig.setDestPortFig(baseFN);
      extFig.setDestFigNode(baseFN);

      newEdge = extFig;
    } else if (Model.getFacade().isAInclude(edge)) {
      // Include relationship is very like extend.
      Object inc = /*(MInclude)*/ edge;
      FigInclude incFig = new FigInclude(inc);

      Object base = Model.getFacade().getBase(inc);
      Object addition = Model.getFacade().getAddition(inc);

      // The figs for the two end nodes

      FigNode baseFN = (FigNode) lay.presentationFor(base);
      FigNode additionFN = (FigNode) lay.presentationFor(addition);

      // Link the new include relationship in to the ends

      incFig.setSourcePortFig(baseFN);
      incFig.setSourceFigNode(baseFN);

      incFig.setDestPortFig(additionFN);
      incFig.setDestFigNode(additionFN);

      newEdge = incFig;
    } else if (Model.getFacade().isADependency(edge)) {
      // Dependency needs a FigDependency
      Object dep = /*(MDependency)*/ edge;
      FigDependency depFig = new FigDependency(dep);

      // Where there is more than one supplier or client, take the first
      // element in each case. There really ought to be a check that
      // there are some here for safety.

      Object supplier = ((Model.getFacade().getSuppliers(dep).toArray())[0]);
      Object client = ((Model.getFacade().getClients(dep).toArray())[0]);

      // The figs for the two end nodes

      FigNode supplierFN = (FigNode) lay.presentationFor(supplier);
      FigNode clientFN = (FigNode) lay.presentationFor(client);

      // Link the new dependency in to the ends

      depFig.setSourcePortFig(clientFN);
      depFig.setSourceFigNode(clientFN);

      depFig.setDestPortFig(supplierFN);
      depFig.setDestFigNode(supplierFN);

      newEdge = depFig;
    } else if (edge instanceof CommentEdge) {
      newEdge = new FigEdgeNote(edge, lay);
    }

    if (newEdge == null) {
      throw new IllegalArgumentException(
          "Don't know how to create FigEdge for model type " + edge.getClass().getName());
    } else {
      setPorts(lay, newEdge);
    }

    lay.add(newEdge);
    newEdge.setDiElement(GraphChangeAdapter.getInstance().createElement(gm, edge));

    return newEdge;
  }