1 /**********************************************************************
2 * Copyright (c) 2005, 2006 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
;
16 import java
.util
.Comparator
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IGC
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.ISDPreferences
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
.SDViewPref
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SortSyncMessageComparator
;
26 * A SyncMessage is a synchronous message which appear at the same event occurrence on both lifeline ends (sender and
28 * A Sync message is usually drawn horizontally.<br>
38 * SyncMessage message = new SyncMessage();
39 * // Create a new event occurrence on each lifeline
40 * lifeline1.getNewOccurrenceIndex();
41 * lifeline2.getNewOccurrenceIndex();
42 * // Set the message sender and receiver
43 * message.setStartLifeline(lifeLine1);
44 * message.setEndLifline(lifeline2);
45 * message.setName("Message label");
46 * // add the message to the frame
47 * frame.addMessage(message);
50 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.Lifeline Lifeline for more event occurence details
55 public class SyncMessage
extends BaseMessage
implements ITimeRange
{
57 // ------------------------------------------------------------------------
59 // ------------------------------------------------------------------------
63 public static final String SYNC_MESS_TAG
= "SyncMessage"; //$NON-NLS-1$
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
70 * The associated message return
72 protected SyncMessageReturn fMessageReturn
;
74 * The time when the message occurs
76 protected ITmfTimestamp fEventTime
= new TmfTimestamp();
78 * Flag whether the message has time information available or not
80 protected boolean fHasTimeInfo
= false;
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
89 public SyncMessage() {
90 fPrefId
= ISDPreferences
.PREF_SYNC_MESS
;
93 // ------------------------------------------------------------------------
95 // ------------------------------------------------------------------------
98 * Ensure both lifelines have the same event occurrence (the greater found on each lifeline)
100 protected void syncLifelinesEventOccurrence() {
101 if ((getStartLifeline() != null) && (getEndLifeline() != null)) {
103 if (getStartLifeline().getEventOccurrence() > getEndLifeline().getEventOccurrence()) {
104 newIndex
= getStartLifeline().getEventOccurrence();
106 newIndex
= getEndLifeline().getEventOccurrence();
108 getStartLifeline().setCurrentEventOccurrence(newIndex
);
109 getEndLifeline().setCurrentEventOccurrence(newIndex
);
110 setEventOccurrence(getStartLifeline().getEventOccurrence());
115 * Set the lifeLine from which the message has been sent.<br>
116 * A new event occurrence will be created on this lifeLine.<br>
117 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
118 * event occurrence on each lifeline (the greater value will be used).<br>
119 * This synchronization is only done if the end lifeline has already been set.
121 * @param lifeline the message sender
123 public void autoSetStartLifeline(Lifeline lifeline
) {
124 lifeline
.getNewEventOccurrence();
125 setStartLifeline(lifeline
);
129 * Set the lifeLine which has receiver the message.<br>
130 * A new EventOccurence will be create on this lifeLine.<br>
131 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
132 * event occurrence on each lifeline (the greater value will be used).<br>
133 * This synchronization is only done if the start lifeline has already been set.
135 * @param lifeline the message receiver
137 public void autoSetEndLifeline(Lifeline lifeline
) {
138 lifeline
.getNewEventOccurrence();
139 setEndLifeline(lifeline
);
143 * Set the lifeLine which has receiver the message.<br>
144 * SyncMessage must occur at the same event occurrence on both lifeline, this method is responsible to synchronize the
145 * event occurrence on each lifeline (the greater value will be used).<br>
146 * This synchronization is only done if the start lifeline has already been set.
148 * @param lifeline the message receiver
151 public void setStartLifeline(Lifeline lifeline
) {
152 super.setStartLifeline(lifeline
);
153 if ((getEndLifeline() == null)) {
154 setEventOccurrence(getStartLifeline().getEventOccurrence());
156 syncLifelinesEventOccurrence();
161 * Set the lifeLine which has receiver the message.<br>
162 * SyncMessage must occur at the same event occurrence on both lifelines, this method is responsible to synchronize the
163 * event occurrence on each lifeline (the greater value will be used).<br>
164 * This synchronization is only done if the start lifeline has already been set.
166 * @param lifeline the message receiver
169 public void setEndLifeline(Lifeline lifeline
) {
170 super.setEndLifeline(lifeline
);
171 if ((getStartLifeline() == null)) {
172 setEventOccurrence(getEndLifeline().getEventOccurrence());
174 syncLifelinesEventOccurrence();
179 * Set the event occurrence when this message occurs.<br>
181 * @param occurrence the event occurrence to assign to this message.<br>
182 * @see Lifeline Lifeline for more event occurence details
185 protected void setEventOccurrence(int occurrence
) {
186 fStartEventOccurrence
= occurrence
;
187 fEndEventOccurrence
= occurrence
;
191 * Set the message return associated with this message.
193 * @param message the message return to associate
195 protected void setMessageReturn(SyncMessageReturn message
) {
196 fMessageReturn
= message
;
200 * Returns the syncMessageReturn associated to this syncMessage
202 * @return the message return
204 public SyncMessageReturn
getMessageReturn() {
205 return fMessageReturn
;
209 * Set the time when the message occurs
211 * @param time the time when the message occurs
214 public void setTime(ITmfTimestamp time
) {
217 if (getStartLifeline() != null && getStartLifeline().getFrame() != null) {
218 getStartLifeline().getFrame().setHasTimeInfo(true);
219 } else if (getEndLifeline() != null && getEndLifeline().getFrame() != null) {
220 getEndLifeline().getFrame().setHasTimeInfo(true);
228 public ITmfTimestamp
getEndTime() {
236 public ITmfTimestamp
getStartTime() {
242 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.ITimeRange#hasTimeInfo()
245 public boolean hasTimeInfo() {
251 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#draw(org.eclipse.linuxtools.tmf.ui.views.uml2sd.drawings.IGC)
254 public void draw(IGC context
) {
259 ISDPreferences pref
= SDViewPref
.getInstance();
263 context
.setBackground(pref
.getBackGroundColor(fPrefId
));
264 context
.setForeground(pref
.getForeGroundColor(fPrefId
));
271 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.BaseMessage#isVisible(int, int, int, int)
274 public boolean isVisible(int x
, int y
, int width
, int height
) {
275 if (getY() > y
+ height
+
276 // take into account the message name drawn above the arrow
277 Metrics
.MESSAGES_NAME_SPACING
+ Metrics
.getMessageFontHeigth()) {
281 // UML2 lost/found message visibility special case
282 // Others visibility cases are perform in the ***common*** case
283 if ((fEndLifeline
== null && fStartLifeline
!= null) || (fEndLifeline
!= null && fStartLifeline
== null)) {
284 if (x
+ width
> getX() + getWidth() && x
< getX() + getWidth()) {
288 // ***Common*** syncMessages visibility
289 return super.isVisible(x
, y
, width
, height
);
294 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getComparator()
297 public Comparator
<GraphNode
> getComparator() {
298 return new SortSyncMessageComparator();
303 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#getArrayId()
306 public String
getArrayId() {
307 return SYNC_MESS_TAG
;
312 * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.core.GraphNode#positiveDistanceToPoint(int, int)
315 public boolean positiveDistanceToPoint(int x
, int y
) {