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 ****************");
165 s
.setLifeline(testFrame
.getLifeline(1));
166 s
.setEventOccurrence(testFrame
.getLifeline(1).getNewEventOccurrence());
167 testFrame
.getLifeline(1).addNode(s
);
168 HotSpot gg
= new HotSpot();
169 gg
.setImage(new LocalImageImpl("obj16/plus_obj.gif"));
170 gg
.setExecution((BasicExecutionOccurrence
) testFrame
.getLifeline(1).getExecutions().get(0));
171 AsyncMessageReturn m
= new AsyncMessageReturn();
172 m
.setStartLifeline(testFrame
.getLifeline(1));
173 m
.setEndLifeline(testFrame
.getLifeline(3));
174 m
.setStartOccurrence(2);
175 m
.setEndOccurrence(6);
176 m
.setStartTime(new TmfTimestamp(2));
177 m
.setEndTime(new TmfTimestamp(6));
178 m
.setName("*******************Async TEST ****************");
179 testFrame
.addMessage(m
);
180 v
.setFrame(testFrame
);
181 v
.getSDWidget().setReorderMode(true);
185 testFrame
.setName("Sequence Diagram");
186 Lifeline lifeline
= new Lifeline();
187 lifeline
.setName("LifeLine 0");
188 testFrame
.addLifeLine(lifeline
);
189 lifeline
= new Lifeline();
190 lifeline
.setName("LifeLine 1");
191 testFrame
.addLifeLine(lifeline
);
192 for (int i
= 1; i
< 30; i
++) {
193 SyncMessage m3
= new SyncMessage();
194 m3
.autoSetStartLifeline(testFrame
.getLifeline(0));
195 m3
.autoSetEndLifeline(testFrame
.getLifeline(0));
196 m3
.setName((new StringBuilder("Message ")).append(i
).toString());
197 testFrame
.addMessage(m3
);
198 SyncMessageReturn m
= new SyncMessageReturn();
199 m
.autoSetStartLifeline(testFrame
.getLifeline(0));
200 m
.autoSetEndLifeline(testFrame
.getLifeline(0));
201 testFrame
.addMessage(m
);
202 m
.setName((new StringBuilder("Message return ")).append(i
).toString());
203 ExecutionOccurrence occ
= new ExecutionOccurrence();
204 occ
.setStartOccurrence(testFrame
.getSyncMessage(i
- 1).getEventOccurrence());
205 occ
.setEndOccurrence(testFrame
.getSyncMessageReturn(i
- 1).getEventOccurrence());
206 testFrame
.getLifeline(0).addExecution(occ
);
209 v
.setFrame(testFrame
);
214 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
217 public boolean find(Criteria toSearch
) {
218 Frame frame
= v
.getFrame();
223 if (findResults
== null || findCriteria
== null || !findCriteria
.compareTo(toSearch
)) {
224 findResults
= new ArrayList
<GraphNode
>();
225 findCriteria
= toSearch
;
226 if (findCriteria
.isLifeLineSelected()) {
227 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
228 if (findCriteria
.matches(frame
.getLifeline(i
).getName())) {
229 findResults
.add(frame
.getLifeline(i
));
234 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
235 if (findCriteria
.isSyncMessageSelected()) {
236 for (int i
= 0; i
< frame
.syncMessageCount(); i
++) {
237 if (findCriteria
.matches(frame
.getSyncMessage(i
).getName())) {
238 msgs
.add(frame
.getSyncMessage(i
));
242 for (int i
= 0; i
< frame
.syncMessageReturnCount(); i
++) {
243 if (findCriteria
.matches(frame
.getSyncMessageReturn(i
).getName())) {
244 msgs
.add(frame
.getSyncMessageReturn(i
));
249 // if(msgs.size() > 0) {
250 // GraphNode temp[] = msgs.toArray(new GraphNode[0]);
251 // Arrays.sort(temp, new DateComparator());
252 // findResults.addAll(Arrays.asList(temp));
255 msgs
= new ArrayList
<GraphNode
>();
256 if (findCriteria
.isAsyncMessageSelected()) {
257 for (int i
= 0; i
< frame
.asyncMessageCount(); i
++) {
258 if (findCriteria
.matches(frame
.getAsyncMessage(i
).getName())) {
259 msgs
.add(frame
.getAsyncMessage(i
));
263 for (int i
= 0; i
< frame
.asyncMessageReturnCount(); i
++) {
264 if (findCriteria
.matches(frame
.getAsyncMessageReturn(i
).getName())) {
265 msgs
.add(frame
.getAsyncMessageReturn(i
));
270 // if(msgs.size() > 0) {
271 // GraphNode temp[] = msgs.toArray(new GraphNode[0]);
272 // Arrays.sort(temp, new DateComparator());
273 // findResults.addAll(Arrays.asList(temp));
276 @SuppressWarnings("rawtypes")
277 List selection
= v
.getSDWidget().getSelection();
278 if (selection
!= null && selection
.size() == 1) {
279 currentFindIndex
= findResults
.indexOf(selection
.get(0)) + 1;
281 currentFindIndex
= 0;
286 if (findResults
.size() > currentFindIndex
) {
287 GraphNode current
= findResults
.get(currentFindIndex
);
288 v
.getSDWidget().moveTo(current
);
291 // return notFoundYet(findCriteria); // search in other page
296 public void cancel() {
299 currentFindIndex
= 0;
302 public boolean isLifelineSupported() {
306 public boolean isSyncMessageSupported() {
310 public boolean isSyncMessageReturnSupported() {
314 public boolean isAsyncMessageSupported() {
318 public boolean isAsyncMessageReturnSupported() {
322 public boolean isStopSupported() {
326 public Action
getFindAction() {
331 public boolean filter(List
<?
> filters
) {
333 if (savedFrame
!= null) {
334 savedFrame
= v
.getFrame();
337 Frame frame
= v
.getFrame();
343 if (filters
.size() != 1) {
347 FilterCriteria filterCriteria
= (FilterCriteria
) filters
.get(0);
349 // One way is to set visiblity of the item, but this only works for messages and not
350 // for lifelines! It's better to create a new frame without the filtered messages.
351 boolean found
= false;
352 if (filterCriteria
.getCriteria().isSyncMessageSelected()) {
353 for (int i
= 0; i
< frame
.syncMessageCount(); i
++) {
354 if (filterCriteria
.getCriteria().matches(frame
.getSyncMessage(i
).getName())) {
355 frame
.getSyncMessage(i
).setVisible(false);
360 for (int i
= 0; i
< frame
.syncMessageReturnCount(); i
++) {
361 if (filterCriteria
.getCriteria().matches(frame
.getSyncMessageReturn(i
).getName())) {
362 frame
.getSyncMessageReturn(i
).setVisible(false);
368 v
.getSDWidget().redraw();
372 public ArrayList
<?
> getCurrentFilters() {
376 @SuppressWarnings("nls")
378 public String
getTitleString() {
379 return "Test Loader";
383 public void dispose() {
388 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
389 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
390 if (sel
!= null && (sel
instanceof StructuredSelection
)) {
391 StructuredSelection stSel
= (StructuredSelection
) sel
;
392 if (stSel
.getFirstElement() instanceof HotSpot
) {
393 // OpenToolBox gg = new OpenToolBox(v);
401 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
404 public boolean isNodeSupported(int nodeType
) {
406 case ISDGraphNodeSupporter
.LIFELINE
:
407 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
408 case ISDGraphNodeSupporter
.SYNCMESSAGERETURN
:
409 case ISDGraphNodeSupporter
.ASYNCMESSAGE
:
410 case ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
:
411 case ISDGraphNodeSupporter
.STOP
:
421 public String
getNodeName(int nodeType
, String loaderClassName
) {
425 public static class LocalImageImpl
implements IImage
{
428 public LocalImageImpl(String file
) {
430 img
= getResourceImage(file
);
433 public LocalImageImpl(Image img_
) {
438 @SuppressWarnings("nls")
439 public Image
getResourceImage(String _name
) {
442 URL BASIC_URL
= new URL("platform", "localhost", "plugin");
443 URL url
= new URL(BASIC_URL
, (new StringBuilder("plugin/org.eclipse.linuxtools.tmf.ui/icons/")).append(_name
).toString());
444 img
= ImageDescriptor
.createFromURL(url
);
445 return img
.createImage();
446 } catch (Exception e
) {
447 System
.err
.println(e
);
453 public Object
getImage() {
458 public void dispose() {
467 public void firstPage() {
474 public void lastPage() {