Commit | Line | Data |
---|---|---|
73005152 | 1 | /********************************************************************** |
df0b8ff4 BH |
2 | * Copyright (c) 2005, 2008 IBM Corporation and others. |
3 | * Copyright (c) 2011, 2012 Ericsson. | |
a55887ca | 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 | |
a55887ca AM |
9 | * |
10 | * Contributors: | |
73005152 BH |
11 | * IBM - Initial API and implementation |
12 | * Bernd Hufmann - Updated for TMF | |
13 | **********************************************************************/ | |
14 | package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core; | |
15 | ||
16 | import java.util.ArrayList; | |
17 | import java.util.Arrays; | |
18 | import java.util.Iterator; | |
19 | import java.util.List; | |
20 | ||
4df4581d | 21 | import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; |
73005152 BH |
22 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IColor; |
23 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC; | |
24 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences.SDViewPref; | |
25 | import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.TimeEventComparator; | |
26 | ||
27 | /** | |
28 | * The Frame class is the base sequence diagram graph nodes container.<br> | |
29 | * For instance, only one frame can be drawn in the View.<br> | |
30 | * Lifelines, Messages and Stop which are supposed to represent a Sequence diagram are drawn in a Frame.<br> | |
31 | * Only the graph node added to their representing list will be drawn. | |
a55887ca | 32 | * |
73005152 BH |
33 | * The lifelines are appended along the X axsis when added in a frame.<br> |
34 | * The syncMessages are ordered along the Y axsis depending on the event occurrence they are attached to.<br> | |
a55887ca | 35 | * |
73005152 BH |
36 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details |
37 | * @author sveyrier | |
38 | * @version 1.0 | |
39 | */ | |
40 | public class Frame extends BasicFrame { | |
41 | ||
df0b8ff4 BH |
42 | // ------------------------------------------------------------------------ |
43 | // Attributes | |
44 | // ------------------------------------------------------------------------ | |
45 | /** | |
46 | * The lifeline that is current highlighted. | |
47 | */ | |
eb63f5ff | 48 | protected Lifeline fHighlightLifeline = null; |
df0b8ff4 BH |
49 | /** |
50 | * The value of the start event. | |
51 | */ | |
eb63f5ff | 52 | protected int fStartEvent = 0; |
df0b8ff4 BH |
53 | /** |
54 | * The nubmer of events in the frame. | |
55 | */ | |
eb63f5ff | 56 | protected int fNbEvent = 0; |
df0b8ff4 BH |
57 | /** |
58 | * The color for highlighting. | |
59 | */ | |
eb63f5ff | 60 | protected IColor fHighlightColor = null; |
df0b8ff4 BH |
61 | /** |
62 | * The list of time events of the corresponding execution occurrences. | |
63 | */ | |
eb63f5ff | 64 | protected List<SDTimeEvent> fExecutionOccurrencesWithTime; |
df0b8ff4 BH |
65 | /** |
66 | * The Array of lifeline categories. | |
67 | */ | |
eb63f5ff | 68 | protected LifelineCategories[] fLifelineCategories = null; |
73005152 | 69 | |
df0b8ff4 BH |
70 | // ------------------------------------------------------------------------ |
71 | // Methods | |
72 | // ------------------------------------------------------------------------ | |
73 | ||
73005152 BH |
74 | /** |
75 | * Returns a list of all lifelines known by this frame. Known lifelines are the only one which can be displayed on | |
76 | * screen. | |
a55887ca | 77 | * |
73005152 BH |
78 | * @return the lifelines list |
79 | */ | |
80 | protected List<GraphNode> getLifelines() { | |
eb63f5ff | 81 | if (!fHasChilden) { |
73005152 | 82 | return null; |
a55887ca | 83 | } |
abbdd66a | 84 | return fNodes.get(Lifeline.LIFELINE_TAG); |
73005152 BH |
85 | } |
86 | ||
87 | /** | |
88 | * Returns the number of lifelines stored in the frame | |
a55887ca | 89 | * |
73005152 BH |
90 | * @return the number of lifelines |
91 | */ | |
92 | public int lifeLinesCount() { | |
93 | List<GraphNode> lifelines = getLifelines(); | |
df0b8ff4 | 94 | if (lifelines != null) { |
73005152 | 95 | return lifelines.size(); |
df0b8ff4 BH |
96 | } |
97 | return 0; | |
73005152 BH |
98 | } |
99 | ||
100 | /** | |
101 | * Returns the lifeline at the given index in the lifelines array | |
a55887ca | 102 | * |
73005152 | 103 | * @param index the position in the lifeline array |
df0b8ff4 | 104 | * @return the lifeline or <code>null</code> |
73005152 BH |
105 | */ |
106 | public Lifeline getLifeline(int index) { | |
df0b8ff4 | 107 | if ((getLifelines() != null) && (index >= 0) && (index < lifeLinesCount())) { |
73005152 | 108 | return (Lifeline) getLifelines().get(index); |
df0b8ff4 | 109 | } |
73005152 BH |
110 | return null; |
111 | } | |
112 | ||
113 | /** | |
114 | * Returns a list of syncMessages known by this frame. Known syncMessages are the only on which can be displayed on | |
115 | * screen | |
a55887ca | 116 | * |
73005152 BH |
117 | * @return the syncMessages list |
118 | */ | |
119 | protected List<GraphNode> getSyncMessages() { | |
eb63f5ff | 120 | if (!fHasChilden) { |
73005152 | 121 | return null; |
a55887ca | 122 | } |
abbdd66a | 123 | return fNodes.get(SyncMessage.SYNC_MESS_TAG); |
73005152 BH |
124 | } |
125 | ||
126 | /** | |
127 | * Returns the number of syncMessages stored in the frame | |
a55887ca | 128 | * |
73005152 BH |
129 | * @return the number of syncMessage |
130 | */ | |
131 | public int syncMessageCount() { | |
df0b8ff4 | 132 | if (getSyncMessages() != null) { |
73005152 | 133 | return getSyncMessages().size(); |
a55887ca | 134 | } |
df0b8ff4 | 135 | return 0; |
73005152 BH |
136 | } |
137 | ||
138 | /** | |
139 | * Returns the syncMessage at the given index in the syncMessages array | |
a55887ca | 140 | * |
73005152 | 141 | * @param index the position in the syncMessages array |
df0b8ff4 | 142 | * @return the syncMessage or <code>null</code> |
73005152 BH |
143 | */ |
144 | public SyncMessage getSyncMessage(int index) { | |
df0b8ff4 | 145 | if ((getSyncMessages() != null) && (index >= 0) && (index < getSyncMessages().size())) { |
73005152 | 146 | return (SyncMessage) getSyncMessages().get(index); |
df0b8ff4 | 147 | } |
73005152 BH |
148 | return null; |
149 | } | |
150 | ||
151 | /** | |
152 | * Returns a list of asyncMessages known by this frame. Known asyncMessages are the only on which can be displayed | |
153 | * on screen | |
a55887ca | 154 | * |
df0b8ff4 | 155 | * @return the asyncMessages list or <code>null</code> |
73005152 BH |
156 | */ |
157 | protected List<GraphNode> getAsyncMessages() { | |
eb63f5ff | 158 | if (!fHasChilden) { |
73005152 | 159 | return null; |
df0b8ff4 | 160 | } |
abbdd66a | 161 | return fNodes.get(AsyncMessage.ASYNC_MESS_TAG); |
73005152 BH |
162 | } |
163 | ||
164 | /** | |
165 | * Returns the number of asyncMessage stored in the frame | |
a55887ca | 166 | * |
73005152 BH |
167 | * @return the number of asyncMessage |
168 | */ | |
169 | public int asyncMessageCount() { | |
df0b8ff4 | 170 | if (getAsyncMessages() != null) { |
73005152 | 171 | return getAsyncMessages().size(); |
df0b8ff4 BH |
172 | } |
173 | return 0; | |
73005152 BH |
174 | } |
175 | ||
176 | /** | |
177 | * Returns the asyncMessage at the given index in the asyncMessage array | |
a55887ca | 178 | * |
73005152 | 179 | * @param index the position in the asyncMessage array |
df0b8ff4 | 180 | * @return the asyncMessage or <code>null</code> |
73005152 BH |
181 | */ |
182 | public AsyncMessage getAsyncMessage(int index) { | |
df0b8ff4 | 183 | if ((getAsyncMessages() != null) && (index >= 0) && (index < getAsyncMessages().size())) { |
73005152 | 184 | return (AsyncMessage) getAsyncMessages().get(index); |
df0b8ff4 | 185 | } |
73005152 BH |
186 | return null; |
187 | } | |
188 | ||
189 | /** | |
190 | * Returns a list of syncMessages return known by this frame. Known syncMessages return are the only on which can be | |
191 | * displayed on screen | |
a55887ca | 192 | * |
df0b8ff4 | 193 | * @return the syncMessages return list or <code>null</code> |
73005152 BH |
194 | */ |
195 | protected List<GraphNode> getSyncMessagesReturn() { | |
eb63f5ff | 196 | if (!fHasChilden) { |
73005152 | 197 | return null; |
df0b8ff4 | 198 | } |
abbdd66a | 199 | return fNodes.get(SyncMessageReturn.SYNC_MESS_RET_TAG); |
73005152 BH |
200 | } |
201 | ||
202 | /** | |
203 | * Returns the number of syncMessageReturn stored in the frame | |
a55887ca | 204 | * |
73005152 BH |
205 | * @return the number of syncMessageReturn |
206 | */ | |
207 | public int syncMessageReturnCount() { | |
df0b8ff4 | 208 | if (getSyncMessagesReturn() != null) { |
73005152 | 209 | return getSyncMessagesReturn().size(); |
df0b8ff4 BH |
210 | } |
211 | return 0; | |
73005152 BH |
212 | } |
213 | ||
214 | /** | |
215 | * Returns the syncMessageReturn at the given index in the syncMessageReturn array | |
a55887ca | 216 | * |
73005152 | 217 | * @param index the position in the syncMessageReturn array |
df0b8ff4 | 218 | * @return the syncMessageReturn or <code>null</code> |
73005152 BH |
219 | */ |
220 | public SyncMessageReturn getSyncMessageReturn(int index) { | |
df0b8ff4 | 221 | if ((getSyncMessagesReturn() != null) && (index >= 0) && (index < getSyncMessagesReturn().size())) { |
73005152 | 222 | return (SyncMessageReturn) getSyncMessagesReturn().get(index); |
df0b8ff4 | 223 | } |
73005152 BH |
224 | return null; |
225 | } | |
226 | ||
227 | /** | |
228 | * Returns a list of asyncMessageRetun known by this frame. Known asyncMessageRetun are the only on which can be | |
229 | * displayed on screen | |
a55887ca | 230 | * |
df0b8ff4 | 231 | * @return the asyncMessageRetun list or <code>null</code> |
73005152 BH |
232 | */ |
233 | protected List<GraphNode> getAsyncMessagesReturn() { | |
eb63f5ff | 234 | if (!fHasChilden) { |
73005152 | 235 | return null; |
df0b8ff4 | 236 | } |
abbdd66a | 237 | return fNodes.get(AsyncMessageReturn.ASYNC_MESS_RET_TAG); |
73005152 BH |
238 | } |
239 | ||
240 | /** | |
241 | * Returns the number of asyncMessageReturn stored in the frame | |
a55887ca | 242 | * |
73005152 BH |
243 | * @return the number of asyncMessageReturn |
244 | */ | |
245 | public int asyncMessageReturnCount() { | |
df0b8ff4 | 246 | if (getAsyncMessagesReturn() != null) { |
73005152 | 247 | return getAsyncMessagesReturn().size(); |
df0b8ff4 BH |
248 | } |
249 | return 0; | |
73005152 BH |
250 | } |
251 | ||
252 | /** | |
253 | * Returns the asyncMessageReturn at the given index in the asyncMessageReturn array | |
a55887ca | 254 | * |
73005152 | 255 | * @param index the position in the asyncMessageReturn array |
df0b8ff4 | 256 | * @return the asyncMessageReturn or <code>null</code> |
73005152 BH |
257 | */ |
258 | public AsyncMessageReturn getAsyncMessageReturn(int index) { | |
df0b8ff4 | 259 | if ((getAsyncMessagesReturn() != null) && (index >= 0) && (index < getAsyncMessagesReturn().size())) { |
73005152 | 260 | return (AsyncMessageReturn) getAsyncMessagesReturn().get(index); |
df0b8ff4 | 261 | } |
73005152 BH |
262 | return null; |
263 | } | |
264 | ||
265 | /** | |
266 | * Adds a lifeline to the frame lifelines list. The lifeline X drawing order depends on the lifeline addition order | |
267 | * into the frame lifelines list. | |
a55887ca | 268 | * |
0d9a6d76 | 269 | * @param lifeline the lifeline to add |
73005152 | 270 | */ |
0d9a6d76 | 271 | public void addLifeLine(Lifeline lifeline) { |
eb63f5ff | 272 | fComputeMinMax = true; |
df0b8ff4 | 273 | if (lifeline == null) { |
73005152 | 274 | return; |
df0b8ff4 | 275 | } |
73005152 | 276 | // set the lifeline parent frame |
0d9a6d76 | 277 | lifeline.setFrame(this); |
73005152 BH |
278 | // Increate the frame lifeline counter |
279 | // and set the lifeline drawing order | |
0d9a6d76 FC |
280 | lifeline.setIndex(getNewHorizontalIndex()); |
281 | if (lifeline.hasTimeInfo()) { | |
eb63f5ff | 282 | fHasTimeInfo = true; |
73005152 BH |
283 | } |
284 | // add the lifeline to the lifelines list | |
0d9a6d76 | 285 | addNode(lifeline); |
73005152 BH |
286 | } |
287 | ||
288 | /** | |
289 | * Returns the first visible lifeline drawn in the view | |
a55887ca | 290 | * |
73005152 BH |
291 | * @return the first visible lifeline index |
292 | */ | |
293 | public int getFirstVisibleLifeline() { | |
eb63f5ff | 294 | if (!fHasChilden) { |
73005152 | 295 | return 0; |
eb63f5ff | 296 | } else if (fIndexes.get(Lifeline.LIFELINE_TAG) != null) { |
abbdd66a | 297 | return fIndexes.get(Lifeline.LIFELINE_TAG).intValue(); |
df0b8ff4 BH |
298 | } |
299 | return 0; | |
73005152 BH |
300 | } |
301 | ||
302 | /** | |
303 | * Returns the first visible synchronous message drawn in the view | |
a55887ca | 304 | * |
73005152 BH |
305 | * @return the first visible synchronous message index |
306 | */ | |
307 | public int getFirstVisibleSyncMessage() { | |
eb63f5ff | 308 | if (!fHasChilden) { |
73005152 | 309 | return 0; |
eb63f5ff | 310 | } else if (fIndexes.get(SyncMessage.SYNC_MESS_TAG) != null) { |
abbdd66a | 311 | return fIndexes.get(SyncMessage.SYNC_MESS_TAG).intValue(); |
df0b8ff4 BH |
312 | } |
313 | return 0; | |
73005152 BH |
314 | } |
315 | ||
316 | /** | |
317 | * Returns the first visible synchronous message return drawn in the view | |
a55887ca | 318 | * |
73005152 BH |
319 | * @return the first visible synchronous message return index |
320 | */ | |
321 | public int getFirstVisibleSyncMessageReturn() { | |
eb63f5ff | 322 | if (!fHasChilden) { |
73005152 | 323 | return 0; |
eb63f5ff | 324 | } else if (fIndexes.get(SyncMessageReturn.SYNC_MESS_RET_TAG) != null) { |
abbdd66a | 325 | return fIndexes.get(SyncMessageReturn.SYNC_MESS_RET_TAG).intValue(); |
df0b8ff4 BH |
326 | } |
327 | return 0; | |
73005152 BH |
328 | } |
329 | ||
330 | /** | |
331 | * Returns the first visible synchronous message drawn in the view | |
a55887ca | 332 | * |
73005152 BH |
333 | * @return the first visible synchronous message index |
334 | */ | |
335 | public int getFirstVisibleAsyncMessage() { | |
eb63f5ff | 336 | if (!fHasChilden) { |
73005152 | 337 | return 0; |
eb63f5ff | 338 | } else if (fIndexes.get(AsyncMessage.ASYNC_MESS_TAG) != null) { |
abbdd66a | 339 | return fIndexes.get(AsyncMessage.ASYNC_MESS_TAG).intValue(); |
df0b8ff4 BH |
340 | } |
341 | return 0; | |
73005152 BH |
342 | } |
343 | ||
344 | /** | |
345 | * Returns the first visible synchronous message return drawn in the view | |
a55887ca | 346 | * |
73005152 BH |
347 | * @return the first visible synchronous message return index |
348 | */ | |
349 | public int getFirstVisibleAsyncMessageReturn() { | |
eb63f5ff | 350 | if (!fHasChilden) { |
73005152 | 351 | return 0; |
eb63f5ff | 352 | } else if (fIndexes.get(AsyncMessageReturn.ASYNC_MESS_RET_TAG) != null) { |
abbdd66a | 353 | return fIndexes.get(AsyncMessageReturn.ASYNC_MESS_RET_TAG).intValue(); |
df0b8ff4 BH |
354 | } |
355 | return 0; | |
73005152 BH |
356 | } |
357 | ||
df0b8ff4 BH |
358 | /** |
359 | * Returns the list of execution occurrences. | |
a55887ca | 360 | * |
df0b8ff4 BH |
361 | * @return the list of execution occurrences |
362 | */ | |
73005152 | 363 | public List<SDTimeEvent> getExecutionOccurrencesWithTime() { |
eb63f5ff | 364 | return fExecutionOccurrencesWithTime; |
73005152 BH |
365 | } |
366 | ||
df0b8ff4 BH |
367 | /** |
368 | * Inserts a lifeline after a given lifeline. | |
a55887ca | 369 | * |
df0b8ff4 | 370 | * @param toInsert A lifeline to insert |
a55887ca | 371 | * @param after A lifelife the toInsert-lifeline will be inserted after. |
df0b8ff4 | 372 | */ |
73005152 | 373 | public void insertLifelineAfter(Lifeline toInsert, Lifeline after) { |
df0b8ff4 | 374 | if ((toInsert == null)) { |
73005152 | 375 | return; |
df0b8ff4 BH |
376 | } |
377 | if (toInsert == after) { | |
73005152 | 378 | return; |
df0b8ff4 | 379 | } |
73005152 | 380 | int insertPoint = 0; |
df0b8ff4 | 381 | if (after != null) { |
73005152 | 382 | insertPoint = after.getIndex(); |
df0b8ff4 | 383 | } |
73005152 | 384 | int removePoint = toInsert.getIndex() - 1; |
df0b8ff4 | 385 | if (removePoint >= insertPoint) { |
73005152 | 386 | getLifelines().remove(removePoint); |
df0b8ff4 | 387 | } |
73005152 | 388 | getLifelines().add(insertPoint, toInsert); |
df0b8ff4 | 389 | if (removePoint < insertPoint) { |
73005152 | 390 | getLifelines().remove(removePoint); |
df0b8ff4 | 391 | } |
73005152 | 392 | |
df0b8ff4 | 393 | if (removePoint >= insertPoint) { |
73005152 | 394 | toInsert.setIndex(insertPoint + 1); |
df0b8ff4 | 395 | } else { |
73005152 | 396 | toInsert.setIndex(insertPoint - 1); |
df0b8ff4 | 397 | } |
73005152 BH |
398 | |
399 | insertPoint++; | |
400 | if (removePoint >= insertPoint) { | |
401 | for (int i = insertPoint; i < getLifelines().size(); i++) { | |
402 | getLifeline(i).setIndex(i + 1); | |
403 | } | |
404 | } else { | |
405 | for (int i = 0; i < insertPoint && i < getLifelines().size(); i++) { | |
406 | getLifeline(i).setIndex(i + 1); | |
407 | } | |
408 | } | |
409 | } | |
410 | ||
df0b8ff4 BH |
411 | /** |
412 | * Inserts a lifeline before a given lifeline. | |
a55887ca AM |
413 | * |
414 | * @param toInsert | |
415 | * A lifeline to insert | |
416 | * @param before | |
417 | * A lifeline the toInsert-lifeline will be inserted before. | |
df0b8ff4 | 418 | */ |
73005152 | 419 | public void insertLifelineBefore(Lifeline toInsert, Lifeline before) { |
df0b8ff4 | 420 | if ((toInsert == null)) { |
73005152 | 421 | return; |
df0b8ff4 BH |
422 | } |
423 | if (toInsert == before) { | |
73005152 | 424 | return; |
df0b8ff4 | 425 | } |
73005152 | 426 | int insertPoint = 0; |
df0b8ff4 | 427 | if (before != null) { |
73005152 | 428 | insertPoint = before.getIndex() - 1; |
df0b8ff4 | 429 | } |
73005152 | 430 | int removePoint = toInsert.getIndex() - 1; |
df0b8ff4 | 431 | if (removePoint >= insertPoint) { |
73005152 | 432 | getLifelines().remove(removePoint); |
df0b8ff4 | 433 | } |
73005152 | 434 | getLifelines().add(insertPoint, toInsert); |
df0b8ff4 | 435 | if (removePoint < insertPoint) { |
73005152 | 436 | getLifelines().remove(removePoint); |
df0b8ff4 | 437 | } |
73005152 | 438 | |
df0b8ff4 | 439 | if (removePoint >= insertPoint) { |
73005152 | 440 | toInsert.setIndex(insertPoint + 1); |
df0b8ff4 | 441 | } else { |
73005152 | 442 | toInsert.setIndex(insertPoint - 1); |
df0b8ff4 | 443 | } |
73005152 BH |
444 | |
445 | insertPoint++; | |
446 | if (removePoint >= insertPoint) { | |
447 | for (int i = insertPoint; i < getLifelines().size(); i++) { | |
448 | getLifeline(i).setIndex(i + 1); | |
449 | } | |
450 | } else { | |
451 | for (int i = 0; i < insertPoint && i < getLifelines().size(); i++) { | |
452 | getLifeline(i).setIndex(i + 1); | |
453 | } | |
454 | } | |
455 | } | |
456 | ||
df0b8ff4 BH |
457 | /** |
458 | * Gets the closer life line to the given x-coordinate. | |
a55887ca | 459 | * |
df0b8ff4 | 460 | * @param x A x coordinate |
a55887ca | 461 | * @return the closer lifeline |
df0b8ff4 | 462 | */ |
73005152 BH |
463 | public Lifeline getCloserLifeline(int x) { |
464 | int index = (x - Metrics.FRAME_H_MARGIN + Metrics.LIFELINE_H_MAGIN) / Metrics.swimmingLaneWidth() - 1; | |
df0b8ff4 | 465 | if (index < 0) { |
73005152 | 466 | index = 0; |
df0b8ff4 BH |
467 | } |
468 | if (index >= getLifelines().size()) { | |
73005152 | 469 | index = getLifelines().size() - 1; |
df0b8ff4 | 470 | } |
73005152 BH |
471 | Lifeline node1, node2, node3; |
472 | int dist1, dist2, dist3; | |
473 | node1 = node2 = node3 = getLifeline(index); | |
474 | dist1 = dist2 = dist3 = Math.abs(node1.getX() + node1.getWidth() / 2 - x); | |
475 | if (index > 0) { | |
476 | node2 = getLifeline(index - 1); | |
477 | dist2 = Math.abs(node2.getX() + node2.getWidth() / 2 - x); | |
478 | } | |
479 | if (index < getLifelines().size() - 1) { | |
480 | node3 = getLifeline(index + 1); | |
481 | dist3 = Math.abs(node3.getX() + node3.getWidth() / 2 - x); | |
482 | } | |
df0b8ff4 | 483 | if (dist1 <= dist2 && dist1 <= dist3) { |
73005152 | 484 | return node1; |
df0b8ff4 | 485 | } else if (dist2 <= dist1 && dist2 <= dist3) { |
73005152 | 486 | return node2; |
df0b8ff4 BH |
487 | } |
488 | return node3; | |
73005152 BH |
489 | } |
490 | ||
df0b8ff4 BH |
491 | /** |
492 | * Re-orders the given list of lifelines. | |
a55887ca | 493 | * |
df0b8ff4 BH |
494 | * @param list A list of lifelines to reorder. |
495 | */ | |
eb63f5ff | 496 | public void reorder(List<?> list) { |
73005152 BH |
497 | for (int i = 0; i < list.size(); i++) { |
498 | if (list.get(i) instanceof Lifeline[]) { | |
499 | Lifeline temp[] = (Lifeline[]) list.get(i); | |
500 | if (temp.length == 2) { | |
501 | if (temp[1] == null) { | |
502 | insertLifelineAfter(temp[0], getLifeline(lifeLinesCount() - 1)); | |
df0b8ff4 | 503 | } else { |
73005152 | 504 | insertLifelineBefore(temp[0], temp[1]); |
df0b8ff4 | 505 | } |
73005152 BH |
506 | } |
507 | } | |
508 | } | |
509 | } | |
510 | ||
df0b8ff4 BH |
511 | /** |
512 | * Resets the time compression information. | |
513 | */ | |
73005152 | 514 | public void resetTimeCompression() { |
eb63f5ff BH |
515 | fHighlightLifeline = null; |
516 | this.fStartEvent = 0; | |
517 | this.fNbEvent = 0; | |
518 | fHighlightColor = null; | |
73005152 BH |
519 | } |
520 | ||
df0b8ff4 BH |
521 | /* |
522 | * (non-Javadoc) | |
523 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicFrame#computeMinMax() | |
524 | */ | |
73005152 BH |
525 | @Override |
526 | protected void computeMinMax() { | |
527 | List<SDTimeEvent> timeArray = buildTimeArray(); | |
3145ec83 | 528 | if ((timeArray == null) || timeArray.isEmpty()) { |
73005152 | 529 | return; |
df0b8ff4 | 530 | } |
73005152 | 531 | for (int i = 0; i < timeArray.size() - 1; i++) { |
abbdd66a AM |
532 | SDTimeEvent m1 = timeArray.get(i); |
533 | SDTimeEvent m2 = timeArray.get(i + 1); | |
eb63f5ff BH |
534 | if (SDViewPref.getInstance().excludeExternalTime() && ((m1.getGraphNode() instanceof BaseMessage) && (m2.getGraphNode() instanceof BaseMessage))) { |
535 | BaseMessage mes1 = (BaseMessage) m1.getGraphNode(); | |
536 | BaseMessage mes2 = (BaseMessage) m2.getGraphNode(); | |
537 | if ((mes2.fStartLifeline == null) || (mes1.fEndLifeline == null)) { | |
538 | continue; | |
73005152 | 539 | } |
eb63f5ff | 540 | } |
73005152 BH |
541 | |
542 | updateMinMax(m1, m2); | |
543 | } | |
544 | } | |
545 | ||
546 | /** | |
547 | * Find the two graph nodes that are closest to this date, one just earlier, second just later. If date is before | |
548 | * any graph node, bounds[0] is null and bounds[1] is the earliest. If date is after any graph node, bounds[1] is | |
549 | * null and bounds[0] is the latest. | |
a55887ca | 550 | * |
73005152 BH |
551 | * @param dateToFind date to be found |
552 | * @param bounds a two items array that will receive bounds if found | |
553 | * @return true if both bounds not null | |
554 | */ | |
d7dbf09a | 555 | public boolean findDateBounds(ITmfTimestamp dateToFind, ITimeRange bounds[]) { |
73005152 BH |
556 | if (hasTimeInfo()) { |
557 | List<SDTimeEvent> timeArray = buildTimeArray(); | |
3145ec83 BH |
558 | |
559 | if ((timeArray == null) || timeArray.isEmpty()) { | |
560 | return false; | |
561 | } | |
562 | ||
73005152 BH |
563 | bounds[0] = null; |
564 | bounds[1] = null; | |
565 | for (int i = 0; i < timeArray.size(); i++) { | |
abbdd66a | 566 | SDTimeEvent m = timeArray.get(i); |
73005152 BH |
567 | if (m.getTime().compareTo(dateToFind, true) > 0) { |
568 | bounds[1] = m.getGraphNode(); | |
569 | if (i > 0) { | |
abbdd66a | 570 | bounds[0] = timeArray.get(i - 1).getGraphNode(); |
73005152 BH |
571 | return true; |
572 | } | |
573 | return false; | |
574 | } | |
575 | } | |
abbdd66a | 576 | bounds[0] = timeArray.get(timeArray.size() - 1).getGraphNode(); |
73005152 BH |
577 | } |
578 | return false; | |
579 | } | |
580 | ||
df0b8ff4 BH |
581 | /** |
582 | * Set whether time information is available or not | |
a55887ca | 583 | * |
df0b8ff4 BH |
584 | * @param value <code>true</code> for has time information else <code>false</code> |
585 | */ | |
73005152 | 586 | protected void setHasTimeInfo(boolean value) { |
eb63f5ff | 587 | fHasTimeInfo = value; |
73005152 BH |
588 | } |
589 | ||
590 | /** | |
df0b8ff4 | 591 | * Returns whether frame has time info or not. |
a55887ca | 592 | * |
df0b8ff4 | 593 | * @return <code>true</code> whether frame has time info else <code>false</code> |
73005152 BH |
594 | */ |
595 | public boolean hasTimeInfo() { | |
eb63f5ff | 596 | return fHasTimeInfo; |
73005152 BH |
597 | } |
598 | ||
599 | /** | |
df0b8ff4 | 600 | * Highlights the time compression. |
a55887ca | 601 | * |
df0b8ff4 BH |
602 | * @param lifeline A lifeline to highlight |
603 | * @param startEvent A start event number | |
604 | * @param nbEvent A number of events | |
605 | * @param color A color for highlighting | |
73005152 BH |
606 | */ |
607 | public void highlightTimeCompression(Lifeline lifeline, int startEvent, int nbEvent, IColor color) { | |
eb63f5ff BH |
608 | fHighlightLifeline = lifeline; |
609 | this.fStartEvent = startEvent; | |
610 | this.fNbEvent = nbEvent; | |
611 | fHighlightColor = color; | |
73005152 BH |
612 | } |
613 | ||
614 | /** | |
615 | * Set the lifeline categories which will be use during the lifelines creation | |
a55887ca | 616 | * |
73005152 BH |
617 | * @see Lifeline#setCategory(int) |
618 | * @param categories the lifeline categories array | |
619 | */ | |
620 | public void setLifelineCategories(LifelineCategories[] categories) { | |
eb63f5ff | 621 | fLifelineCategories = Arrays.copyOf(categories, categories.length); |
73005152 BH |
622 | } |
623 | ||
624 | /** | |
625 | * Returns the lifeline categories array set for the this frame | |
a55887ca | 626 | * |
73005152 BH |
627 | * @return the lifeline categories array or null if not set |
628 | */ | |
629 | public LifelineCategories[] getLifelineCategories() { | |
a55887ca | 630 | return Arrays.copyOf(fLifelineCategories, fLifelineCategories.length); |
73005152 BH |
631 | } |
632 | ||
633 | /** | |
634 | * Adds a message to the Frame message list. Four kinds of syncMessages can be added:<br> | |
635 | * - synchronous syncMessages<br> | |
636 | * - synchronous syncMessages return<br> | |
637 | * - asynchronous syncMessages<br> | |
638 | * - asynchronous syncMessages return<br> | |
639 | * For drawing performance reason, it is recommended to add synchronous syncMessages in the same order they should | |
640 | * appear along the Y axis in the Frame. | |
a55887ca | 641 | * |
0d9a6d76 | 642 | * @param message the message to add |
73005152 BH |
643 | */ |
644 | public void addMessage(BaseMessage message) { | |
645 | addNode(message); | |
646 | } | |
647 | ||
df0b8ff4 BH |
648 | /* |
649 | * (non-Javadoc) | |
650 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicFrame#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC) | |
651 | */ | |
73005152 BH |
652 | @Override |
653 | public void draw(IGC context) { | |
654 | drawFrame(context); | |
eb63f5ff | 655 | if (!fHasChilden) { |
73005152 | 656 | return; |
df0b8ff4 | 657 | } |
a55887ca | 658 | |
eb63f5ff | 659 | if (fHighlightLifeline != null) { |
73005152 | 660 | IColor backupColor = context.getBackground(); |
3145ec83 | 661 | context.setBackground(SDViewPref.getInstance().getTimeCompressionSelectionColor()); |
eb63f5ff BH |
662 | int gy = fHighlightLifeline.getY() + fHighlightLifeline.getHeight() + (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fStartEvent; |
663 | context.fillRectangle(Metrics.FRAME_H_MARGIN + 1, gy, fHighlightLifeline.getX() + Metrics.getLifelineWidth() / 2 - Metrics.FRAME_H_MARGIN, (Metrics.getMessageFontHeigth() + Metrics.getMessagesSpacing()) * fNbEvent); | |
73005152 BH |
664 | context.setBackground(backupColor); |
665 | } | |
666 | super.draw(context, false); | |
667 | int lifelineArryStep = 1; | |
df0b8ff4 | 668 | if (Metrics.swimmingLaneWidth() * context.getZoom() < Metrics.LIFELINE_SIGNIFICANT_HSPACING) { |
73005152 | 669 | lifelineArryStep = Math.round(Metrics.LIFELINE_SIGNIFICANT_HSPACING / (Metrics.swimmingLaneWidth() * context.getZoom())); |
df0b8ff4 | 670 | } |
eb63f5ff | 671 | if (fIndexes.size() == 0) { |
73005152 | 672 | return; |
df0b8ff4 | 673 | } |
abbdd66a AM |
674 | int lifeLineDrawIndex = fIndexes.get(Lifeline.LIFELINE_TAG).intValue(); |
675 | for (int i = lifeLineDrawIndex; i < fNodes.get(Lifeline.LIFELINE_TAG).size(); i = i + lifelineArryStep) { | |
676 | Lifeline toDraw = (Lifeline) fNodes.get(Lifeline.LIFELINE_TAG).get(i); | |
df0b8ff4 | 677 | if (toDraw.getX() - Metrics.LIFELINE_SPACING / 2 > context.getContentsX() + context.getVisibleWidth()) { |
73005152 | 678 | break; |
df0b8ff4 | 679 | } |
73005152 BH |
680 | toDraw.drawName(context); |
681 | ||
eb63f5ff BH |
682 | if (fHighlightLifeline != null) { |
683 | if (toDraw == fHighlightLifeline) { | |
684 | toDraw.highlightExecOccurrenceRegion(context, fStartEvent, fNbEvent, fHighlightColor); | |
685 | } else if ((toDraw.getIndex() < fHighlightLifeline.getIndex()) || ((toDraw.getIndex() < fHighlightLifeline.getIndex()))) { | |
73005152 BH |
686 | |
687 | int acIndex = toDraw.getExecOccurrenceDrawIndex(); | |
688 | // acIndex = first visible execution occurrence | |
689 | // for drawing speed reason with only search on the visible subset | |
df0b8ff4 | 690 | if (toDraw.getExecutions() != null) { |
73005152 BH |
691 | for (int index = acIndex; index < toDraw.getExecutions().size(); index++) { |
692 | BasicExecutionOccurrence exec = (BasicExecutionOccurrence) toDraw.getExecutions().get(index); | |
eb63f5ff BH |
693 | int tempEvent = fStartEvent; |
694 | for (int j = 0; j < fNbEvent; j++) { | |
695 | if (((tempEvent >= exec.fStartEventOccurrence) && (tempEvent <= exec.fEndEventOccurrence) && (tempEvent + 1 >= exec.fStartEventOccurrence) && (tempEvent + 1 <= exec.fEndEventOccurrence))) { | |
3145ec83 | 696 | toDraw.highlightExecOccurrenceRegion(context, tempEvent, 1, SDViewPref.getInstance().getTimeCompressionSelectionColor()); |
73005152 BH |
697 | } |
698 | tempEvent = tempEvent + 1; | |
699 | } | |
700 | // if we are outside the visible area we stop right now | |
701 | // This works because execution occurrences are ordered along the Y axis | |
df0b8ff4 | 702 | if (exec.getY() > getY()) { |
73005152 | 703 | break; |
df0b8ff4 | 704 | } |
73005152 | 705 | } |
df0b8ff4 | 706 | } |
73005152 BH |
707 | } |
708 | } | |
709 | } | |
710 | } | |
711 | ||
df0b8ff4 BH |
712 | /* |
713 | * (non-Javadoc) | |
714 | * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BasicFrame#buildTimeArray() | |
715 | */ | |
73005152 BH |
716 | @Override |
717 | protected List<SDTimeEvent> buildTimeArray() { | |
3145ec83 | 718 | |
eb63f5ff | 719 | if (!fHasChilden) { |
3145ec83 BH |
720 | return new ArrayList<SDTimeEvent>(); |
721 | } | |
722 | ||
723 | List<SDTimeEvent> timeArray = super.buildTimeArray(); | |
724 | fExecutionOccurrencesWithTime = null; | |
725 | if (getLifelines() != null) { | |
abbdd66a AM |
726 | for (int i = 0; i < fNodes.get(Lifeline.LIFELINE_TAG).size(); i++) { |
727 | Lifeline lifeline = (Lifeline) fNodes.get(Lifeline.LIFELINE_TAG).get(i); | |
3145ec83 BH |
728 | if (lifeline.hasTimeInfo() && lifeline.getExecutions() != null) { |
729 | for (Iterator<GraphNode> j = lifeline.getExecutions().iterator(); j.hasNext();) { | |
730 | GraphNode o = j.next(); | |
731 | if (o instanceof ExecutionOccurrence) { | |
732 | ExecutionOccurrence eo = (ExecutionOccurrence) o; | |
733 | if (eo.hasTimeInfo()) { | |
734 | int event = eo.getStartOccurrence(); | |
735 | ITmfTimestamp time = eo.getStartTime(); | |
736 | SDTimeEvent f = new SDTimeEvent(time, event, eo); | |
737 | timeArray.add(f); | |
738 | if (fExecutionOccurrencesWithTime == null) { | |
739 | fExecutionOccurrencesWithTime = new ArrayList<SDTimeEvent>(); | |
73005152 | 740 | } |
3145ec83 BH |
741 | fExecutionOccurrencesWithTime.add(f); |
742 | event = eo.getEndOccurrence(); | |
743 | time = eo.getEndTime(); | |
744 | f = new SDTimeEvent(time, event, eo); | |
745 | timeArray.add(f); | |
746 | fExecutionOccurrencesWithTime.add(f); | |
73005152 BH |
747 | } |
748 | } | |
749 | } | |
750 | } | |
df0b8ff4 | 751 | } |
3145ec83 | 752 | } |
73005152 | 753 | |
3145ec83 BH |
754 | if (fExecutionOccurrencesWithTime != null) { |
755 | SDTimeEvent[] temp = fExecutionOccurrencesWithTime.toArray(new SDTimeEvent[fExecutionOccurrencesWithTime.size()]); | |
73005152 | 756 | Arrays.sort(temp, new TimeEventComparator()); |
3145ec83 | 757 | fExecutionOccurrencesWithTime = Arrays.asList(temp); |
73005152 | 758 | } |
3145ec83 BH |
759 | SDTimeEvent[] temp = timeArray.toArray(new SDTimeEvent[timeArray.size()]); |
760 | Arrays.sort(temp, new TimeEventComparator()); | |
761 | timeArray = Arrays.asList(temp); | |
762 | return timeArray; | |
73005152 BH |
763 | } |
764 | ||
df0b8ff4 BH |
765 | /** |
766 | * Get the closer leaving message. | |
a55887ca | 767 | * |
df0b8ff4 BH |
768 | * @param lifeline A lifeline reference |
769 | * @param message A message reference | |
770 | * @param list A list of graph nodes | |
771 | * @param smallerEvent A smaller event flag | |
772 | * @return the closer leaving message. | |
773 | */ | |
73005152 | 774 | protected GraphNode getCloserLeavingMessage(Lifeline lifeline, BaseMessage message, List<GraphNode> list, boolean smallerEvent) { |
df0b8ff4 | 775 | if (list == null) { |
73005152 | 776 | return null; |
df0b8ff4 BH |
777 | } |
778 | ||
3145ec83 | 779 | if (!smallerEvent) { |
73005152 | 780 | int event = 0; |
df0b8ff4 | 781 | if (message != null) { |
73005152 | 782 | event = message.getEventOccurrence(); |
df0b8ff4 | 783 | } |
73005152 | 784 | for (int i = 0; i < list.size(); i++) { |
abbdd66a | 785 | GraphNode node = list.get(i); |
73005152 BH |
786 | if (node instanceof SyncMessage) { |
787 | SyncMessage syncNode = (SyncMessage) node; | |
df0b8ff4 | 788 | if ((syncNode.getEventOccurrence() > event) && (syncNode.getStartLifeline() == lifeline) && !syncNode.isSameAs(message)) { |
73005152 | 789 | return node; |
df0b8ff4 | 790 | } |
73005152 BH |
791 | } else if (node instanceof AsyncMessage) { |
792 | AsyncMessage asyncNode = (AsyncMessage) node; | |
df0b8ff4 | 793 | if ((asyncNode.getStartOccurrence() > event) && (asyncNode.getStartLifeline() == lifeline) && !asyncNode.isSameAs(message)) { |
73005152 | 794 | return node; |
df0b8ff4 | 795 | } |
73005152 BH |
796 | } |
797 | } | |
798 | } else { | |
799 | int event = getMaxEventOccurrence(); | |
df0b8ff4 | 800 | if (message != null) { |
73005152 BH |
801 | if (message instanceof AsyncMessage) { |
802 | event = ((AsyncMessage) message).getStartOccurrence(); | |
df0b8ff4 | 803 | } else { |
73005152 | 804 | event = message.getEventOccurrence(); |
df0b8ff4 BH |
805 | } |
806 | } | |
73005152 | 807 | for (int i = list.size() - 1; i >= 0; i--) { |
abbdd66a | 808 | GraphNode node = list.get(i); |
73005152 BH |
809 | if (node instanceof SyncMessage) { |
810 | SyncMessage syncNode = (SyncMessage) node; | |
df0b8ff4 | 811 | if ((syncNode.getEventOccurrence() < event) && (syncNode.getStartLifeline() == lifeline) && !syncNode.isSameAs(message)) { |
73005152 | 812 | return node; |
df0b8ff4 | 813 | } |
73005152 BH |
814 | } else if (node instanceof AsyncMessage) { |
815 | AsyncMessage asyncNode = (AsyncMessage) node; | |
df0b8ff4 | 816 | if ((asyncNode.getStartOccurrence() < event) && (asyncNode.getStartLifeline() == lifeline) && !asyncNode.isSameAs(message)) { |
73005152 | 817 | return node; |
df0b8ff4 | 818 | } |
73005152 BH |
819 | } |
820 | } | |
821 | } | |
822 | return null; | |
823 | } | |
824 | ||
a55887ca | 825 | |
df0b8ff4 BH |
826 | /** |
827 | * Get the closer entering message. | |
a55887ca | 828 | * |
df0b8ff4 BH |
829 | * @param lifeline A lifeline reference |
830 | * @param message A message reference | |
831 | * @param list A list of graph nodes | |
832 | * @param smallerEvent A smaller event flag | |
833 | * @return the closer entering message. | |
834 | */ | |
73005152 | 835 | protected GraphNode getCloserEnteringMessage(Lifeline lifeline, BaseMessage message, List<GraphNode> list, boolean smallerEvent) { |
df0b8ff4 | 836 | if (list == null) { |
73005152 | 837 | return null; |
df0b8ff4 | 838 | } |
eb63f5ff | 839 | if (!smallerEvent) { |
73005152 | 840 | int event = 0; |
df0b8ff4 | 841 | if (message != null) { |
73005152 | 842 | event = message.getEventOccurrence(); |
df0b8ff4 | 843 | } |
73005152 | 844 | for (int i = 0; i < list.size(); i++) { |
abbdd66a | 845 | GraphNode node = list.get(i); |
73005152 BH |
846 | if (node instanceof SyncMessage) { |
847 | SyncMessage syncNode = (SyncMessage) node; | |
df0b8ff4 | 848 | if ((syncNode.getEventOccurrence() > event) && (syncNode.getEndLifeline() == lifeline) && !syncNode.isSameAs(message)) { |
73005152 | 849 | return node; |
df0b8ff4 | 850 | } |
73005152 BH |
851 | } else if (node instanceof AsyncMessage) { |
852 | AsyncMessage asyncNode = (AsyncMessage) node; | |
df0b8ff4 | 853 | if ((asyncNode.getStartOccurrence() > event) && (asyncNode.getEndLifeline() == lifeline) && !asyncNode.isSameAs(message)) { |
73005152 | 854 | return node; |
df0b8ff4 | 855 | } |
73005152 BH |
856 | } |
857 | } | |
858 | } else { | |
859 | int event = getMaxEventOccurrence(); | |
a55887ca | 860 | if (message != null) { |
73005152 BH |
861 | if (message instanceof AsyncMessage) { |
862 | event = ((AsyncMessage) message).getStartOccurrence(); | |
df0b8ff4 | 863 | } else { |
73005152 | 864 | event = message.getEventOccurrence(); |
df0b8ff4 | 865 | } |
a55887ca | 866 | } |
73005152 | 867 | for (int i = list.size() - 1; i >= 0; i--) { |
abbdd66a | 868 | GraphNode node = list.get(i); |
73005152 BH |
869 | if (node instanceof SyncMessage) { |
870 | SyncMessage syncNode = (SyncMessage) node; | |
df0b8ff4 | 871 | if ((syncNode.getEventOccurrence() < event) && (syncNode.getEndLifeline() == lifeline) && !syncNode.isSameAs(message)) { |
73005152 | 872 | return node; |
df0b8ff4 | 873 | } |
73005152 BH |
874 | } else if (node instanceof AsyncMessage) { |
875 | AsyncMessage asyncNode = (AsyncMessage) node; | |
df0b8ff4 | 876 | if ((asyncNode.getStartOccurrence() < event) && (asyncNode.getEndLifeline() == lifeline) && !asyncNode.isSameAs(message)) { |
73005152 | 877 | return node; |
df0b8ff4 | 878 | } |
73005152 BH |
879 | } |
880 | } | |
881 | } | |
882 | return null; | |
883 | } | |
884 | ||
df0b8ff4 BH |
885 | /** |
886 | * Get distance of given event from given graph node. | |
a55887ca | 887 | * |
df0b8ff4 BH |
888 | * @param node A graph node reference. |
889 | * @param event A event number to check. | |
890 | * @return distance of event from graph node. | |
891 | */ | |
73005152 BH |
892 | protected int distanceFromEvent(GraphNode node, int event) { |
893 | int distance = 0; | |
df0b8ff4 | 894 | if (node instanceof SyncMessage) { |
73005152 | 895 | distance = ((SyncMessage) node).getEventOccurrence() - event; |
df0b8ff4 | 896 | } else if (node instanceof AsyncMessage) { |
73005152 BH |
897 | int start = ((AsyncMessage) node).getStartOccurrence(); |
898 | int end = ((AsyncMessage) node).getEndOccurrence(); | |
df0b8ff4 | 899 | if ((start - event) < (end - event)) { |
73005152 | 900 | distance = start - event; |
df0b8ff4 | 901 | } else { |
73005152 | 902 | distance = end - event; |
df0b8ff4 | 903 | } |
73005152 BH |
904 | } |
905 | return Math.abs(distance); | |
906 | } | |
907 | ||
df0b8ff4 BH |
908 | /** |
909 | * Get node from 2 given nodes that is close to event. | |
a55887ca | 910 | * |
df0b8ff4 BH |
911 | * @param node1 A first graph node |
912 | * @param node2 A second graph node | |
913 | * @param event A event to check. | |
914 | * @return graph node that is closer or <code>null</code> | |
915 | */ | |
73005152 BH |
916 | protected GraphNode getCloserToEvent(GraphNode node1, GraphNode node2, int event) { |
917 | if ((node1 != null) && (node2 != null)) { | |
df0b8ff4 | 918 | if (distanceFromEvent(node1, event) < distanceFromEvent(node2, event)) { |
73005152 | 919 | return node1; |
df0b8ff4 | 920 | } |
abbdd66a | 921 | return node2; |
df0b8ff4 | 922 | } else if (node1 != null) { |
73005152 | 923 | return node1; |
df0b8ff4 | 924 | } else if (node2 != null) { |
73005152 | 925 | return node2; |
a55887ca | 926 | } |
df0b8ff4 | 927 | return null; |
73005152 BH |
928 | } |
929 | ||
df0b8ff4 BH |
930 | /** |
931 | * Get called message based on given start message. | |
a55887ca | 932 | * |
df0b8ff4 BH |
933 | * @param startMessage A start message to check. |
934 | * @return called message (graph node) or <code>null</code> | |
935 | */ | |
936 | public GraphNode getCalledMessage(BaseMessage startMessage) { | |
73005152 BH |
937 | int event = 0; |
938 | GraphNode result = null; | |
939 | Lifeline lifeline = null; | |
df0b8ff4 | 940 | if (startMessage != null) { |
abbdd66a AM |
941 | event = startMessage.getEventOccurrence(); |
942 | lifeline = startMessage.getEndLifeline(); | |
df0b8ff4 | 943 | if (lifeline == null) { |
abbdd66a | 944 | lifeline = startMessage.getStartLifeline(); |
df0b8ff4 | 945 | } |
73005152 | 946 | } |
df0b8ff4 | 947 | if (lifeline == null) { |
73005152 | 948 | return null; |
df0b8ff4 BH |
949 | } |
950 | GraphNode message = getCloserLeavingMessage(lifeline, startMessage, getSyncMessages(), false); | |
951 | GraphNode messageReturn = getCloserLeavingMessage(lifeline, startMessage, getSyncMessagesReturn(), false); | |
73005152 | 952 | result = getCloserToEvent(message, messageReturn, event); |
df0b8ff4 | 953 | message = getCloserLeavingMessage(lifeline, startMessage, getAsyncMessages(), false); |
73005152 | 954 | result = getCloserToEvent(result, message, event); |
df0b8ff4 | 955 | messageReturn = getCloserLeavingMessage(lifeline, startMessage, getAsyncMessagesReturn(), false); |
73005152 BH |
956 | result = getCloserToEvent(result, messageReturn, event); |
957 | return result; | |
958 | } | |
959 | ||
df0b8ff4 BH |
960 | /** |
961 | * Get caller message based on given start message. | |
a55887ca | 962 | * |
df0b8ff4 BH |
963 | * @param startMessage A start message to check. |
964 | * @return called message (graph node) or <code>null</code> | |
965 | */ | |
966 | public GraphNode getCallerMessage(BaseMessage startMessage) { | |
73005152 BH |
967 | int event = getMaxEventOccurrence(); |
968 | GraphNode result = null; | |
969 | Lifeline lifeline = null; | |
df0b8ff4 | 970 | if (startMessage != null) { |
abbdd66a AM |
971 | event = startMessage.getEventOccurrence(); |
972 | lifeline = startMessage.getStartLifeline(); | |
df0b8ff4 | 973 | if (lifeline == null) { |
abbdd66a | 974 | lifeline = startMessage.getEndLifeline(); |
df0b8ff4 | 975 | } |
73005152 | 976 | } |
df0b8ff4 | 977 | if (lifeline == null) { |
73005152 | 978 | return null; |
df0b8ff4 BH |
979 | } |
980 | GraphNode message = getCloserEnteringMessage(lifeline, startMessage, getSyncMessages(), true); | |
981 | GraphNode messageReturn = getCloserEnteringMessage(lifeline, startMessage, getSyncMessagesReturn(), true); | |
73005152 | 982 | result = getCloserToEvent(message, messageReturn, event); |
df0b8ff4 | 983 | message = getCloserEnteringMessage(lifeline, startMessage, getAsyncMessages(), true); |
73005152 | 984 | result = getCloserToEvent(result, message, event); |
df0b8ff4 | 985 | messageReturn = getCloserEnteringMessage(lifeline, startMessage, getAsyncMessagesReturn(), true); |
73005152 BH |
986 | result = getCloserToEvent(result, messageReturn, event); |
987 | return result; | |
988 | } | |
989 | ||
df0b8ff4 BH |
990 | /** |
991 | * Get next lifeline based on given message. | |
a55887ca | 992 | * |
df0b8ff4 BH |
993 | * @param lifeline A lifeline reference |
994 | * @param startMessage A start message to check | |
995 | * @return next lifeline or <code>null</code> | |
996 | */ | |
997 | public GraphNode getNextLifelineMessage(Lifeline lifeline, BaseMessage startMessage) { | |
73005152 | 998 | int event = 0; |
df0b8ff4 | 999 | if (startMessage != null) { |
abbdd66a | 1000 | event = startMessage.getEventOccurrence(); |
df0b8ff4 BH |
1001 | } |
1002 | if (lifeline == null) { | |
73005152 | 1003 | return null; |
df0b8ff4 BH |
1004 | } |
1005 | GraphNode message = getCloserLeavingMessage(lifeline, startMessage, getSyncMessages(), false); | |
1006 | GraphNode messageReturn = getCloserLeavingMessage(lifeline, startMessage, getSyncMessagesReturn(), false); | |
73005152 | 1007 | GraphNode result = getCloserToEvent(message, messageReturn, event); |
df0b8ff4 | 1008 | message = getCloserLeavingMessage(lifeline, startMessage, getAsyncMessages(), false); |
73005152 | 1009 | result = getCloserToEvent(result, message, event); |
df0b8ff4 | 1010 | messageReturn = getCloserLeavingMessage(lifeline, startMessage, getAsyncMessagesReturn(), false); |
73005152 BH |
1011 | result = getCloserToEvent(result, messageReturn, event); |
1012 | return result; | |
1013 | } | |
1014 | ||
df0b8ff4 BH |
1015 | /** |
1016 | * Get previous lifeline based on given message. | |
a55887ca | 1017 | * |
df0b8ff4 BH |
1018 | * @param lifeline A lifeline reference |
1019 | * @param startMessage A start message to check. | |
1020 | * @return previous lifeline or <code>null</code> | |
1021 | */ | |
1022 | public GraphNode getPrevLifelineMessage(Lifeline lifeline, BaseMessage startMessage) { | |
1023 | int event = getMaxEventOccurrence(); | |
a55887ca | 1024 | if (startMessage != null) { |
df0b8ff4 BH |
1025 | if (startMessage instanceof AsyncMessage) { |
1026 | event = ((AsyncMessage) startMessage).getStartOccurrence(); | |
1027 | } else { | |
1028 | event = startMessage.getEventOccurrence(); | |
1029 | } | |
a55887ca | 1030 | } |
df0b8ff4 BH |
1031 | if (lifeline == null) { |
1032 | return null; | |
1033 | } | |
1034 | GraphNode message = getCloserLeavingMessage(lifeline, startMessage, getSyncMessages(), true); | |
1035 | GraphNode messageReturn = getCloserLeavingMessage(lifeline, startMessage, getSyncMessagesReturn(), true); | |
1036 | GraphNode result = getCloserToEvent(message, messageReturn, event); | |
1037 | message = getCloserLeavingMessage(lifeline, startMessage, getAsyncMessages(), true); | |
1038 | result = getCloserToEvent(result, message, event); | |
1039 | messageReturn = getCloserLeavingMessage(lifeline, startMessage, getAsyncMessagesReturn(), true); | |
1040 | result = getCloserToEvent(result, messageReturn, event); | |
1041 | return result; | |
1042 | } | |
a55887ca | 1043 | |
df0b8ff4 BH |
1044 | /** |
1045 | * Get the first execution occurrence. | |
a55887ca | 1046 | * |
df0b8ff4 BH |
1047 | * @param lifeline A lifeline reference |
1048 | * @return the first execution occurrence of lifeline or <code>null</code>. | |
1049 | */ | |
73005152 | 1050 | public BasicExecutionOccurrence getFirstExecution(Lifeline lifeline) { |
df0b8ff4 | 1051 | if (lifeline == null) { |
73005152 | 1052 | return null; |
df0b8ff4 | 1053 | } |
73005152 | 1054 | List<GraphNode> list = lifeline.getExecutions(); |
eb63f5ff BH |
1055 | |
1056 | if ((list == null) || (list.isEmpty())) { | |
73005152 | 1057 | return null; |
df0b8ff4 | 1058 | } |
eb63f5ff | 1059 | |
73005152 BH |
1060 | BasicExecutionOccurrence result = (BasicExecutionOccurrence) list.get(0); |
1061 | for (int i = 0; i < list.size(); i++) { | |
1062 | BasicExecutionOccurrence e = (BasicExecutionOccurrence) list.get(i); | |
df0b8ff4 | 1063 | if ((e.getStartOccurrence() < result.getEndOccurrence())) { |
73005152 | 1064 | result = e; |
df0b8ff4 | 1065 | } |
73005152 BH |
1066 | } |
1067 | return result; | |
1068 | } | |
a55887ca | 1069 | |
df0b8ff4 BH |
1070 | /** |
1071 | * Get the previous execution occurrence relative to a given execution occurrence. | |
a55887ca | 1072 | * |
df0b8ff4 BH |
1073 | * @param exec A execution occurrence reference. |
1074 | * @return the previous execution occurrence of lifeline or <code>null</code>. | |
1075 | */ | |
73005152 | 1076 | public BasicExecutionOccurrence getPrevExecOccurrence(BasicExecutionOccurrence exec) { |
df0b8ff4 | 1077 | if (exec == null) { |
73005152 | 1078 | return null; |
df0b8ff4 | 1079 | } |
73005152 | 1080 | Lifeline lifeline = exec.getLifeline(); |
df0b8ff4 | 1081 | if (lifeline == null) { |
73005152 | 1082 | return null; |
df0b8ff4 | 1083 | } |
73005152 | 1084 | List<GraphNode> list = lifeline.getExecutions(); |
df0b8ff4 | 1085 | if (list == null) { |
73005152 | 1086 | return null; |
df0b8ff4 | 1087 | } |
73005152 BH |
1088 | BasicExecutionOccurrence result = null; |
1089 | for (int i = 0; i < list.size(); i++) { | |
1090 | BasicExecutionOccurrence e = (BasicExecutionOccurrence) list.get(i); | |
eb63f5ff | 1091 | if ((e.getStartOccurrence() < exec.fStartEventOccurrence) && (result == null)) { |
73005152 | 1092 | result = e; |
df0b8ff4 | 1093 | } |
eb63f5ff | 1094 | if ((e.getStartOccurrence() < exec.fStartEventOccurrence) && (e.getStartOccurrence() >= result.getEndOccurrence())) { |
73005152 | 1095 | result = e; |
df0b8ff4 | 1096 | } |
73005152 BH |
1097 | } |
1098 | return result; | |
1099 | } | |
1100 | ||
df0b8ff4 BH |
1101 | /** |
1102 | * Get the next execution occurrence relative to a given execution occurrence. | |
a55887ca | 1103 | * |
df0b8ff4 BH |
1104 | * @param exec A execution occurrence reference. |
1105 | * @return the next execution occurrence of lifeline or <code>null</code>. | |
1106 | */ | |
73005152 | 1107 | public BasicExecutionOccurrence getNextExecOccurrence(BasicExecutionOccurrence exec) { |
df0b8ff4 | 1108 | if (exec == null) { |
73005152 | 1109 | return null; |
df0b8ff4 | 1110 | } |
73005152 | 1111 | Lifeline lifeline = exec.getLifeline(); |
df0b8ff4 | 1112 | if (lifeline == null) { |
73005152 | 1113 | return null; |
df0b8ff4 | 1114 | } |
73005152 | 1115 | List<GraphNode> list = lifeline.getExecutions(); |
df0b8ff4 | 1116 | if (list == null) { |
73005152 | 1117 | return null; |
df0b8ff4 | 1118 | } |
73005152 BH |
1119 | BasicExecutionOccurrence result = null; |
1120 | for (int i = 0; i < list.size(); i++) { | |
1121 | BasicExecutionOccurrence e = (BasicExecutionOccurrence) list.get(i); | |
eb63f5ff | 1122 | if ((e.getStartOccurrence() > exec.fStartEventOccurrence) && (result == null)) { |
73005152 | 1123 | result = e; |
df0b8ff4 | 1124 | } |
eb63f5ff | 1125 | if ((e.getStartOccurrence() > exec.fStartEventOccurrence) && (e.getStartOccurrence() <= result.getEndOccurrence())) { |
73005152 | 1126 | result = e; |
df0b8ff4 | 1127 | } |
73005152 BH |
1128 | } |
1129 | return result; | |
1130 | } | |
1131 | ||
df0b8ff4 BH |
1132 | /** |
1133 | * Get the last execution occurrence. | |
a55887ca | 1134 | * |
df0b8ff4 BH |
1135 | * @param lifeline A lifeline reference. |
1136 | * @return the last execution occurrence of lifeline or <code>null</code>. | |
1137 | */ | |
73005152 | 1138 | public BasicExecutionOccurrence getLastExecOccurrence(Lifeline lifeline) { |
df0b8ff4 | 1139 | if (lifeline == null) { |
73005152 | 1140 | return null; |
df0b8ff4 | 1141 | } |
73005152 | 1142 | List<GraphNode> list = lifeline.getExecutions(); |
df0b8ff4 | 1143 | if (list == null) { |
73005152 | 1144 | return null; |
df0b8ff4 | 1145 | } |
73005152 BH |
1146 | BasicExecutionOccurrence result = null; |
1147 | for (int i = 0; i < list.size(); i++) { | |
1148 | BasicExecutionOccurrence e = (BasicExecutionOccurrence) list.get(i); | |
df0b8ff4 | 1149 | if (result == null) { |
73005152 | 1150 | result = e; |
df0b8ff4 BH |
1151 | } |
1152 | if (e.getStartOccurrence() > result.getEndOccurrence()) { | |
73005152 | 1153 | result = e; |
df0b8ff4 | 1154 | } |
73005152 BH |
1155 | } |
1156 | return result; | |
1157 | } | |
73005152 | 1158 | } |