1 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.uml2sd
.load
;
4 import java
.util
.ArrayList
;
7 import org
.eclipse
.jface
.action
.Action
;
8 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
9 import org
.eclipse
.jface
.viewers
.ISelection
;
10 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
11 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
12 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
13 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessageReturn
;
14 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BasicExecutionOccurrence
;
15 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.EllipsisMessage
;
16 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.ExecutionOccurrence
;
17 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
18 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
19 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.HotSpot
;
20 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
21 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.LifelineCategories
;
22 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Stop
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessage
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessageReturn
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IImage
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFilterProvider
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFindProvider
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDPagingProvider
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.IUml2SDLoader
;
33 import org
.eclipse
.swt
.graphics
.Image
;
34 import org
.eclipse
.ui
.ISelectionListener
;
35 import org
.eclipse
.ui
.IWorkbenchPart
;
36 import org
.eclipse
.ui
.PlatformUI
;
38 // Referenced classes of package org.eclipse.hyades.uml2sd.ztest:
41 public class TestLoaders
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDPagingProvider
, ISelectionListener
{
45 private List
<GraphNode
> findResults
= new ArrayList
<GraphNode
>();
46 private Criteria findCriteria
;
47 private int currentFindIndex
= 0;
49 private Frame savedFrame
= null;
51 public TestLoaders() {
52 this(""); //$NON-NLS-1$
55 public TestLoaders(String name
) {
60 public void setViewer(SDView j
) {
61 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
63 v
.setSDPagingProvider(this);
64 v
.setSDFindProvider(this);
65 v
.setSDFilterProvider(this);
71 public boolean hasNextPage() {
76 public boolean hasPrevPage() {
81 public void prevPage() {
87 public void nextPage() {
92 @SuppressWarnings("nls")
93 private void createFrame() {
94 Frame testFrame
= new Frame();
96 testFrame
.setName("Sequence Diagram - First Page");
97 LifelineCategories tt
[] = new LifelineCategories
[2];
98 tt
[0] = new LifelineCategories();
99 tt
[1] = new LifelineCategories();
100 tt
[1].setName("Categorie 1");
101 tt
[1].setImage(new LocalImageImpl("obj16/node_obj.gif"));
102 tt
[0].setImage(new LocalImageImpl("obj16/class.gif"));
103 tt
[0].setName("Categorie 0");
104 testFrame
.setLifelineCategories(tt
);
105 Lifeline lifeline
= new Lifeline();
106 lifeline
.setName("LifeLine 0");
107 testFrame
.addLifeLine(lifeline
);
108 EllipsisMessage mn
= new EllipsisMessage();
109 lifeline
.getNewEventOccurrence();
110 mn
.setStartLifeline(lifeline
);
111 mn
.setName("******************* EllipsisisMessage TEST ****************");
112 testFrame
.addMessage(mn
);
113 SyncMessage mn3
= new SyncMessage();
114 mn3
.setStartLifeline(lifeline
);
115 testFrame
.addMessage(mn3
);
116 SyncMessage mn2
= new SyncMessage();
117 lifeline
.getNewEventOccurrence();
118 lifeline
.setCategory(0);
119 mn2
.setEndLifeline(lifeline
);
120 mn2
.setName("*******************Sync TEST ****************");
121 testFrame
.addMessage(mn2
);
122 for (int i
= 1; i
< 300; i
++) {
123 lifeline
= new Lifeline();
124 lifeline
.setName((new StringBuilder("LifeLine ")).append(i
).toString());
125 lifeline
.setCategory(1);
126 testFrame
.addLifeLine(lifeline
);
127 SyncMessage m3
= new SyncMessage();
128 testFrame
.getLifeline(i
- 1).getNewEventOccurrence();
129 m3
.setStartLifeline(testFrame
.getLifeline(i
- 1));
130 m3
.setEndLifeline(testFrame
.getLifeline(i
));
131 m3
.setName((new StringBuilder("Sync Message ")).append(i
).toString());
132 testFrame
.addMessage(m3
);
134 // m3.setTime(new TmfTimestamp(i - 400));
136 // m3.setTime(new TmfTimestamp(i));
138 m3
.setTime(new TmfTimestamp(i
+ 1));
141 for (int i
= testFrame
.lifeLinesCount() - 1; i
> 0; i
--) {
142 SyncMessageReturn m
= new SyncMessageReturn();
143 testFrame
.getLifeline(i
).getNewEventOccurrence();
144 m
.setStartLifeline(testFrame
.getLifeline(i
));
145 m
.setEndLifeline(testFrame
.getLifeline(i
- 1));
146 testFrame
.addMessage(m
);
147 m
.setName((new StringBuilder("Sync Message return ")).append(i
).toString());
148 if (i
+ 1 < testFrame
.lifeLinesCount()) {
149 SyncMessage h
= testFrame
.getSyncMessage(i
+ 1);
154 for (int i
= 0; i
< testFrame
.lifeLinesCount(); i
++)
156 ExecutionOccurrence occ
= new ExecutionOccurrence();
157 occ
.setStartOccurrence(testFrame
.getSyncMessage(i
).getEventOccurrence() + 1);
158 occ
.setEndOccurrence(testFrame
.getSyncMessageReturn(testFrame
.syncMessageReturnCount() - i
).getEventOccurrence());
159 testFrame
.getLifeline(i
).addExecution(occ
);
160 occ
.setName("******************* Execution Occurance TEST ****************");
164 s
.setLifeline(testFrame
.getLifeline(1));
165 s
.setEventOccurrence(testFrame
.getLifeline(1).getNewEventOccurrence());
166 testFrame
.getLifeline(1).addNode(s
);
167 HotSpot gg
= new HotSpot();
168 gg
.setImage(new LocalImageImpl("obj16/plus_obj.gif"));
169 gg
.setExecution((BasicExecutionOccurrence
) testFrame
.getLifeline(1).getExecutions().get(0));
170 AsyncMessageReturn m
= new AsyncMessageReturn();
171 m
.setStartLifeline(testFrame
.getLifeline(1));
172 m
.setEndLifeline(testFrame
.getLifeline(3));
173 m
.setStartOccurrence(2);
174 m
.setEndOccurrence(6);
175 m
.setStartTime(new TmfTimestamp(2));
176 m
.setEndTime(new TmfTimestamp(6));
177 m
.setName("*******************Async TEST ****************");
178 testFrame
.addMessage(m
);
179 v
.setFrame(testFrame
);
180 v
.getSDWidget().setReorderMode(true);
184 testFrame
.setName("Sequence Diagram");
185 Lifeline lifeline
= new Lifeline();
186 lifeline
.setName("LifeLine 0");
187 testFrame
.addLifeLine(lifeline
);
188 lifeline
= new Lifeline();
189 lifeline
.setName("LifeLine 1");
190 testFrame
.addLifeLine(lifeline
);
191 for (int i
= 1; i
< 30; i
++) {
192 SyncMessage m3
= new SyncMessage();
193 m3
.autoSetStartLifeline(testFrame
.getLifeline(0));
194 m3
.autoSetEndLifeline(testFrame
.getLifeline(0));
195 m3
.setName((new StringBuilder("Message ")).append(i
).toString());
196 testFrame
.addMessage(m3
);
197 SyncMessageReturn m
= new SyncMessageReturn();
198 m
.autoSetStartLifeline(testFrame
.getLifeline(0));
199 m
.autoSetEndLifeline(testFrame
.getLifeline(0));
200 testFrame
.addMessage(m
);
201 m
.setName((new StringBuilder("Message return ")).append(i
).toString());
202 ExecutionOccurrence occ
= new ExecutionOccurrence();
203 occ
.setStartOccurrence(testFrame
.getSyncMessage(i
- 1).getEventOccurrence());
204 occ
.setEndOccurrence(testFrame
.getSyncMessageReturn(i
- 1).getEventOccurrence());
205 testFrame
.getLifeline(0).addExecution(occ
);
208 v
.setFrame(testFrame
);
213 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
216 public boolean find(Criteria toSearch
) {
217 Frame frame
= v
.getFrame();
221 if (findResults
== null || findCriteria
== null || !findCriteria
.compareTo(toSearch
)) {
222 findResults
= new ArrayList
<GraphNode
>();
223 findCriteria
= toSearch
;
224 if (findCriteria
.isLifeLineSelected()) {
225 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
226 if (findCriteria
.matches(frame
.getLifeline(i
).getName()))
227 findResults
.add(frame
.getLifeline(i
));
231 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
232 if (findCriteria
.isSyncMessageSelected()) {
233 for (int i
= 0; i
< frame
.syncMessageCount(); i
++) {
234 if (findCriteria
.matches(frame
.getSyncMessage(i
).getName()))
235 msgs
.add(frame
.getSyncMessage(i
));
238 for (int i
= 0; i
< frame
.syncMessageReturnCount(); i
++)
239 if (findCriteria
.matches(frame
.getSyncMessageReturn(i
).getName()))
240 msgs
.add(frame
.getSyncMessageReturn(i
));
243 // if(msgs.size() > 0) {
244 // GraphNode temp[] = msgs.toArray(new GraphNode[0]);
245 // Arrays.sort(temp, new DateComparator());
246 // findResults.addAll(Arrays.asList(temp));
249 msgs
= new ArrayList
<GraphNode
>();
250 if (findCriteria
.isAsyncMessageSelected()) {
251 for (int i
= 0; i
< frame
.asyncMessageCount(); i
++)
252 if (findCriteria
.matches(frame
.getAsyncMessage(i
).getName()))
253 msgs
.add(frame
.getAsyncMessage(i
));
255 for (int i
= 0; i
< frame
.asyncMessageReturnCount(); i
++)
256 if (findCriteria
.matches(frame
.getAsyncMessageReturn(i
).getName()))
257 msgs
.add(frame
.getAsyncMessageReturn(i
));
260 // if(msgs.size() > 0) {
261 // GraphNode temp[] = msgs.toArray(new GraphNode[0]);
262 // Arrays.sort(temp, new DateComparator());
263 // findResults.addAll(Arrays.asList(temp));
266 @SuppressWarnings("rawtypes")
267 List selection
= v
.getSDWidget().getSelection();
268 if (selection
!= null && selection
.size() == 1)
269 currentFindIndex
= findResults
.indexOf(selection
.get(0)) + 1;
271 currentFindIndex
= 0;
275 if (findResults
.size() > currentFindIndex
) {
276 GraphNode current
= (GraphNode
) findResults
.get(currentFindIndex
);
277 v
.getSDWidget().moveTo(current
);
280 // return notFoundYet(findCriteria); // search in other page
287 public void cancel() {
290 currentFindIndex
= 0;
293 public boolean isLifelineSupported() {
297 public boolean isSyncMessageSupported() {
301 public boolean isSyncMessageReturnSupported() {
305 public boolean isAsyncMessageSupported() {
309 public boolean isAsyncMessageReturnSupported() {
313 public boolean isStopSupported() {
317 public Action
getFindAction() {
322 public boolean filter(List
<?
> filters
) {
324 if (savedFrame
!= null) {
325 savedFrame
= v
.getFrame();
328 Frame frame
= v
.getFrame();
334 if (filters
.size() != 1) {
338 FilterCriteria filterCriteria
= (FilterCriteria
) filters
.get(0);
340 // One way is to set visiblity of the item, but this only works for messages and not
341 // for lifelines! It's better to create a new frame without the filtered messages.
342 boolean found
= false;
343 if (filterCriteria
.getCriteria().isSyncMessageSelected()) {
344 for (int i
= 0; i
< frame
.syncMessageCount(); i
++) {
345 if (filterCriteria
.getCriteria().matches(frame
.getSyncMessage(i
).getName())) {
346 frame
.getSyncMessage(i
).setVisible(false);
351 for (int i
= 0; i
< frame
.syncMessageReturnCount(); i
++)
352 if (filterCriteria
.getCriteria().matches(frame
.getSyncMessageReturn(i
).getName())) {
353 frame
.getSyncMessageReturn(i
).setVisible(false);
358 v
.getSDWidget().redraw();
362 public ArrayList
<?
> getCurrentFilters() {
366 @SuppressWarnings("nls")
368 public String
getTitleString() {
369 return "Test Loader";
373 public void dispose() {
378 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
379 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
380 if (sel
!= null && (sel
instanceof StructuredSelection
)) {
381 StructuredSelection stSel
= (StructuredSelection
) sel
;
382 if (stSel
.getFirstElement() instanceof HotSpot
) {
383 // OpenToolBox gg = new OpenToolBox(v);
391 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
394 public boolean isNodeSupported(int nodeType
) {
396 case ISDGraphNodeSupporter
.LIFELINE
:
397 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
398 case ISDGraphNodeSupporter
.SYNCMESSAGERETURN
:
399 case ISDGraphNodeSupporter
.ASYNCMESSAGE
:
400 case ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
:
401 case ISDGraphNodeSupporter
.STOP
:
411 public String
getNodeName(int nodeType
, String loaderClassName
) {
415 public static class LocalImageImpl
implements IImage
{
418 public LocalImageImpl(String file
) {
420 img
= getResourceImage(file
);
423 public LocalImageImpl(Image img_
) {
428 @SuppressWarnings("nls")
429 public Image
getResourceImage(String _name
) {
432 URL BASIC_URL
= new URL("platform", "localhost", "plugin");
433 URL url
= new URL(BASIC_URL
, (new StringBuilder("plugin/org.eclipse.linuxtools.tmf.ui/icons/")).append(_name
).toString());
434 img
= ImageDescriptor
.createFromURL(url
);
435 return img
.createImage();
436 } catch (Exception e
) {
437 System
.err
.println(e
);
443 public Object
getImage() {
448 public void dispose() {
456 public void firstPage() {
463 public void lastPage() {