1 /**********************************************************************
2 * Copyright (c) 2005, 2014 IBM Corporation, Ericsson
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
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.core
;
15 import java
.util
.Comparator
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
19 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
20 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.preferences
.ISDPreferences
;
21 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
22 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.uml2sd
.util
.SortSyncMessageComparator
;
25 * A SyncMessage is a synchronous message which appear at the same event occurrence on both lifeline ends (sender and
27 * A Sync message is usually drawn horizontally.<br>
37 * SyncMessage message = new SyncMessage();
38 * // Create a new event occurrence on each lifeline
39 * lifeline1.getNewOccurrenceIndex();
40 * lifeline2.getNewOccurrenceIndex();
41 * // Set the message sender and receiver
42 * message.setStartLifeline(lifeLine1);
43 * message.setEndLifline(lifeline2);
44 * message.setName("Message label");
45 * // add the message to the frame
46 * frame.addMessage(message);
49 * @see org.eclipse.tracecompass.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
54 public class SyncMessage
extends BaseMessage
implements ITimeRange
{
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
62 public static final String SYNC_MESS_TAG
= "SyncMessage"; //$NON-NLS-1$
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
69 * The associated message return
71 private SyncMessageReturn fMessageReturn
;
73 * The time when the message occurs
75 private ITmfTimestamp fEventTime
= new TmfTimestamp();
77 * Flag whether the message has time information available or not
79 private boolean fHasTimeInfo
= false;
81 // ------------------------------------------------------------------------
83 // ------------------------------------------------------------------------
88 public SyncMessage() {
89 setColorPrefId(ISDPreferences
.PREF_SYNC_MESS
);
92 // ------------------------------------------------------------------------
94 // ------------------------------------------------------------------------
97 * Ensure both lifelines have the same event occurrence (the greater found on each lifeline)
99 protected void syncLifelinesEventOccurrence() {
100 if ((getStartLifeline() != null) && (getEndLifeline() != null)) {
102 if (getStartLifeline().getEventOccurrence() > getEndLifeline().getEventOccurrence()) {
103 newIndex
= getStartLifeline().getEventOccurrence();
105 newIndex
= getEndLifeline().getEventOccurrence();
107 getStartLifeline().setCurrentEventOccurrence(newIndex
);
108 getEndLifeline().setCurrentEventOccurrence(newIndex
);
109 setEventOccurrence(getStartLifeline().getEventOccurrence());
114 * Set the lifeLine from which the message has been sent.<br>
115 * A new event occurrence will be created on this lifeLine.<br>
116 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
117 * event occurrence on each lifeline (the greater value will be used).<br>
118 * This synchronization is only done if the end lifeline has already been set.
120 * @param lifeline the message sender
122 public void autoSetStartLifeline(Lifeline lifeline
) {
123 lifeline
.getNewEventOccurrence();
124 setStartLifeline(lifeline
);
128 * Set the lifeLine which has receiver the message.<br>
129 * A new EventOccurence will be create on this lifeLine.<br>
130 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
131 * event occurrence on each lifeline (the greater value will be used).<br>
132 * This synchronization is only done if the start lifeline has already been set.
134 * @param lifeline the message receiver
136 public void autoSetEndLifeline(Lifeline lifeline
) {
137 lifeline
.getNewEventOccurrence();
138 setEndLifeline(lifeline
);
142 * Set the lifeLine which has receiver the message.<br>
143 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
144 * event occurrence on each lifeline (the greater value will be used).<br>
145 * This synchronization is only done if the start lifeline has already been set.
147 * @param lifeline the message receiver
150 public void setStartLifeline(Lifeline lifeline
) {
151 super.setStartLifeline(lifeline
);
152 if ((getEndLifeline() == null)) {
153 setEventOccurrence(getStartLifeline().getEventOccurrence());
155 syncLifelinesEventOccurrence();
160 * Set the lifeLine which has receiver the message.<br>
161 * SyncMessage must occur at the same event occurrence on both lifelines, this method is responsible to synchronize the
162 * event occurrence on each lifeline (the greater value will be used).<br>
163 * This synchronization is only done if the start lifeline has already been set.
165 * @param lifeline the message receiver
168 public void setEndLifeline(Lifeline lifeline
) {
169 super.setEndLifeline(lifeline
);
170 if ((getStartLifeline() == null)) {
171 setEventOccurrence(getEndLifeline().getEventOccurrence());
173 syncLifelinesEventOccurrence();
178 * Set the event occurrence when this message occurs.<br>
180 * @param occurrence the event occurrence to assign to this message.<br>
181 * @see Lifeline Lifeline for more event occurence details
184 protected void setEventOccurrence(int occurrence
) {
185 setStartOccurrence(occurrence
);
186 setEndOccurrence(occurrence
);
190 * Set the message return associated with this message.
192 * @param message the message return to associate
194 protected void setMessageReturn(SyncMessageReturn message
) {
195 fMessageReturn
= message
;
199 * Returns the syncMessageReturn associated to this syncMessage
201 * @return the message return
203 public SyncMessageReturn
getMessageReturn() {
204 return fMessageReturn
;
208 * Set the time when the message occurs
210 * @param time the time when the message occurs
212 public void setTime(ITmfTimestamp time
) {
215 if (getStartLifeline() != null && getStartLifeline().getFrame() != null) {
216 getStartLifeline().getFrame().setHasTimeInfo(true);
217 } else if (getEndLifeline() != null && getEndLifeline().getFrame() != null) {
218 getEndLifeline().getFrame().setHasTimeInfo(true);
223 public ITmfTimestamp
getEndTime() {
228 public ITmfTimestamp
getStartTime() {
233 public boolean hasTimeInfo() {
238 public void draw(IGC context
) {
243 ISDPreferences pref
= SDViewPref
.getInstance();
247 context
.setBackground(pref
.getBackGroundColor(getColorPrefId()));
248 context
.setForeground(pref
.getForeGroundColor(getColorPrefId()));
254 public boolean isVisible(int x
, int y
, int width
, int height
) {
255 if (getY() > y
+ height
+
256 // take into account the message name drawn above the arrow
257 Metrics
.MESSAGES_NAME_SPACING
+ Metrics
.getMessageFontHeigth()) {
261 // UML2 lost/found message visibility special case
262 // Others visibility cases are perform in the ***common*** case
263 if ((getEndLifeline() == null && getStartLifeline() != null) || (getEndLifeline() != null && getStartLifeline() == null)) {
264 if (x
+ width
> getX() + getWidth() && x
< getX() + getWidth()) {
268 // ***Common*** syncMessages visibility
269 return super.isVisible(x
, y
, width
, height
);
273 public Comparator
<GraphNode
> getComparator() {
274 return new SortSyncMessageComparator();
278 public String
getArrayId() {
279 return SYNC_MESS_TAG
;
283 public boolean positiveDistanceToPoint(int x
, int y
) {