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