1 | /* |
2 | * Copyright 2007, SDQ, IPD, U KA |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.allocation.edit.policies; |
5 | |
6 | import java.util.Collections; |
7 | import java.util.List; |
8 | |
9 | import org.eclipse.draw2d.ColorConstants; |
10 | import org.eclipse.draw2d.Figure; |
11 | import org.eclipse.draw2d.Graphics; |
12 | import org.eclipse.draw2d.IFigure; |
13 | import org.eclipse.draw2d.Label; |
14 | import org.eclipse.draw2d.RectangleFigure; |
15 | import org.eclipse.draw2d.geometry.Rectangle; |
16 | import org.eclipse.gef.GraphicalEditPart; |
17 | import org.eclipse.gef.handles.MoveHandle; |
18 | import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx; |
19 | import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx; |
20 | import org.eclipse.gmf.runtime.draw2d.ui.figures.WrapLabel; |
21 | |
22 | /** |
23 | * @generated |
24 | */ |
25 | public class PalladioComponentModelTextNonResizableEditPolicy extends |
26 | NonResizableEditPolicyEx { |
27 | |
28 | /** |
29 | * @generated |
30 | */ |
31 | private IFigure selectionFeedbackFigure; |
32 | |
33 | /** |
34 | * @generated |
35 | */ |
36 | private IFigure focusFeedbackFigure; |
37 | |
38 | /** |
39 | * @generated |
40 | */ |
41 | protected void showPrimarySelection() { |
42 | if (getHostFigure() instanceof WrapLabel) { |
43 | ((WrapLabel) getHostFigure()).setSelected(true); |
44 | ((WrapLabel) getHostFigure()).setFocus(true); |
45 | } else { |
46 | showSelection(); |
47 | showFocus(); |
48 | } |
49 | } |
50 | |
51 | /** |
52 | * @generated |
53 | */ |
54 | protected void showSelection() { |
55 | if (getHostFigure() instanceof WrapLabel) { |
56 | ((WrapLabel) getHostFigure()).setSelected(true); |
57 | ((WrapLabel) getHostFigure()).setFocus(false); |
58 | } else { |
59 | hideSelection(); |
60 | addFeedback(selectionFeedbackFigure = createSelectionFeedbackFigure()); |
61 | refreshSelectionFeedback(); |
62 | hideFocus(); |
63 | } |
64 | } |
65 | |
66 | /** |
67 | * @generated |
68 | */ |
69 | protected void hideSelection() { |
70 | if (getHostFigure() instanceof WrapLabel) { |
71 | ((WrapLabel) getHostFigure()).setSelected(false); |
72 | ((WrapLabel) getHostFigure()).setFocus(false); |
73 | } else { |
74 | if (selectionFeedbackFigure != null) { |
75 | removeFeedback(selectionFeedbackFigure); |
76 | selectionFeedbackFigure = null; |
77 | } |
78 | hideFocus(); |
79 | } |
80 | } |
81 | |
82 | /** |
83 | * @generated |
84 | */ |
85 | protected void showFocus() { |
86 | if (getHostFigure() instanceof WrapLabel) { |
87 | ((WrapLabel) getHostFigure()).setFocus(true); |
88 | } else { |
89 | hideFocus(); |
90 | addFeedback(focusFeedbackFigure = createFocusFeedbackFigure()); |
91 | refreshFocusFeedback(); |
92 | } |
93 | } |
94 | |
95 | /** |
96 | * @generated |
97 | */ |
98 | protected void hideFocus() { |
99 | if (getHostFigure() instanceof WrapLabel) { |
100 | ((WrapLabel) getHostFigure()).setFocus(false); |
101 | } else { |
102 | if (focusFeedbackFigure != null) { |
103 | removeFeedback(focusFeedbackFigure); |
104 | focusFeedbackFigure = null; |
105 | } |
106 | } |
107 | } |
108 | |
109 | /** |
110 | * @generated |
111 | */ |
112 | protected Rectangle getFeedbackBounds() { |
113 | Rectangle bounds; |
114 | if (getHostFigure() instanceof Label) { |
115 | bounds = ((Label) getHostFigure()).getTextBounds(); |
116 | bounds.intersect(getHostFigure().getBounds()); |
117 | } else { |
118 | bounds = getHostFigure().getBounds().getCopy(); |
119 | } |
120 | getHostFigure().getParent().translateToAbsolute(bounds); |
121 | getFeedbackLayer().translateToRelative(bounds); |
122 | return bounds; |
123 | } |
124 | |
125 | /** |
126 | * @generated |
127 | */ |
128 | protected IFigure createSelectionFeedbackFigure() { |
129 | if (getHostFigure() instanceof Label) { |
130 | Label feedbackFigure = new Label(); |
131 | feedbackFigure.setOpaque(true); |
132 | feedbackFigure |
133 | .setBackgroundColor(ColorConstants.menuBackgroundSelected); |
134 | feedbackFigure |
135 | .setForegroundColor(ColorConstants.menuForegroundSelected); |
136 | return feedbackFigure; |
137 | } else { |
138 | RectangleFigure feedbackFigure = new RectangleFigure(); |
139 | feedbackFigure.setFill(false); |
140 | return feedbackFigure; |
141 | } |
142 | } |
143 | |
144 | /** |
145 | * @generated |
146 | */ |
147 | protected IFigure createFocusFeedbackFigure() { |
148 | return new Figure() { |
149 | |
150 | protected void paintFigure(Graphics graphics) { |
151 | graphics.drawFocus(getBounds().getResized(-1, -1)); |
152 | } |
153 | }; |
154 | } |
155 | |
156 | /** |
157 | * @generated |
158 | */ |
159 | protected void updateLabel(Label target) { |
160 | Label source = (Label) getHostFigure(); |
161 | target.setText(source.getText()); |
162 | target.setTextAlignment(source.getTextAlignment()); |
163 | target.setFont(source.getFont()); |
164 | } |
165 | |
166 | /** |
167 | * @generated |
168 | */ |
169 | protected void refreshSelectionFeedback() { |
170 | if (selectionFeedbackFigure != null) { |
171 | if (selectionFeedbackFigure instanceof Label) { |
172 | updateLabel((Label) selectionFeedbackFigure); |
173 | selectionFeedbackFigure.setBounds(getFeedbackBounds()); |
174 | } else { |
175 | selectionFeedbackFigure.setBounds(getFeedbackBounds().expand(5, |
176 | 5)); |
177 | } |
178 | } |
179 | } |
180 | |
181 | /** |
182 | * @generated |
183 | */ |
184 | protected void refreshFocusFeedback() { |
185 | if (focusFeedbackFigure != null) { |
186 | focusFeedbackFigure.setBounds(getFeedbackBounds()); |
187 | } |
188 | } |
189 | |
190 | /** |
191 | * @generated |
192 | */ |
193 | public void refreshFeedback() { |
194 | refreshSelectionFeedback(); |
195 | refreshFocusFeedback(); |
196 | } |
197 | |
198 | /** |
199 | * @generated |
200 | */ |
201 | protected List createSelectionHandles() { |
202 | MoveHandle moveHandle = new MoveHandle((GraphicalEditPart) getHost()); |
203 | moveHandle.setBorder(null); |
204 | moveHandle.setDragTracker(new DragEditPartsTrackerEx(getHost())); |
205 | return Collections.singletonList(moveHandle); |
206 | } |
207 | } |