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