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
.timestamp
.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
;
41 @SuppressWarnings("javadoc")
42 public class TestLoaders
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDPagingProvider
, ISelectionListener
{
46 private List
<GraphNode
> findResults
= new ArrayList
<GraphNode
>();
47 private Criteria findCriteria
;
48 private int currentFindIndex
= 0;
50 private Frame savedFrame
= null;
52 public TestLoaders() {
53 this(""); //$NON-NLS-1$
56 @SuppressWarnings("unused")
57 public TestLoaders(String name
) {
62 public void setViewer(SDView j
) {
63 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
65 v
.setSDPagingProvider(this);
66 v
.setSDFindProvider(this);
67 v
.setSDFilterProvider(this);
73 public boolean hasNextPage() {
78 public boolean hasPrevPage() {
83 public void prevPage() {
89 public void nextPage() {
94 @SuppressWarnings("nls")
95 private void createFrame() {
96 Frame testFrame
= new Frame();
98 testFrame
.setName("Sequence Diagram - First Page");
99 LifelineCategories tt
[] = new LifelineCategories
[2];
100 tt
[0] = new LifelineCategories();
101 tt
[1] = new LifelineCategories();
102 tt
[1].setName("Categorie 1");
103 tt
[1].setImage(new LocalImageImpl("obj16/node_obj.gif"));
104 tt
[0].setImage(new LocalImageImpl("obj16/class.gif"));
105 tt
[0].setName("Categorie 0");
106 testFrame
.setLifelineCategories(tt
);
107 Lifeline lifeline
= new Lifeline();
108 lifeline
.setName("LifeLine 0");
109 testFrame
.addLifeLine(lifeline
);
110 EllipsisMessage mn
= new EllipsisMessage();
111 lifeline
.getNewEventOccurrence();
112 mn
.setStartLifeline(lifeline
);
113 mn
.setName("******************* EllipsisisMessage TEST ****************");
114 testFrame
.addMessage(mn
);
115 SyncMessage mn3
= new SyncMessage();
116 mn3
.setStartLifeline(lifeline
);
117 testFrame
.addMessage(mn3
);
118 SyncMessage mn2
= new SyncMessage();
119 lifeline
.getNewEventOccurrence();
120 lifeline
.setCategory(0);
121 mn2
.setEndLifeline(lifeline
);
122 mn2
.setName("*******************Sync TEST ****************");
123 testFrame
.addMessage(mn2
);
124 for (int i
= 1; i
< 300; i
++) {
125 lifeline
= new Lifeline();
126 lifeline
.setName((new StringBuilder("LifeLine ")).append(i
).toString());
127 lifeline
.setCategory(1);
128 testFrame
.addLifeLine(lifeline
);
129 SyncMessage m3
= new SyncMessage();
130 testFrame
.getLifeline(i
- 1).getNewEventOccurrence();
131 m3
.setStartLifeline(testFrame
.getLifeline(i
- 1));
132 m3
.setEndLifeline(testFrame
.getLifeline(i
));
133 m3
.setName((new StringBuilder("Sync Message ")).append(i
).toString());
134 testFrame
.addMessage(m3
);
136 // m3.setTime(new TmfTimestamp(i - 400));
138 // m3.setTime(new TmfTimestamp(i));
140 m3
.setTime(new TmfTimestamp(i
+ 1));
143 for (int i
= testFrame
.lifeLinesCount() - 1; i
> 0; i
--) {
144 SyncMessageReturn m
= new SyncMessageReturn();
145 testFrame
.getLifeline(i
).getNewEventOccurrence();
146 m
.setStartLifeline(testFrame
.getLifeline(i
));
147 m
.setEndLifeline(testFrame
.getLifeline(i
- 1));
148 testFrame
.addMessage(m
);
149 m
.setName((new StringBuilder("Sync Message return ")).append(i
).toString());
150 if (i
+ 1 < testFrame
.lifeLinesCount()) {
151 SyncMessage h
= testFrame
.getSyncMessage(i
+ 1);
156 for (int i
= 0; i
< testFrame
.lifeLinesCount(); i
++) {
158 ExecutionOccurrence occ
= new ExecutionOccurrence();
159 occ
.setStartOccurrence(testFrame
.getSyncMessage(i
).getEventOccurrence() + 1);
160 occ
.setEndOccurrence(testFrame
.getSyncMessageReturn(testFrame
.syncMessageReturnCount() - i
).getEventOccurrence());
161 testFrame
.getLifeline(i
).addExecution(occ
);
162 occ
.setName("******************* Execution Occurance TEST ****************");
167 s
.setLifeline(testFrame
.getLifeline(1));
168 s
.setEventOccurrence(testFrame
.getLifeline(1).getNewEventOccurrence());
169 testFrame
.getLifeline(1).addNode(s
);
170 HotSpot gg
= new HotSpot();
171 gg
.setImage(new LocalImageImpl("obj16/plus_obj.gif"));
172 gg
.setExecution((BasicExecutionOccurrence
) testFrame
.getLifeline(1).getExecutions().get(0));
173 AsyncMessageReturn m
= new AsyncMessageReturn();
174 m
.setStartLifeline(testFrame
.getLifeline(1));
175 m
.setEndLifeline(testFrame
.getLifeline(3));
176 m
.setStartOccurrence(2);
177 m
.setEndOccurrence(6);
178 m
.setStartTime(new TmfTimestamp(2));
179 m
.setEndTime(new TmfTimestamp(6));
180 m
.setName("*******************Async TEST ****************");
181 testFrame
.addMessage(m
);
182 v
.setFrame(testFrame
);
183 v
.getSDWidget().setReorderMode(true);
187 testFrame
.setName("Sequence Diagram");
188 Lifeline lifeline
= new Lifeline();
189 lifeline
.setName("LifeLine 0");
190 testFrame
.addLifeLine(lifeline
);
191 lifeline
= new Lifeline();
192 lifeline
.setName("LifeLine 1");
193 testFrame
.addLifeLine(lifeline
);
194 for (int i
= 1; i
< 30; i
++) {
195 SyncMessage m3
= new SyncMessage();
196 m3
.autoSetStartLifeline(testFrame
.getLifeline(0));
197 m3
.autoSetEndLifeline(testFrame
.getLifeline(0));
198 m3
.setName((new StringBuilder("Message ")).append(i
).toString());
199 testFrame
.addMessage(m3
);
200 SyncMessageReturn m
= new SyncMessageReturn();
201 m
.autoSetStartLifeline(testFrame
.getLifeline(0));
202 m
.autoSetEndLifeline(testFrame
.getLifeline(0));
203 testFrame
.addMessage(m
);
204 m
.setName((new StringBuilder("Message return ")).append(i
).toString());
205 ExecutionOccurrence occ
= new ExecutionOccurrence();
206 occ
.setStartOccurrence(testFrame
.getSyncMessage(i
- 1).getEventOccurrence());
207 occ
.setEndOccurrence(testFrame
.getSyncMessageReturn(i
- 1).getEventOccurrence());
208 testFrame
.getLifeline(0).addExecution(occ
);
211 v
.setFrame(testFrame
);
216 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
219 public boolean find(Criteria toSearch
) {
220 Frame frame
= v
.getFrame();
225 if (findResults
== null || findCriteria
== null || !findCriteria
.compareTo(toSearch
)) {
226 findResults
= new ArrayList
<GraphNode
>();
227 findCriteria
= toSearch
;
228 if (findCriteria
.isLifeLineSelected()) {
229 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
230 if (findCriteria
.matches(frame
.getLifeline(i
).getName())) {
231 findResults
.add(frame
.getLifeline(i
));
236 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
237 if (findCriteria
.isSyncMessageSelected()) {
238 for (int i
= 0; i
< frame
.syncMessageCount(); i
++) {
239 if (findCriteria
.matches(frame
.getSyncMessage(i
).getName())) {
240 msgs
.add(frame
.getSyncMessage(i
));
244 for (int i
= 0; i
< frame
.syncMessageReturnCount(); i
++) {
245 if (findCriteria
.matches(frame
.getSyncMessageReturn(i
).getName())) {
246 msgs
.add(frame
.getSyncMessageReturn(i
));
251 // if(msgs.size() > 0) {
252 // GraphNode temp[] = msgs.toArray(new GraphNode[0]);
253 // Arrays.sort(temp, new DateComparator());
254 // findResults.addAll(Arrays.asList(temp));
257 msgs
= new ArrayList
<GraphNode
>();
258 if (findCriteria
.isAsyncMessageSelected()) {
259 for (int i
= 0; i
< frame
.asyncMessageCount(); i
++) {
260 if (findCriteria
.matches(frame
.getAsyncMessage(i
).getName())) {
261 msgs
.add(frame
.getAsyncMessage(i
));
265 for (int i
= 0; i
< frame
.asyncMessageReturnCount(); i
++) {
266 if (findCriteria
.matches(frame
.getAsyncMessageReturn(i
).getName())) {
267 msgs
.add(frame
.getAsyncMessageReturn(i
));
272 // if(msgs.size() > 0) {
273 // GraphNode temp[] = msgs.toArray(new GraphNode[0]);
274 // Arrays.sort(temp, new DateComparator());
275 // findResults.addAll(Arrays.asList(temp));
278 @SuppressWarnings("rawtypes")
279 List selection
= v
.getSDWidget().getSelection();
280 if (selection
!= null && selection
.size() == 1) {
281 currentFindIndex
= findResults
.indexOf(selection
.get(0)) + 1;
283 currentFindIndex
= 0;
288 if (findResults
.size() > currentFindIndex
) {
289 GraphNode current
= findResults
.get(currentFindIndex
);
290 v
.getSDWidget().moveTo(current
);
293 // return notFoundYet(findCriteria); // search in other page
298 public void cancel() {
301 currentFindIndex
= 0;
304 public boolean isLifelineSupported() {
308 public boolean isSyncMessageSupported() {
312 public boolean isSyncMessageReturnSupported() {
316 public boolean isAsyncMessageSupported() {
320 public boolean isAsyncMessageReturnSupported() {
324 public boolean isStopSupported() {
328 public Action
getFindAction() {
333 public boolean filter(List
<?
> filters
) {
335 if (savedFrame
!= null) {
336 savedFrame
= v
.getFrame();
339 Frame frame
= v
.getFrame();
345 if (filters
.size() != 1) {
349 FilterCriteria filterCriteria
= (FilterCriteria
) filters
.get(0);
351 // One way is to set visiblity of the item, but this only works for messages and not
352 // for lifelines! It's better to create a new frame without the filtered messages.
353 boolean found
= false;
354 if (filterCriteria
.getCriteria().isSyncMessageSelected()) {
355 for (int i
= 0; i
< frame
.syncMessageCount(); i
++) {
356 if (filterCriteria
.getCriteria().matches(frame
.getSyncMessage(i
).getName())) {
357 frame
.getSyncMessage(i
).setVisible(false);
362 for (int i
= 0; i
< frame
.syncMessageReturnCount(); i
++) {
363 if (filterCriteria
.getCriteria().matches(frame
.getSyncMessageReturn(i
).getName())) {
364 frame
.getSyncMessageReturn(i
).setVisible(false);
370 v
.getSDWidget().redraw();
374 public ArrayList
<?
> getCurrentFilters() {
378 @SuppressWarnings("nls")
380 public String
getTitleString() {
381 return "Test Loader";
385 public void dispose() {
390 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
391 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
392 if (sel
!= null && (sel
instanceof StructuredSelection
)) {
393 StructuredSelection stSel
= (StructuredSelection
) sel
;
394 if (stSel
.getFirstElement() instanceof HotSpot
) {
395 // OpenToolBox gg = new OpenToolBox(v);
403 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
406 public boolean isNodeSupported(int nodeType
) {
408 case ISDGraphNodeSupporter
.LIFELINE
:
409 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
410 case ISDGraphNodeSupporter
.SYNCMESSAGERETURN
:
411 case ISDGraphNodeSupporter
.ASYNCMESSAGE
:
412 case ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
:
413 case ISDGraphNodeSupporter
.STOP
:
423 public String
getNodeName(int nodeType
, String loaderClassName
) {
427 public static class LocalImageImpl
implements IImage
{
430 public LocalImageImpl(String file
) {
432 img
= getResourceImage(file
);
435 public LocalImageImpl(Image img_
) {
440 @SuppressWarnings("nls")
441 public Image
getResourceImage(String _name
) {
442 ImageDescriptor imgage
;
444 URL BASIC_URL
= new URL("platform", "localhost", "plugin");
445 URL url
= new URL(BASIC_URL
, (new StringBuilder("plugin/org.eclipse.linuxtools.tmf.ui/icons/")).append(_name
).toString());
446 imgage
= ImageDescriptor
.createFromURL(url
);
447 return imgage
.createImage();
448 } catch (Exception e
) {
449 System
.err
.println(e
);
455 public Object
getImage() {
460 public void dispose() {
469 public void firstPage() {
476 public void lastPage() {