1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
9 * Bernd Hufmann - Initial API and implementation
10 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.uml2sd
.load
;
15 import java
.util
.ArrayList
;
16 import java
.util
.List
;
18 import org
.eclipse
.jface
.action
.Action
;
19 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfTimestamp
;
23 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.AsyncMessageReturn
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.BasicExecutionOccurrence
;
26 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.EllipsisMessage
;
27 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.ExecutionOccurrence
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Frame
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.GraphNode
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.HotSpot
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Lifeline
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.LifelineCategories
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.Stop
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessage
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.core
.SyncMessageReturn
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.drawings
.IImage
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFilterProvider
;
40 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDFindProvider
;
41 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDGraphNodeSupporter
;
42 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.provider
.ISDPagingProvider
;
43 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.IUml2SDLoader
;
44 import org
.eclipse
.swt
.graphics
.Image
;
45 import org
.eclipse
.ui
.ISelectionListener
;
46 import org
.eclipse
.ui
.IWorkbenchPart
;
47 import org
.eclipse
.ui
.PlatformUI
;
52 @SuppressWarnings("javadoc")
53 public class TestLoaders
implements IUml2SDLoader
, ISDFindProvider
, ISDFilterProvider
, ISDPagingProvider
, ISelectionListener
{
57 private List
<GraphNode
> findResults
= new ArrayList
<GraphNode
>();
58 private Criteria findCriteria
;
59 private int currentFindIndex
= 0;
61 private Frame savedFrame
= null;
63 public TestLoaders() {
64 this(""); //$NON-NLS-1$
67 @SuppressWarnings("unused")
68 public TestLoaders(String name
) {
73 public void setViewer(SDView j
) {
74 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().addPostSelectionListener(this);
76 v
.setSDPagingProvider(this);
77 v
.setSDFindProvider(this);
78 v
.setSDFilterProvider(this);
84 public boolean hasNextPage() {
89 public boolean hasPrevPage() {
94 public void prevPage() {
100 public void nextPage() {
105 @SuppressWarnings("nls")
106 private void createFrame() {
107 Frame testFrame
= new Frame();
109 testFrame
.setName("Sequence Diagram - First Page");
110 LifelineCategories tt
[] = new LifelineCategories
[2];
111 tt
[0] = new LifelineCategories();
112 tt
[1] = new LifelineCategories();
113 tt
[1].setName("Categorie 1");
114 tt
[1].setImage(new LocalImageImpl("obj16/node_obj.gif"));
115 tt
[0].setImage(new LocalImageImpl("obj16/class.gif"));
116 tt
[0].setName("Categorie 0");
117 testFrame
.setLifelineCategories(tt
);
118 Lifeline lifeline
= new Lifeline();
119 lifeline
.setName("LifeLine 0");
120 testFrame
.addLifeLine(lifeline
);
121 EllipsisMessage mn
= new EllipsisMessage();
122 lifeline
.getNewEventOccurrence();
123 mn
.setStartLifeline(lifeline
);
124 mn
.setName("******************* EllipsisisMessage TEST ****************");
125 testFrame
.addMessage(mn
);
126 SyncMessage mn3
= new SyncMessage();
127 mn3
.setStartLifeline(lifeline
);
128 testFrame
.addMessage(mn3
);
129 SyncMessage mn2
= new SyncMessage();
130 lifeline
.getNewEventOccurrence();
131 lifeline
.setCategory(0);
132 mn2
.setEndLifeline(lifeline
);
133 mn2
.setName("*******************Sync TEST ****************");
134 testFrame
.addMessage(mn2
);
135 for (int i
= 1; i
< 300; i
++) {
136 lifeline
= new Lifeline();
137 lifeline
.setName((new StringBuilder("LifeLine ")).append(i
).toString());
138 lifeline
.setCategory(1);
139 testFrame
.addLifeLine(lifeline
);
140 SyncMessage m3
= new SyncMessage();
141 testFrame
.getLifeline(i
- 1).getNewEventOccurrence();
142 m3
.setStartLifeline(testFrame
.getLifeline(i
- 1));
143 m3
.setEndLifeline(testFrame
.getLifeline(i
));
144 m3
.setName((new StringBuilder("Sync Message ")).append(i
).toString());
145 testFrame
.addMessage(m3
);
147 // m3.setTime(new TmfTimestamp(i - 400));
149 // m3.setTime(new TmfTimestamp(i));
151 m3
.setTime(new TmfTimestamp(i
+ 1));
154 for (int i
= testFrame
.lifeLinesCount() - 1; i
> 0; i
--) {
155 SyncMessageReturn m
= new SyncMessageReturn();
156 testFrame
.getLifeline(i
).getNewEventOccurrence();
157 m
.setStartLifeline(testFrame
.getLifeline(i
));
158 m
.setEndLifeline(testFrame
.getLifeline(i
- 1));
159 testFrame
.addMessage(m
);
160 m
.setName((new StringBuilder("Sync Message return ")).append(i
).toString());
161 if (i
+ 1 < testFrame
.lifeLinesCount()) {
162 SyncMessage h
= testFrame
.getSyncMessage(i
+ 1);
167 for (int i
= 0; i
< testFrame
.lifeLinesCount(); i
++) {
169 ExecutionOccurrence occ
= new ExecutionOccurrence();
170 occ
.setStartOccurrence(testFrame
.getSyncMessage(i
).getEventOccurrence() + 1);
171 occ
.setEndOccurrence(testFrame
.getSyncMessageReturn(testFrame
.syncMessageReturnCount() - i
).getEventOccurrence());
172 testFrame
.getLifeline(i
).addExecution(occ
);
173 occ
.setName("******************* Execution Occurance TEST ****************");
178 s
.setLifeline(testFrame
.getLifeline(1));
179 s
.setEventOccurrence(testFrame
.getLifeline(1).getNewEventOccurrence());
180 testFrame
.getLifeline(1).addNode(s
);
181 HotSpot gg
= new HotSpot();
182 gg
.setImage(new LocalImageImpl("obj16/plus_obj.gif"));
183 gg
.setExecution((BasicExecutionOccurrence
) testFrame
.getLifeline(1).getExecutions().get(0));
184 AsyncMessageReturn m
= new AsyncMessageReturn();
185 m
.setStartLifeline(testFrame
.getLifeline(1));
186 m
.setEndLifeline(testFrame
.getLifeline(3));
187 m
.setStartOccurrence(2);
188 m
.setEndOccurrence(6);
189 m
.setStartTime(new TmfTimestamp(2));
190 m
.setEndTime(new TmfTimestamp(6));
191 m
.setName("*******************Async TEST ****************");
192 testFrame
.addMessage(m
);
193 v
.setFrame(testFrame
);
194 v
.getSDWidget().setReorderMode(true);
198 testFrame
.setName("Sequence Diagram");
199 Lifeline lifeline
= new Lifeline();
200 lifeline
.setName("LifeLine 0");
201 testFrame
.addLifeLine(lifeline
);
202 lifeline
= new Lifeline();
203 lifeline
.setName("LifeLine 1");
204 testFrame
.addLifeLine(lifeline
);
205 for (int i
= 1; i
< 30; i
++) {
206 SyncMessage m3
= new SyncMessage();
207 m3
.autoSetStartLifeline(testFrame
.getLifeline(0));
208 m3
.autoSetEndLifeline(testFrame
.getLifeline(0));
209 m3
.setName((new StringBuilder("Message ")).append(i
).toString());
210 testFrame
.addMessage(m3
);
211 SyncMessageReturn m
= new SyncMessageReturn();
212 m
.autoSetStartLifeline(testFrame
.getLifeline(0));
213 m
.autoSetEndLifeline(testFrame
.getLifeline(0));
214 testFrame
.addMessage(m
);
215 m
.setName((new StringBuilder("Message return ")).append(i
).toString());
216 ExecutionOccurrence occ
= new ExecutionOccurrence();
217 occ
.setStartOccurrence(testFrame
.getSyncMessage(i
- 1).getEventOccurrence());
218 occ
.setEndOccurrence(testFrame
.getSyncMessageReturn(i
- 1).getEventOccurrence());
219 testFrame
.getLifeline(0).addExecution(occ
);
222 v
.setFrame(testFrame
);
227 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDFindProvider#find(org.eclipse.hyades.uml2sd.ui.actions.widgets.Criteria)
230 public boolean find(Criteria toSearch
) {
231 Frame frame
= v
.getFrame();
236 if (findResults
== null || findCriteria
== null || !findCriteria
.compareTo(toSearch
)) {
237 findResults
= new ArrayList
<GraphNode
>();
238 findCriteria
= toSearch
;
239 if (findCriteria
.isLifeLineSelected()) {
240 for (int i
= 0; i
< frame
.lifeLinesCount(); i
++) {
241 if (findCriteria
.matches(frame
.getLifeline(i
).getName())) {
242 findResults
.add(frame
.getLifeline(i
));
247 ArrayList
<GraphNode
> msgs
= new ArrayList
<GraphNode
>();
248 if (findCriteria
.isSyncMessageSelected()) {
249 for (int i
= 0; i
< frame
.syncMessageCount(); i
++) {
250 if (findCriteria
.matches(frame
.getSyncMessage(i
).getName())) {
251 msgs
.add(frame
.getSyncMessage(i
));
255 for (int i
= 0; i
< frame
.syncMessageReturnCount(); i
++) {
256 if (findCriteria
.matches(frame
.getSyncMessageReturn(i
).getName())) {
257 msgs
.add(frame
.getSyncMessageReturn(i
));
262 // if(msgs.size() > 0) {
263 // GraphNode temp[] = msgs.toArray(new GraphNode[0]);
264 // Arrays.sort(temp, new DateComparator());
265 // findResults.addAll(Arrays.asList(temp));
268 msgs
= new ArrayList
<GraphNode
>();
269 if (findCriteria
.isAsyncMessageSelected()) {
270 for (int i
= 0; i
< frame
.asyncMessageCount(); i
++) {
271 if (findCriteria
.matches(frame
.getAsyncMessage(i
).getName())) {
272 msgs
.add(frame
.getAsyncMessage(i
));
276 for (int i
= 0; i
< frame
.asyncMessageReturnCount(); i
++) {
277 if (findCriteria
.matches(frame
.getAsyncMessageReturn(i
).getName())) {
278 msgs
.add(frame
.getAsyncMessageReturn(i
));
283 // if(msgs.size() > 0) {
284 // GraphNode temp[] = msgs.toArray(new GraphNode[0]);
285 // Arrays.sort(temp, new DateComparator());
286 // findResults.addAll(Arrays.asList(temp));
289 @SuppressWarnings("rawtypes")
290 List selection
= v
.getSDWidget().getSelection();
291 if (selection
!= null && selection
.size() == 1) {
292 currentFindIndex
= findResults
.indexOf(selection
.get(0)) + 1;
294 currentFindIndex
= 0;
299 if (findResults
.size() > currentFindIndex
) {
300 GraphNode current
= findResults
.get(currentFindIndex
);
301 v
.getSDWidget().moveTo(current
);
304 // return notFoundYet(findCriteria); // search in other page
309 public void cancel() {
312 currentFindIndex
= 0;
315 public boolean isLifelineSupported() {
319 public boolean isSyncMessageSupported() {
323 public boolean isSyncMessageReturnSupported() {
327 public boolean isAsyncMessageSupported() {
331 public boolean isAsyncMessageReturnSupported() {
335 public boolean isStopSupported() {
339 public Action
getFindAction() {
344 public boolean filter(List
<?
> filters
) {
346 if (savedFrame
!= null) {
347 savedFrame
= v
.getFrame();
350 Frame frame
= v
.getFrame();
356 if (filters
.size() != 1) {
360 FilterCriteria filterCriteria
= (FilterCriteria
) filters
.get(0);
362 // One way is to set visiblity of the item, but this only works for messages and not
363 // for lifelines! It's better to create a new frame without the filtered messages.
364 boolean found
= false;
365 if (filterCriteria
.getCriteria().isSyncMessageSelected()) {
366 for (int i
= 0; i
< frame
.syncMessageCount(); i
++) {
367 if (filterCriteria
.getCriteria().matches(frame
.getSyncMessage(i
).getName())) {
368 frame
.getSyncMessage(i
).setVisible(false);
373 for (int i
= 0; i
< frame
.syncMessageReturnCount(); i
++) {
374 if (filterCriteria
.getCriteria().matches(frame
.getSyncMessageReturn(i
).getName())) {
375 frame
.getSyncMessageReturn(i
).setVisible(false);
381 v
.getSDWidget().redraw();
385 public ArrayList
<?
> getCurrentFilters() {
389 @SuppressWarnings("nls")
391 public String
getTitleString() {
392 return "Test Loader";
396 public void dispose() {
401 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
402 ISelection sel
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
403 if (sel
!= null && (sel
instanceof StructuredSelection
)) {
404 StructuredSelection stSel
= (StructuredSelection
) sel
;
405 if (stSel
.getFirstElement() instanceof HotSpot
) {
406 // OpenToolBox gg = new OpenToolBox(v);
414 * @see org.eclipse.hyades.uml2sd.ui.actions.provider.ISDGraphNodeSupporter#isNodeSupported(int)
417 public boolean isNodeSupported(int nodeType
) {
419 case ISDGraphNodeSupporter
.LIFELINE
:
420 case ISDGraphNodeSupporter
.SYNCMESSAGE
:
421 case ISDGraphNodeSupporter
.SYNCMESSAGERETURN
:
422 case ISDGraphNodeSupporter
.ASYNCMESSAGE
:
423 case ISDGraphNodeSupporter
.ASYNCMESSAGERETURN
:
424 case ISDGraphNodeSupporter
.STOP
:
434 public String
getNodeName(int nodeType
, String loaderClassName
) {
438 public static class LocalImageImpl
implements IImage
{
441 public LocalImageImpl(String file
) {
443 img
= getResourceImage(file
);
446 public LocalImageImpl(Image img_
) {
451 @SuppressWarnings("nls")
452 public Image
getResourceImage(String _name
) {
453 ImageDescriptor imgage
;
455 URL BASIC_URL
= new URL("platform", "localhost", "plugin");
456 URL url
= new URL(BASIC_URL
, (new StringBuilder("plugin/org.eclipse.linuxtools.tmf.ui/icons/")).append(_name
).toString());
457 imgage
= ImageDescriptor
.createFromURL(url
);
458 return imgage
.createImage();
459 } catch (Exception e
) {
460 System
.err
.println(e
);
466 public Object
getImage() {
471 public void dispose() {
480 public void firstPage() {
487 public void lastPage() {