Integrate the TmfEvent+ITmfTimestamp API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / core / SyncMessage.java
CommitLineData
73005152
BH
1/**********************************************************************
2 * Copyright (c) 2005, 2006, 2011 IBM Corporation and others.
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
7 * $Id: SyncMessage.java,v 1.2 2006/09/20 20:56:25 ewchan Exp $
8 *
9 * Contributors:
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.core;
14
15import java.util.Comparator;
16
4df4581d 17import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
6c13869b 18import org.eclipse.linuxtools.tmf.core.event.TmfTimestamp;
73005152
BH
19import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC;
20import org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.ISDPreferences;
21import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SortSyncMessageComparator;
22
23/**
24 * A SyncMessage is a synchronous message which appear at the same event occurrence on both lifeline ends (sender and
25 * receiver).<br>
26 * A Sync message is usually drawn horizontally.<br>
27 * <br>
28 * <br>
29 * Usage example:
30 *
31 * <pre>
32 * Frame frame;
33 * Lifeline lifeLine1;
34 * Lifeline lifeLine2;
35 *
36 * SyncMessage message = new SyncMessage();
37 * // Create a new event occurrence on each lifeline
38 * lifeline1.getNewOccurrenceIndex();
39 * lifeline2.getNewOccurrenceIndex();
40 * // Set the message sender and receiver
41 * message.setStartLifeline(lifeLine1);
42 * message.setEndLifline(lifeline2);
43 * message.setName(&quot;Message label&quot;);
44 * // add the message to the frame
45 * frame.addMessage(message);
46 * </pre>
47 *
48 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
49 * @author sveyrier
50 *
51 */
52public class SyncMessage extends BaseMessage implements ITimeRange {
53
54 /**
55 * The associated message return
56 */
57 protected SyncMessageReturn messageReturn;
58
59 /**
60 * The time when the message occurs
61 */
4df4581d 62 protected ITmfTimestamp eventTime = new TmfTimestamp();
73005152
BH
63
64 public static final String SYNC_MESS_TAG = "SyncMessage"; //$NON-NLS-1$
65
66 protected boolean hasTime = false;
67
68 public SyncMessage() {
69 prefId = ISDPreferences.PREF_SYNC_MESS;
70 }
71
72 /**
73 * Ensure both lifelines have the same event occurrence (the greater found on each lifeline)
74 */
75 protected void syncLifelinesEventOccurrence() {
76 if ((getStartLifeline() != null) && (getEndLifeline() != null)) {
77 int newIndex = 0;
78 if (getStartLifeline().getEventOccurrence() > getEndLifeline().getEventOccurrence())
79 newIndex = getStartLifeline().getEventOccurrence();
80 else
81 newIndex = getEndLifeline().getEventOccurrence();
82 getStartLifeline().setCurrentEventOccurrence(newIndex);
83 getEndLifeline().setCurrentEventOccurrence(newIndex);
84 setEventOccurrence(getStartLifeline().getEventOccurrence());
85 }
86 }
87
88 /**
89 * Set the lifeLine from which the message has been sent.<br>
90 * A new event occurrence will be created on this lifeLine.<br>
91 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
92 * event occurrence on each lifeline (the greater value will be used).<br>
93 * This synchronization is only done if the end lifeline has already been set.
94 *
95 * @param lifeline the message sender
96 */
97 public void autoSetStartLifeline(Lifeline lifeline) {
98 lifeline.getNewEventOccurrence();
99 setStartLifeline(lifeline);
100 }
101
102 /**
103 * Set the lifeLine which has receiver the message.<br>
104 * A new EventOccurence will be create on this lifeLine.<br>
105 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
106 * event occurrence on each lifeline (the greater value will be used).<br>
107 * This synchronization is only done if the start lifeline has already been set.
108 *
109 * @param lifeline the message receiver
110 */
111 public void autoSetEndLifeline(Lifeline lifeline) {
112 lifeline.getNewEventOccurrence();
113 setEndLifeline(lifeline);
114 }
115
116 /**
117 * Set the lifeLine which has receiver the message.<br>
118 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
119 * event occurrence on each lifeline (the greater value will be used).<br>
120 * This synchronization is only done if the start lifeline has already been set.
121 *
122 * @param lifeline the message receiver
123 */
124 @Override
125 public void setStartLifeline(Lifeline lifeline) {
126 super.setStartLifeline(lifeline);
127 if ((getEndLifeline() == null)) {
128 setEventOccurrence(getStartLifeline().getEventOccurrence());
129 } else
130 syncLifelinesEventOccurrence();
131 }
132
133 /**
134 * Set the lifeLine which has receiver the message.<br>
135 * SyncMessage must occur at the same event occurrence on both lifelines, this method is responsible to synchronize the
136 * event occurrence on each lifeline (the greater value will be used).<br>
137 * This synchronization is only done if the start lifeline has already been set.
138 *
139 * @param lifeline the message receiver
140 */
141 @Override
142 public void setEndLifeline(Lifeline lifeline) {
143 super.setEndLifeline(lifeline);
144 if ((getStartLifeline() == null)) {
145 setEventOccurrence(getEndLifeline().getEventOccurrence());
146 } else
147 syncLifelinesEventOccurrence();
148 }
149
150 /**
151 * Set the event occurrence when this message occurs.<br>
152 *
153 * @param occurrence the event occurrence to assign to this message.<br>
154 * @see Lifeline Lifeline for more event occurence details
155 */
156 @Override
157 protected void setEventOccurrence(int occurrence) {
158 startEventOccurrence = occurrence;
159 endEventOccurrence = occurrence;
160 }
161
162 /**
163 * Set the message return associated with this message.
164 *
165 * @param message the message return to associate
166 */
167 protected void setMessageReturn(SyncMessageReturn message) {
168 messageReturn = message;
169 }
170
171 /**
172 * Returns the syncMessageReturn associated to this syncMessage
173 *
174 * @return the message return
175 */
176 public SyncMessageReturn getMessageReturn() {
177 return messageReturn;
178 }
179
180 /**
181 * Set the time when the message occurs
182 *
183 * @param time the time when the message occurs
184 */
4df4581d 185 public void setTime(ITmfTimestamp time) {
73005152
BH
186 eventTime = time.clone();
187 hasTime = true;
188 if (getStartLifeline() != null && getStartLifeline().getFrame() != null)
189 getStartLifeline().getFrame().setHasTimeInfo(true);
190 else if (getEndLifeline() != null && getEndLifeline().getFrame() != null)
191 getEndLifeline().getFrame().setHasTimeInfo(true);
192 }
193
194 /**
195 * Returns the time when the message begin
196 *
197 * @return the time
198 */
199 @Override
4df4581d 200 public ITmfTimestamp getEndTime() {
73005152
BH
201 return eventTime;
202 }
203
204 /**
205 * Returns the time when the message end
206 *
207 * @return the time
208 */
209 @Override
4df4581d 210 public ITmfTimestamp getStartTime() {
73005152
BH
211 return eventTime;
212 }
213
214 @Override
215 public boolean hasTimeInfo() {
216 return hasTime;
217 }
218
219 @Override
220 public void draw(IGC context) {
221 if (!isVisible())
222 return;
223 // Draw it selected?*/
224 if (!isSelected()) {
225 context.setBackground(Frame.getUserPref().getBackGroundColor(prefId));
226 context.setForeground(Frame.getUserPref().getForeGroundColor(prefId));
227 }
228 super.draw(context);
229 }
230
231 @Override
232 public boolean isVisible(int x, int y, int width, int height) {
233 if (getY() > y + height +
234 // take into account the message name drawn above the arrow
235 Metrics.MESSAGES_NAME_SPACING + Metrics.getMessageFontHeigth())
236 return false;
237
238 // UML2 lost/found message visibility special case
239 // Others visibility cases are perform in the ***common*** case
240 if ((endLifeline == null && startLifeline != null) || (endLifeline != null && startLifeline == null)) {
241 if (x + width > getX() + getWidth() && x < getX() + getWidth())
242 return true;
243 }
244 // ***Common*** syncMessages visibility
245 return super.isVisible(x, y, width, height);
246 }
247
248 @Override
249 public Comparator<GraphNode> getComparator() {
250 return new SortSyncMessageComparator();
251 }
252
253 @Override
254 public String getArrayId() {
255 return SYNC_MESS_TAG;
256 }
257
258 @Override
259 public boolean positiveDistanceToPoint(int x, int y) {
260 if (getY() > y)
261 return true;
262 return false;
263 }
264}
This page took 0.035167 seconds and 5 git commands to generate.