Coverage Report - org.argouml.uml.diagram.deployment.ui.DeploymentDiagramRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
DeploymentDiagramRenderer
2%
2/75
0%
0/22
6
 
 1  
 /* $Id: DeploymentDiagramRenderer.java 18729 2010-09-10 16:10:34Z bobtarling $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009-2010 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    Bob Tarling
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2003-2008 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.uml.diagram.deployment.ui;
 40  
 
 41  
 import java.util.Collection;
 42  
 import java.util.Map;
 43  
 
 44  
 import org.apache.log4j.Logger;
 45  
 import org.argouml.model.Model;
 46  
 import org.argouml.uml.CommentEdge;
 47  
 import org.argouml.uml.diagram.ArgoDiagram;
 48  
 import org.argouml.uml.diagram.DiagramEdgeSettings;
 49  
 import org.argouml.uml.diagram.DiagramSettings;
 50  
 import org.argouml.uml.diagram.UmlDiagramRenderer;
 51  
 import org.argouml.uml.diagram.static_structure.ui.FigEdgeNote;
 52  
 import org.argouml.uml.diagram.static_structure.ui.FigLink;
 53  
 import org.argouml.uml.diagram.ui.FigAssociation;
 54  
 import org.argouml.uml.diagram.ui.FigAssociationClass;
 55  
 import org.argouml.uml.diagram.ui.FigAssociationEnd;
 56  
 import org.argouml.uml.diagram.ui.FigDependency;
 57  
 import org.argouml.uml.diagram.ui.FigGeneralization;
 58  
 import org.argouml.uml.diagram.ui.UMLDiagram;
 59  
 import org.tigris.gef.base.Diagram;
 60  
 import org.tigris.gef.base.Layer;
 61  
 import org.tigris.gef.base.LayerPerspective;
 62  
 import org.tigris.gef.graph.GraphModel;
 63  
 import org.tigris.gef.presentation.FigEdge;
 64  
 import org.tigris.gef.presentation.FigNode;
 65  
 
 66  
 /**
 67  
  * This class defines a renderer object for UML Deployment Diagrams.
 68  
  *
 69  
  */
 70  38
 public class DeploymentDiagramRenderer extends UmlDiagramRenderer {
 71  
     
 72  
     static final long serialVersionUID = 8002278834226522224L;
 73  
 
 74  
     /**
 75  
      * Logger.
 76  
      */
 77  19
     private static final Logger LOG =
 78  
         Logger.getLogger(DeploymentDiagramRenderer.class);
 79  
 
 80  
     /*
 81  
      * @see org.tigris.gef.graph.GraphNodeRenderer#getFigNodeFor(
 82  
      *         org.tigris.gef.graph.GraphModel, org.tigris.gef.base.Layer,
 83  
      *         java.lang.Object, java.util.Map)
 84  
      */
 85  
     public FigNode getFigNodeFor(
 86  
             GraphModel gm,
 87  
             Layer lay,
 88  
             Object node,
 89  
             Map styleAttributes) {
 90  
 
 91  0
         FigNode figNode = null;
 92  
 
 93  
         // Although not generally true for GEF, for Argo we know that the layer
 94  
         // is a LayerPerspective which knows the associated diagram
 95  0
         Diagram diag = ((LayerPerspective) lay).getDiagram(); 
 96  0
         if (diag instanceof UMLDiagram
 97  
                 && ((UMLDiagram) diag).doesAccept(node)) {
 98  0
             figNode = (FigNode) ((UMLDiagram) diag).drop(node, null);
 99  
         } else {
 100  0
             LOG.debug("TODO: DeploymentDiagramRenderer getFigNodeFor");
 101  0
             return null;
 102  
         }
 103  0
         lay.add(figNode);
 104  0
         return figNode;
 105  
     }
 106  
 
 107  
     /*
 108  
      * @see org.tigris.gef.graph.GraphEdgeRenderer#getFigEdgeFor(
 109  
      *         org.tigris.gef.graph.GraphModel, org.tigris.gef.base.Layer,
 110  
      *         java.lang.Object, java.util.Map)
 111  
      */
 112  
     public FigEdge getFigEdgeFor(
 113  
             GraphModel gm,
 114  
             Layer lay,
 115  
             Object edge,
 116  
             Map styleAttributes) {
 117  
         
 118  0
         assert lay instanceof LayerPerspective;
 119  0
         ArgoDiagram diag = (ArgoDiagram) ((LayerPerspective) lay).getDiagram();
 120  0
         DiagramSettings settings = diag.getDiagramSettings();
 121  
         
 122  0
         FigEdge newEdge = null;
 123  0
         if (Model.getFacade().isAAssociationClass(edge)) {
 124  0
             Object[] associationEnds = 
 125  
                 Model.getFacade().getConnections(edge).toArray();
 126  0
             newEdge = new FigAssociationClass(
 127  
                     new DiagramEdgeSettings(
 128  
                             edge, 
 129  
                             associationEnds[0], 
 130  
                             associationEnds[1]), 
 131  
                             settings);
 132  0
             FigNode sourceFig =
 133  
                 getFigNodeForAssociationEnd(diag, associationEnds[0]);
 134  0
             FigNode destFig =
 135  
                 getFigNodeForAssociationEnd(diag, associationEnds[1]);
 136  0
             newEdge.setSourceFigNode(sourceFig);
 137  0
             newEdge.setSourcePortFig(sourceFig);
 138  0
             newEdge.setDestFigNode(destFig);
 139  0
             newEdge.setDestPortFig(destFig);
 140  0
         } else if (Model.getFacade().isAAssociation(edge)) {
 141  0
             Object[] associationEnds = 
 142  
                 Model.getFacade().getConnections(edge).toArray();
 143  0
             newEdge = new FigAssociation(
 144  
                     new DiagramEdgeSettings(
 145  
                         edge, 
 146  
                         associationEnds[0], 
 147  
                         associationEnds[1]), 
 148  
                         settings);
 149  0
             FigNode sourceFig =
 150  
                 getFigNodeForAssociationEnd(diag, associationEnds[0]);
 151  0
             FigNode destFig =
 152  
                 getFigNodeForAssociationEnd(diag, associationEnds[1]);
 153  0
             newEdge.setSourceFigNode(sourceFig);
 154  0
             newEdge.setSourcePortFig(sourceFig);
 155  0
             newEdge.setDestFigNode(destFig);
 156  0
             newEdge.setDestPortFig(destFig);
 157  0
         } else if (Model.getFacade().isAAssociationEnd(edge)) {
 158  0
             FigAssociationEnd asend = new FigAssociationEnd(edge, settings);
 159  0
             Model.getFacade().getAssociation(edge);
 160  0
             FigNode associationFN =
 161  
                     (FigNode) lay.presentationFor(Model
 162  
                             .getFacade().getAssociation(edge));
 163  0
             FigNode classifierFN =
 164  
                     (FigNode) lay.presentationFor(Model
 165  
                             .getFacade().getType(edge));
 166  
 
 167  0
             asend.setSourcePortFig(associationFN);
 168  0
             asend.setSourceFigNode(associationFN);
 169  0
             asend.setDestPortFig(classifierFN);
 170  0
             asend.setDestFigNode(classifierFN);
 171  0
             newEdge = asend;
 172  0
         } else if (Model.getFacade().isALink(edge)) {
 173  0
             FigLink lnkFig = new FigLink(edge, settings);
 174  0
             Collection linkEnds = Model.getFacade().getConnections(edge);
 175  0
             Object[] leArray = linkEnds.toArray();
 176  0
             Object fromEnd = leArray[0];
 177  0
             Object fromInst = Model.getFacade().getInstance(fromEnd);
 178  0
             Object toEnd = leArray[1];
 179  0
             Object toInst = Model.getFacade().getInstance(toEnd);
 180  0
             FigNode fromFN = (FigNode) lay.presentationFor(fromInst);
 181  0
             FigNode toFN = (FigNode) lay.presentationFor(toInst);
 182  0
             lnkFig.setSourcePortFig(fromFN);
 183  0
             lnkFig.setSourceFigNode(fromFN);
 184  0
             lnkFig.setDestPortFig(toFN);
 185  0
             lnkFig.setDestFigNode(toFN);
 186  0
             newEdge = lnkFig;
 187  0
         } else if (Model.getFacade().isADependency(edge)) {
 188  0
             FigDependency depFig = new FigDependency(edge, settings);
 189  
 
 190  0
             Object supplier =
 191  
                 ((Model.getFacade().getSuppliers(edge).toArray())[0]);
 192  0
             Object client =
 193  
                 ((Model.getFacade().getClients(edge).toArray())[0]);
 194  
 
 195  0
             FigNode supFN = (FigNode) lay.presentationFor(supplier);
 196  0
             FigNode cliFN = (FigNode) lay.presentationFor(client);
 197  
 
 198  0
             depFig.setSourcePortFig(cliFN);
 199  0
             depFig.setSourceFigNode(cliFN);
 200  0
             depFig.setDestPortFig(supFN);
 201  0
             depFig.setDestFigNode(supFN);
 202  0
             depFig.getFig().setDashed(true);
 203  0
             newEdge = depFig;
 204  0
         } else if (Model.getFacade().isAGeneralization(edge)) {
 205  0
             newEdge = new FigGeneralization(edge, settings);
 206  0
         } else if (edge instanceof CommentEdge) {
 207  0
             newEdge = new FigEdgeNote(edge, settings);
 208  
         }
 209  0
         addEdge(lay, newEdge, edge);
 210  0
         return newEdge;
 211  
     }
 212  
 }