Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
CollabDiagramRenderer |
|
| 6.0;6 |
1 | /* $Id: CollabDiagramRenderer.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) 1996-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.collaboration.ui; | |
40 | ||
41 | import java.util.Map; | |
42 | ||
43 | import org.apache.log4j.Logger; | |
44 | import org.argouml.model.Model; | |
45 | import org.argouml.uml.CommentEdge; | |
46 | import org.argouml.uml.diagram.ArgoDiagram; | |
47 | import org.argouml.uml.diagram.DiagramEdgeSettings; | |
48 | import org.argouml.uml.diagram.DiagramSettings; | |
49 | import org.argouml.uml.diagram.UmlDiagramRenderer; | |
50 | import org.argouml.uml.diagram.static_structure.ui.FigEdgeNote; | |
51 | import org.argouml.uml.diagram.ui.FigDependency; | |
52 | import org.argouml.uml.diagram.ui.FigGeneralization; | |
53 | import org.argouml.uml.diagram.ui.UMLDiagram; | |
54 | import org.tigris.gef.base.Diagram; | |
55 | import org.tigris.gef.base.Layer; | |
56 | import org.tigris.gef.base.LayerPerspective; | |
57 | import org.tigris.gef.graph.GraphModel; | |
58 | import org.tigris.gef.presentation.FigEdge; | |
59 | import org.tigris.gef.presentation.FigNode; | |
60 | ||
61 | /** | |
62 | * This class defines a renderer object for UML Collaboration Diagrams. | |
63 | * In a collaboration Diagram the following UML objects are displayed with the | |
64 | * following Figs:<p> | |
65 | * | |
66 | * <pre> | |
67 | * UML Object --- Fig | |
68 | * --------------------------------------- | |
69 | * MClassifierRole --- FigClassifierRole | |
70 | * MMessage --- FigMessage | |
71 | * MComment --- FigComment | |
72 | * </pre> | |
73 | * | |
74 | * Provides {@link #getFigNodeFor} to implement the | |
75 | * {@link org.tigris.gef.graph.GraphNodeRenderer} interface and | |
76 | * {@link #getFigEdgeFor} to implement the | |
77 | * {@link org.tigris.gef.graph.GraphEdgeRenderer} interface.<p> | |
78 | * | |
79 | * <em>Note</em>. Should be implemented as a singleton - we don't really | |
80 | * need a separate instance for each use case diagram.<p> | |
81 | * | |
82 | * | |
83 | * @author agauthie | |
84 | */ | |
85 | 38 | public class CollabDiagramRenderer extends UmlDiagramRenderer { |
86 | /** | |
87 | * Logger. | |
88 | */ | |
89 | 19 | private static final Logger LOG = |
90 | Logger.getLogger(CollabDiagramRenderer.class); | |
91 | ||
92 | /* | |
93 | * @see org.tigris.gef.graph.GraphNodeRenderer#getFigNodeFor( | |
94 | * org.tigris.gef.graph.GraphModel, org.tigris.gef.base.Layer, | |
95 | * java.lang.Object, java.util.Map) | |
96 | */ | |
97 | public FigNode getFigNodeFor(GraphModel gm, Layer lay, | |
98 | Object node, Map styleAttributes) { | |
99 | ||
100 | 0 | FigNode figNode = null; |
101 | ||
102 | 0 | assert node != null; |
103 | ||
104 | // Although not generally true for GEF, for Argo we know that the layer | |
105 | // is a LayerPerspective which knows the associated diagram | |
106 | 0 | Diagram diag = ((LayerPerspective) lay).getDiagram(); |
107 | 0 | if (diag instanceof UMLDiagram |
108 | && ((UMLDiagram) diag).doesAccept(node)) { | |
109 | 0 | figNode = (FigNode) ((UMLDiagram) diag).drop(node, null); |
110 | } else { | |
111 | 0 | LOG.error("TODO: CollabDiagramRenderer getFigNodeFor"); |
112 | 0 | throw new IllegalArgumentException( |
113 | "Node is not a recognised type. Received " | |
114 | + node.getClass().getName()); | |
115 | } | |
116 | ||
117 | 0 | lay.add(figNode); |
118 | 0 | return figNode; |
119 | } | |
120 | ||
121 | /** | |
122 | * Return a Fig that can be used to represent the given edge, | |
123 | * Generally the same code as for the ClassDiagram, since its | |
124 | * very related to it. | |
125 | * | |
126 | * {@inheritDoc} | |
127 | */ | |
128 | public FigEdge getFigEdgeFor(GraphModel gm, Layer lay, | |
129 | Object edge, Map styleAttributes) { | |
130 | 0 | if (LOG.isDebugEnabled()) { |
131 | 0 | LOG.debug("making figedge for " + edge); |
132 | } | |
133 | 0 | if (edge == null) { |
134 | 0 | throw new IllegalArgumentException("A model edge must be supplied"); |
135 | } | |
136 | ||
137 | 0 | assert lay instanceof LayerPerspective; |
138 | 0 | ArgoDiagram diag = (ArgoDiagram) ((LayerPerspective) lay).getDiagram(); |
139 | 0 | DiagramSettings settings = diag.getDiagramSettings(); |
140 | ||
141 | 0 | FigEdge newEdge = null; |
142 | 0 | if (Model.getFacade().isAAssociationRole(edge)) { |
143 | 0 | Object[] associationEnds = |
144 | Model.getFacade().getConnections(edge).toArray(); | |
145 | 0 | newEdge = new FigAssociationRole( |
146 | new DiagramEdgeSettings( | |
147 | edge, | |
148 | associationEnds[0], | |
149 | associationEnds[1]), | |
150 | settings); | |
151 | 0 | FigNode sourceFig = |
152 | getFigNodeForAssociationEnd(diag, associationEnds[0]); | |
153 | 0 | FigNode destFig = |
154 | getFigNodeForAssociationEnd(diag, associationEnds[1]); | |
155 | 0 | newEdge.setSourceFigNode(sourceFig); |
156 | 0 | newEdge.setSourcePortFig(sourceFig); |
157 | 0 | newEdge.setDestFigNode(destFig); |
158 | 0 | newEdge.setDestPortFig(destFig); |
159 | 0 | } else if (Model.getFacade().isAGeneralization(edge)) { |
160 | 0 | newEdge = new FigGeneralization(edge, settings); |
161 | 0 | } else if (Model.getFacade().isADependency(edge)) { |
162 | 0 | newEdge = new FigDependency(edge , settings); |
163 | 0 | } else if (edge instanceof CommentEdge) { |
164 | 0 | newEdge = new FigEdgeNote(edge, settings); // TODO -> settings |
165 | } | |
166 | ||
167 | 0 | addEdge(lay, newEdge, edge); |
168 | 0 | return newEdge; |
169 | } | |
170 | } |