Update bookmarks file API, link to editor and delete & rename handlers
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / BasicExecutionOccurrence.java
CommitLineData
73005152 1/**********************************************************************
df0b8ff4
BH
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
abbdd66a 4 *
73005152
BH
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
abbdd66a
AM
9 *
10 * Contributors:
73005152
BH
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
15
16import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor;
17import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
df0b8ff4 18import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.ISDPreferences;
3145ec83 19import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref;
73005152
BH
20
21/**
22 * BasicExecutionOccurrence is the UML2 execution occurrence graphical representation. It is attached to one Lifeline,
23 * the event occurrence "duration" along the lifeline is defined by two event occurrences
abbdd66a 24 *
73005152 25 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
abbdd66a 26 * @version 1.0
73005152 27 * @author sveyrier
abbdd66a 28 *
73005152
BH
29 */
30public class BasicExecutionOccurrence extends GraphNode {
31
df0b8ff4
BH
32 // ------------------------------------------------------------------------
33 // Constants
34 // ------------------------------------------------------------------------
35 /**
36 * The grahNode ID constant
37 */
73005152
BH
38 public static final String EXEC_OCC_TAG = "Execution_Occ"; //$NON-NLS-1$
39
df0b8ff4
BH
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43
44 /**
abbdd66a 45 * The corresponding lifeline.
df0b8ff4 46 */
eb63f5ff 47 protected Lifeline fLifeline = null;
df0b8ff4
BH
48
49 // ------------------------------------------------------------------------
50 // Constructors
51 // ------------------------------------------------------------------------
52 /**
53 * Default constructore
54 */
73005152 55 public BasicExecutionOccurrence() {
eb63f5ff 56 fPrefId = ISDPreferences.PREF_EXEC;
73005152
BH
57 }
58
df0b8ff4
BH
59 // ------------------------------------------------------------------------
60 // Constants
61 // ------------------------------------------------------------------------
62
63 /*
64 * (non-Javadoc)
65 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getX()
66 */
73005152
BH
67 @Override
68 public int getX() {
eb63f5ff 69 if (fLifeline == null) {
73005152 70 return 0;
df0b8ff4 71 }
eb63f5ff 72 return fLifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.EXECUTION_OCCURRENCE_WIDTH / 2;
73005152
BH
73 }
74
df0b8ff4
BH
75 /*
76 * (non-Javadoc)
77 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getY()
78 */
73005152
BH
79 @Override
80 public int getY() {
eb63f5ff 81 if (fLifeline == null) {
73005152 82 return 0;
df0b8ff4 83 }
eb63f5ff 84 return fLifeline.getY() + fLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fStartEventOccurrence;
73005152
BH
85 }
86
df0b8ff4
BH
87 /*
88 * (non-Javadoc)
89 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getWidth()
90 */
73005152
BH
91 @Override
92 public int getWidth() {
eb63f5ff 93 if (fLifeline == null) {
73005152 94 return 0;
df0b8ff4 95 }
73005152
BH
96 return Metrics.EXECUTION_OCCURRENCE_WIDTH;
97 }
98
df0b8ff4
BH
99 /*
100 * (non-Javadoc)
101 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getHeight()
102 */
73005152
BH
103 @Override
104 public int getHeight() {
eb63f5ff 105 if (fLifeline == null) {
73005152 106 return 0;
df0b8ff4 107 }
eb63f5ff 108 return ((Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing())) * (fEndEventOccurrence - fStartEventOccurrence);
73005152
BH
109 }
110
df0b8ff4
BH
111 /*
112 * (non-Javadoc)
113 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#contains(int, int)
114 */
73005152 115 @Override
eb63f5ff 116 public boolean contains(int xValue, int yValue) {
73005152
BH
117 int x = getX();
118 int y = getY();
119 int width = getWidth();
120 int height = getHeight();
121
abbdd66a 122 if (GraphNode.contains(x, y, width, height, xValue, yValue)) {
73005152
BH
123 return true;
124 }
125
eb63f5ff 126 if (getNodeAt(xValue, yValue) != null) {
73005152 127 return true;
df0b8ff4 128 }
73005152
BH
129 return false;
130 }
131
df0b8ff4
BH
132 /*
133 * (non-Javadoc)
134 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getName()
135 */
73005152
BH
136 @Override
137 public String getName() {
df0b8ff4 138 if (super.getName() == null || super.getName().equals("")) { //$NON-NLS-1$
eb63f5ff 139 return fLifeline.getToolTipText();
df0b8ff4 140 }
abbdd66a 141 return super.getName();
73005152
BH
142 }
143
144 /**
145 * Set the lifeline on which the execution occurrence appears.
abbdd66a 146 *
73005152
BH
147 * @param theLifeline - the parent lifeline
148 */
149 public void setLifeline(Lifeline theLifeline) {
eb63f5ff 150 fLifeline = theLifeline;
73005152
BH
151 }
152
153 /**
154 * Get the lifeline on which the execution occurrence appears.
abbdd66a 155 *
73005152
BH
156 * @return - the parent lifeline
157 */
158 public Lifeline getLifeline() {
eb63f5ff 159 return fLifeline;
73005152
BH
160 }
161
162 /**
163 * Get the execution start event occurrence
abbdd66a 164 *
73005152
BH
165 * @return the start event occurrence to set
166 */
167 @Override
168 public int getStartOccurrence() {
eb63f5ff 169 return fStartEventOccurrence;
73005152
BH
170 }
171
172 /**
173 * Set the execution end event occurrence
abbdd66a 174 *
73005152
BH
175 * @return the end event occurrence to set
176 */
177 @Override
178 public int getEndOccurrence() {
eb63f5ff 179 return fEndEventOccurrence;
73005152
BH
180 }
181
182 /**
183 * Set the execution start event occurrence
abbdd66a 184 *
73005152
BH
185 * @param occurrence the start event occurrence to set
186 */
187 public void setStartOccurrence(int occurrence) {
eb63f5ff 188 fStartEventOccurrence = occurrence;
73005152
BH
189 }
190
191 /**
192 * Set the execution end event occurrence
abbdd66a 193 *
73005152
BH
194 * @param occurrence the end event occurrence to set
195 */
196 public void setEndOccurrence(int occurrence) {
eb63f5ff 197 fEndEventOccurrence = occurrence;
73005152
BH
198 }
199
df0b8ff4
BH
200 /*
201 * (non-Javadoc)
202 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
203 */
73005152
BH
204 @Override
205 public void draw(IGC context) {
206 int x = getX();
207 int y = getY();
208 int width = getWidth();
209 int height = getHeight();
eb63f5ff
BH
210 IColor tempFillColor = null;
211 IColor tempStrokeColor = null;
73005152 212
3145ec83 213 ISDPreferences pref = SDViewPref.getInstance();
abbdd66a 214
73005152
BH
215 // The execution occurrence is selected
216 // if the owning lifeline is selected
eb63f5ff 217 if (fLifeline.isSelected() || isSelected()) {
3145ec83
BH
218 context.setBackground(pref.getBackGroundColorSelection());
219 context.setForeground(pref.getForeGroundColorSelection());
73005152
BH
220 } else {
221 tempFillColor = setUnselectedFillColor(context);
222 }
3145ec83 223 if (pref.useGradienColor()) {
73005152 224 context.fillGradientRectangle(x, y, width, height, false);
df0b8ff4 225 } else {
73005152 226 context.fillRectangle(x, y, width, height);
df0b8ff4 227 }
73005152
BH
228 tempStrokeColor = setUnselectedStrokeColor(context);
229 context.drawRectangle(x, y, width, height);
230 if (tempFillColor != null) {
231 tempFillColor.dispose();
73005152
BH
232 }
233 if (tempStrokeColor != null) {
234 tempStrokeColor.dispose();
73005152 235 }
df0b8ff4 236 if (hasFocus()) {
73005152 237 drawFocus(context);
df0b8ff4 238 }
73005152
BH
239 super.drawChildenNodes(context);
240 }
241
242 /**
243 * Rewrite this method in your extension in order to support customized fill colors
abbdd66a 244 *
73005152
BH
245 * @param context
246 * @return IColor
247 */
248 protected IColor setUnselectedFillColor(IGC context) {
3145ec83
BH
249
250 ISDPreferences pref = SDViewPref.getInstance();
251
252 if (pref.useGradienColor()) {
253 context.setGradientColor(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
254 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_FRAME));
df0b8ff4 255 } else {
3145ec83 256 context.setBackground(pref.getBackGroundColor(ISDPreferences.PREF_EXEC));
df0b8ff4 257 }
73005152
BH
258 return null;
259 }
260
261 /**
262 * Rewrite this method in your extension in order to support customized stroke colors
abbdd66a 263 *
73005152
BH
264 * @param context
265 * @return IColor
266 */
267 protected IColor setUnselectedStrokeColor(IGC context) {
3145ec83 268 context.setForeground(SDViewPref.getInstance().getForeGroundColor(ISDPreferences.PREF_EXEC));
73005152
BH
269 return null;
270 }
271
df0b8ff4
BH
272 /*
273 * (non-Javadoc)
274 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
275 */
73005152
BH
276 @Override
277 public String getArrayId() {
278 return EXEC_OCC_TAG;
279 }
280
df0b8ff4
BH
281 /*
282 * (non-Javadoc)
283 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
284 */
73005152
BH
285 @Override
286 public boolean positiveDistanceToPoint(int x, int y) {
df0b8ff4 287 if (getY() + getHeight() > y) {
73005152 288 return true;
df0b8ff4 289 }
73005152
BH
290 return false;
291 }
292
df0b8ff4
BH
293 /*
294 * (non-Javadoc)
295 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#isVisible(int, int, int, int)
296 */
73005152
BH
297 @Override
298 public boolean isVisible(int x, int y, int width, int height) {
299 if ((getLifeline() != null) && (getLifeline().isVisible(x, y, width, height))) {
300 int ly = getY();
301 int lh = getHeight();
df0b8ff4 302 if (ly >= y && ly < y + height) {
73005152 303 return true;
df0b8ff4
BH
304 }
305 if (ly + lh > y && ly + lh <= y + height) {
73005152 306 return true;
df0b8ff4
BH
307 }
308 if ((ly < y) && (ly + lh > y + height)) {
73005152 309 return true;
df0b8ff4 310 }
73005152
BH
311 }
312 return false;
313 }
314}
This page took 0.050161 seconds and 5 git commands to generate.