1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
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 | |
|
68 | |
|
69 | |
|
70 | 38 | public class DeploymentDiagramRenderer extends UmlDiagramRenderer { |
71 | |
|
72 | |
static final long serialVersionUID = 8002278834226522224L; |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | 19 | private static final Logger LOG = |
78 | |
Logger.getLogger(DeploymentDiagramRenderer.class); |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
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 | |
|
94 | |
|
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 | |
|
109 | |
|
110 | |
|
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 | |
} |