1 | /* |
2 | * Copyright 2007, SDQ, IPD, Uni Karlsruhe (TH) |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.composite.edit.parts; |
5 | |
6 | import org.eclipse.draw2d.FigureUtilities; |
7 | import org.eclipse.draw2d.Label; |
8 | import org.eclipse.draw2d.geometry.Dimension; |
9 | import org.eclipse.draw2d.geometry.Rectangle; |
10 | import org.eclipse.gef.EditPart; |
11 | import org.eclipse.gef.EditPartFactory; |
12 | import org.eclipse.gef.tools.CellEditorLocator; |
13 | import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart; |
14 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel; |
15 | import org.eclipse.gmf.runtime.notation.View; |
16 | import org.eclipse.jface.viewers.CellEditor; |
17 | import org.eclipse.swt.SWT; |
18 | import org.eclipse.swt.widgets.Text; |
19 | |
20 | import de.uka.ipd.sdq.pcm.gmf.composite.part.PalladioComponentModelVisualIDRegistry; |
21 | |
22 | /** |
23 | * @generated |
24 | */ |
25 | public class PalladioComponentModelEditPartFactory implements EditPartFactory { |
26 | |
27 | /** |
28 | * @generated |
29 | */ |
30 | public EditPart createEditPart(EditPart context, Object model) { |
31 | if (model instanceof View) { |
32 | View view = (View) model; |
33 | switch (PalladioComponentModelVisualIDRegistry.getVisualID(view)) { |
34 | |
35 | case ComposedProvidingRequiringEntityEditPart.VISUAL_ID: |
36 | return new ComposedProvidingRequiringEntityEditPart(view); |
37 | |
38 | case ComposedProvidingRequiringEntity2EditPart.VISUAL_ID: |
39 | return new ComposedProvidingRequiringEntity2EditPart(view); |
40 | |
41 | case ComposedProvidingRequiringEntityEntityNameEditPart.VISUAL_ID: |
42 | return new ComposedProvidingRequiringEntityEntityNameEditPart( |
43 | view); |
44 | |
45 | case AssemblyContextEditPart.VISUAL_ID: |
46 | return new AssemblyContextEditPart(view); |
47 | |
48 | case AssemblyContextEntityNameEditPart.VISUAL_ID: |
49 | return new AssemblyContextEntityNameEditPart(view); |
50 | |
51 | case OperationProvidedRoleEditPart.VISUAL_ID: |
52 | return new OperationProvidedRoleEditPart(view); |
53 | |
54 | case OperationProvidedRoleEntityNameEditPart.VISUAL_ID: |
55 | return new OperationProvidedRoleEntityNameEditPart(view); |
56 | |
57 | case OperationRequiredRoleEditPart.VISUAL_ID: |
58 | return new OperationRequiredRoleEditPart(view); |
59 | |
60 | case OperationRequiredRoleEntityNameEditPart.VISUAL_ID: |
61 | return new OperationRequiredRoleEntityNameEditPart(view); |
62 | |
63 | case SourceRoleEditPart.VISUAL_ID: |
64 | return new SourceRoleEditPart(view); |
65 | |
66 | case SourceRoleEntityNameEditPart.VISUAL_ID: |
67 | return new SourceRoleEntityNameEditPart(view); |
68 | |
69 | case SinkRoleEditPart.VISUAL_ID: |
70 | return new SinkRoleEditPart(view); |
71 | |
72 | case SinkRoleEntityNameEditPart.VISUAL_ID: |
73 | return new SinkRoleEntityNameEditPart(view); |
74 | |
75 | case InfrastructureProvidedRoleEditPart.VISUAL_ID: |
76 | return new InfrastructureProvidedRoleEditPart(view); |
77 | |
78 | case InfrastructureProvidedRoleEntityNameEditPart.VISUAL_ID: |
79 | return new InfrastructureProvidedRoleEntityNameEditPart(view); |
80 | |
81 | case InfrastructureRequiredRoleEditPart.VISUAL_ID: |
82 | return new InfrastructureRequiredRoleEditPart(view); |
83 | |
84 | case InfrastructureRequiredRoleEntityNameEditPart.VISUAL_ID: |
85 | return new InfrastructureRequiredRoleEntityNameEditPart(view); |
86 | |
87 | case OperationProvidedRole2EditPart.VISUAL_ID: |
88 | return new OperationProvidedRole2EditPart(view); |
89 | |
90 | case OperationProvidedRoleEntityName2EditPart.VISUAL_ID: |
91 | return new OperationProvidedRoleEntityName2EditPart(view); |
92 | |
93 | case OperationRequiredRole2EditPart.VISUAL_ID: |
94 | return new OperationRequiredRole2EditPart(view); |
95 | |
96 | case OperationRequiredRoleEntityName2EditPart.VISUAL_ID: |
97 | return new OperationRequiredRoleEntityName2EditPart(view); |
98 | |
99 | case ComposedProvidingRequiringEntityCompositeStructureInnerCompartmentEditPart.VISUAL_ID: |
100 | return new ComposedProvidingRequiringEntityCompositeStructureInnerCompartmentEditPart( |
101 | view); |
102 | |
103 | case AssemblyConnectorEditPart.VISUAL_ID: |
104 | return new AssemblyConnectorEditPart(view); |
105 | |
106 | case AssemblyEventConnectorEditPart.VISUAL_ID: |
107 | return new AssemblyEventConnectorEditPart(view); |
108 | |
109 | case RequiredDelegationConnectorEditPart.VISUAL_ID: |
110 | return new RequiredDelegationConnectorEditPart(view); |
111 | |
112 | case ProvidedDelegationConnectorEditPart.VISUAL_ID: |
113 | return new ProvidedDelegationConnectorEditPart(view); |
114 | |
115 | case AssemblyInfrastructureConnectorEditPart.VISUAL_ID: |
116 | return new AssemblyInfrastructureConnectorEditPart(view); |
117 | |
118 | } |
119 | } |
120 | return createUnrecognizedEditPart(context, model); |
121 | } |
122 | |
123 | /** |
124 | * @generated |
125 | */ |
126 | private EditPart createUnrecognizedEditPart(EditPart context, Object model) { |
127 | // Handle creation of unrecognized child node EditParts here |
128 | return null; |
129 | } |
130 | |
131 | /** |
132 | * @generated |
133 | */ |
134 | public static CellEditorLocator getTextCellEditorLocator( |
135 | ITextAwareEditPart source) { |
136 | if (source.getFigure() instanceof WrappingLabel) |
137 | return new TextCellEditorLocator((WrappingLabel) source.getFigure()); |
138 | else { |
139 | return new LabelCellEditorLocator((Label) source.getFigure()); |
140 | } |
141 | } |
142 | |
143 | /** |
144 | * @generated |
145 | */ |
146 | static private class TextCellEditorLocator implements CellEditorLocator { |
147 | |
148 | /** |
149 | * @generated |
150 | */ |
151 | private WrappingLabel wrapLabel; |
152 | |
153 | /** |
154 | * @generated |
155 | */ |
156 | public TextCellEditorLocator(WrappingLabel wrapLabel) { |
157 | this.wrapLabel = wrapLabel; |
158 | } |
159 | |
160 | /** |
161 | * @generated |
162 | */ |
163 | public WrappingLabel getWrapLabel() { |
164 | return wrapLabel; |
165 | } |
166 | |
167 | /** |
168 | * @generated |
169 | */ |
170 | public void relocate(CellEditor celleditor) { |
171 | Text text = (Text) celleditor.getControl(); |
172 | Rectangle rect = getWrapLabel().getTextBounds().getCopy(); |
173 | getWrapLabel().translateToAbsolute(rect); |
174 | if (getWrapLabel().isTextWrapOn() |
175 | && getWrapLabel().getText().length() > 0) { |
176 | rect.setSize(new Dimension(text.computeSize(rect.width, |
177 | SWT.DEFAULT))); |
178 | } else { |
179 | int avr = FigureUtilities.getFontMetrics(text.getFont()) |
180 | .getAverageCharWidth(); |
181 | rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, |
182 | SWT.DEFAULT)).expand(avr * 2, 0)); |
183 | } |
184 | if (!rect.equals(new Rectangle(text.getBounds()))) { |
185 | text.setBounds(rect.x, rect.y, rect.width, rect.height); |
186 | } |
187 | } |
188 | |
189 | } |
190 | |
191 | /** |
192 | * @generated |
193 | */ |
194 | private static class LabelCellEditorLocator implements CellEditorLocator { |
195 | |
196 | /** |
197 | * @generated |
198 | */ |
199 | private Label label; |
200 | |
201 | /** |
202 | * @generated |
203 | */ |
204 | public LabelCellEditorLocator(Label label) { |
205 | this.label = label; |
206 | } |
207 | |
208 | /** |
209 | * @generated |
210 | */ |
211 | public Label getLabel() { |
212 | return label; |
213 | } |
214 | |
215 | /** |
216 | * @generated |
217 | */ |
218 | public void relocate(CellEditor celleditor) { |
219 | Text text = (Text) celleditor.getControl(); |
220 | Rectangle rect = getLabel().getTextBounds().getCopy(); |
221 | getLabel().translateToAbsolute(rect); |
222 | int avr = FigureUtilities.getFontMetrics(text.getFont()) |
223 | .getAverageCharWidth(); |
224 | rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, |
225 | SWT.DEFAULT)).expand(avr * 2, 0)); |
226 | if (!rect.equals(new Rectangle(text.getBounds()))) { |
227 | text.setBounds(rect.x, rect.y, rect.width, rect.height); |
228 | } |
229 | } |
230 | } |
231 | } |