Method: updateView(IVdmProject)

1: /*
2: * #%~
3: * Combinatorial Testing
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.plugins.combinatorialtesting.views;
23:
24: import java.io.File;
25: import java.util.concurrent.CancellationException;
26:
27: import org.eclipse.core.resources.IFile;
28: import org.eclipse.core.resources.IProject;
29: import org.eclipse.core.resources.IResource;
30: import org.eclipse.core.runtime.CoreException;
31: import org.eclipse.core.runtime.IProgressMonitor;
32: import org.eclipse.core.runtime.IStatus;
33: import org.eclipse.core.runtime.Status;
34: import org.eclipse.core.runtime.jobs.Job;
35: import org.eclipse.jface.action.Action;
36: import org.eclipse.jface.action.IMenuListener;
37: import org.eclipse.jface.action.IMenuManager;
38: import org.eclipse.jface.action.IToolBarManager;
39: import org.eclipse.jface.action.MenuManager;
40: import org.eclipse.jface.action.Separator;
41: import org.eclipse.jface.resource.ImageDescriptor;
42: import org.eclipse.jface.viewers.ISelection;
43: import org.eclipse.jface.viewers.ISelectionChangedListener;
44: import org.eclipse.jface.viewers.IStructuredSelection;
45: import org.eclipse.jface.viewers.ITreeSelection;
46: import org.eclipse.jface.viewers.ITreeViewerListener;
47: import org.eclipse.jface.viewers.SelectionChangedEvent;
48: import org.eclipse.jface.viewers.TreeExpansionEvent;
49: import org.eclipse.jface.viewers.TreeViewer;
50: import org.eclipse.jface.viewers.ViewerFilter;
51: import org.eclipse.jface.viewers.ViewerSorter;
52: import org.eclipse.swt.SWT;
53: import org.eclipse.swt.graphics.Image;
54: import org.eclipse.swt.graphics.Point;
55: import org.eclipse.swt.widgets.Button;
56: import org.eclipse.swt.widgets.Composite;
57: import org.eclipse.swt.widgets.Display;
58: import org.eclipse.swt.widgets.Menu;
59: import org.eclipse.swt.widgets.Shell;
60: import org.eclipse.swt.widgets.TreeItem;
61: import org.eclipse.ui.IActionBars;
62: import org.eclipse.ui.IPageLayout;
63: import org.eclipse.ui.IViewPart;
64: import org.eclipse.ui.IWorkbenchActionConstants;
65: import org.eclipse.ui.IWorkbenchPage;
66: import org.eclipse.ui.IWorkbenchWindow;
67: import org.eclipse.ui.PartInitException;
68: import org.eclipse.ui.PlatformUI;
69: import org.eclipse.ui.console.ConsolePlugin;
70: import org.eclipse.ui.console.IConsole;
71: import org.eclipse.ui.console.IConsoleConstants;
72: import org.eclipse.ui.console.IConsoleManager;
73: import org.eclipse.ui.console.MessageConsole;
74: import org.eclipse.ui.console.MessageConsoleStream;
75: import org.eclipse.ui.part.ViewPart;
76: import org.eclipse.ui.plugin.AbstractUIPlugin;
77: import org.overture.ast.definitions.ANamedTraceDefinition;
78: import org.overture.ast.definitions.SClassDefinition;
79: import org.overture.ast.modules.AModuleModules;
80: import org.overture.ast.node.INode;
81: import org.overture.ide.core.IVdmModel;
82: import org.overture.ide.core.resources.IVdmProject;
83: import org.overture.ide.plugins.combinatorialtesting.ITracesConstants;
84: import org.overture.ide.plugins.combinatorialtesting.OvertureTracesPlugin;
85: import org.overture.ide.plugins.combinatorialtesting.debug.TraceDebugLauncher;
86: import org.overture.ide.plugins.combinatorialtesting.internal.ITracesDisplay;
87: import org.overture.ide.plugins.combinatorialtesting.internal.VdmjTracesHelper;
88: import org.overture.ide.plugins.combinatorialtesting.views.internal.InconclusiveTraceViewerFilter;
89: import org.overture.ide.plugins.combinatorialtesting.views.internal.OkTraceViewerFilter;
90: import org.overture.ide.plugins.combinatorialtesting.views.internal.TraceNodeSorter;
91: import org.overture.ide.plugins.combinatorialtesting.views.internal.TraceViewerSorter;
92: import org.overture.ide.plugins.combinatorialtesting.views.treeView.ITreeNode;
93: import org.overture.ide.plugins.combinatorialtesting.views.treeView.NotYetReadyTreeNode;
94: import org.overture.ide.plugins.combinatorialtesting.views.treeView.ProjectTreeNode;
95: import org.overture.ide.plugins.combinatorialtesting.views.treeView.TraceTestGroup;
96: import org.overture.ide.plugins.combinatorialtesting.views.treeView.TraceTestTreeNode;
97: import org.overture.ide.plugins.combinatorialtesting.views.treeView.TraceTreeNode;
98: import org.overture.ide.ui.utility.EditorUtility;
99:
100: public class TracesTreeView extends ViewPart implements ITracesDisplay
101: {
102:         private TreeViewer viewer;
103:         private Action actionRunSelected;
104:         private Action actionRunSelectedAdvanced;
105:         private Action actionSetOkFilter;
106:         private Action actionSetSort;
107:         private Action actionSetInconclusiveFilter;
108:         private Action actionSendToInterpreter;
109:
110:         private Action refreshAction;
111:         final Display display = Display.getCurrent();
112:
113:         Button buttonSetSort = null;
114:
115:         private ViewerFilter okFilter = new OkTraceViewerFilter();
116:         private ViewerSorter traceSorter = new TraceViewerSorter();
117:         private ViewerSorter defaultTraceSorter = new TraceNodeSorter();
118:         private ViewerFilter inconclusiveFilter = new InconclusiveTraceViewerFilter();
119:
120:         /**
121:          * The constructor.
122:          */
123:         public TracesTreeView()
124:         {
125:         }
126:
127:         private void init()
128:         {
129:                 viewer.setContentProvider(new ViewContentProvider(this));
130:                 viewer.setLabelProvider(new ViewLabelProvider());
131:                 viewer.setSorter(defaultTraceSorter);
132:                 viewer.setInput(getViewSite());
133:         }
134:
135:         /**
136:          * This is a callback that will allow us to create the viewer and initialize it.
137:          */
138:         @Override
139:         public void createPartControl(Composite parent)
140:         {
141:                 viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
142:
143:                 getSite().setSelectionProvider(viewer);
144:
145:                 makeActions();
146:                 hookContextMenu();
147:                 hookTreeAction();
148:                 contributeToActionBars();
149:
150:                 init();
151:
152:         }
153:
154:         private void hookContextMenu()
155:         {
156:                 MenuManager menuMgr = new MenuManager("#PopupMenu");
157:                 menuMgr.setRemoveAllWhenShown(true);
158:                 menuMgr.addMenuListener(new IMenuListener()
159:                 {
160:                         public void menuAboutToShow(IMenuManager manager)
161:                         {
162:                                 TracesTreeView.this.fillContextMenu(manager);
163:                         }
164:                 });
165:                 Menu menu = menuMgr.createContextMenu(viewer.getControl());
166:                 viewer.getControl().setMenu(menu);
167:                 getSite().registerContextMenu(menuMgr, viewer);
168:         }
169:
170:         private void contributeToActionBars()
171:         {
172:                 IActionBars bars = getViewSite().getActionBars();
173:                 fillLocalPullDown(bars.getMenuManager());
174:                 fillLocalToolBar(bars.getToolBarManager());
175:         }
176:
177:         private void fillLocalPullDown(IMenuManager manager)
178:         {
179:                 manager.add(actionSetSort);
180:                 manager.add(new Separator());
181:                 manager.add(actionSetOkFilter);
182:                 manager.add(actionSetInconclusiveFilter);
183:         }
184:
185:         private void fillContextMenu(IMenuManager manager)
186:         {
187:                 ISelection selection = viewer.getSelection();
188:                 Object obj = ((IStructuredSelection) selection).getFirstElement();
189:
190:                 if (obj instanceof ProjectTreeNode /* || obj instanceof ClassTreeNode */
191:                                 || obj instanceof SClassDefinition
192:                                 || obj instanceof AModuleModules
193:                                 || obj instanceof TraceTreeNode) // ||
194:                 {
195:                         manager.add(actionRunSelected);
196:                         manager.add(actionRunSelectedAdvanced);
197:                 }
198:                 if (obj instanceof TraceTestTreeNode)
199:                 {
200:                         if (((TraceTestTreeNode) obj).getStatus() != null)
201:                         {
202:                                 manager.add(actionSendToInterpreter);
203:                         }
204:                 }
205:
206:                 manager.add(new Separator());
207:                 manager.add(refreshAction);
208:                 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
209:         }
210:
211:         private void fillLocalToolBar(IToolBarManager manager)
212:         {
213:                 manager.add(refreshAction);
214:                 manager.add(actionSetSort);
215:                 manager.add(new Separator());
216:                 manager.add(actionSetOkFilter);
217:                 manager.add(actionSetInconclusiveFilter);
218:         }
219:
220:         private final Image getImage(String path)
221:         {
222:                 ImageDescriptor theDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin("org.overture.ide.plugins.combinatorialtesting", path);
223:                 Image theImage = null;
224:                 if (theDescriptor != null)
225:                 {
226:                         theImage = theDescriptor.createImage();
227:                 }
228:                 return theImage;
229:         }
230:
231:         private void makeActions()
232:         {
233:                 refreshAction = new Action("Refresh",OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_REFRESH))
234:                 {
235:                         @Override
236:                         public void run()
237:                         {
238:
239:                                 Job job = new Job("Refresh Projects")
240:                                 {
241:
242:                                         @Override
243:                                         protected IStatus run(IProgressMonitor monitor)
244:                                         {
245:
246:                                                 refreshAction.setEnabled(false);
247:
248:                                                 for (IVdmProject proj : TraceAstUtility.getProjects())
249:                                                 {
250:
251:                                                         IVdmModel model = proj.getModel();
252:                                                         model.refresh(false, null);
253:                                                 }
254:
255:                                                 refreshAction.setEnabled(true);
256:
257:                                                 display.asyncExec(new Runnable()
258:                                                 {
259:
260:                                                         public void run()
261:                                                         {
262:
263:                                                                 init();
264:                                                         }
265:                                                 });
266:
267:                                                 return Status.OK_STATUS;
268:                                         }
269:                                 };
270:                                 job.schedule();
271:                         }
272:                 };
273:                 
274:
275:                 actionRunSelected = new Action("Full Evaluation")
276:                 {
277:
278:                         @Override
279:                         public void run()
280:                         {
281:                                 ISelection selection = viewer.getSelection();
282:                                 final Object obj = ((IStructuredSelection) selection).getFirstElement();
283:
284:                                 handleEvaluateTrace(obj, null);
285:                         }
286:                 };
287:                 actionRunSelected.setImageDescriptor(OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_RUN_SELECTED_TRACE));
288:                 
289:                 actionRunSelectedAdvanced = new Action("Filtered Evaluation",OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_RUN_SELECTED_TRACE))
290:                 {
291:                         @Override
292:                         public void run()
293:                         {
294:                                 Shell dialog = new Shell(display, SWT.DIALOG_TRIM);
295:                                 dialog.setText("Select filtering options");
296:                                 dialog.setSize(200, 200);
297:
298:                                 Image ctIcon = getImage(new StringBuilder("icons").append(File.separator).append("ctool16").append(File.separator).append("ct_tsk.png").toString());
299:                                 dialog.setImage(ctIcon);
300:
301:                                 final TraceOptionsDialog d = new TraceOptionsDialog(dialog, SWT.DIALOG_TRIM);
302:                                 d.pack();
303:                                 dialog.pack();
304:                                 Point pt = display.getCursorLocation();
305:                                 dialog.setLocation(pt.x - d.getSize().x / 2, pt.y
306:                                                 - d.getSize().y / 2);
307:                                 dialog.open();
308:                                 while (!dialog.isDisposed())
309:                                 {
310:                                         if (d.isCanceled)
311:                                         {
312:                                                 return;
313:                                         }
314:                                         if (!display.readAndDispatch())
315:                                         {
316:                                                 display.sleep();
317:                                         }
318:                                 }
319:
320:                                 if (d.isCanceled || d.getTraceReductionType() == null)
321:                                 {
322:                                         return;
323:                                 }
324:                                 ISelection selection = viewer.getSelection();
325:                                 final Object obj = ((IStructuredSelection) selection).getFirstElement();
326:
327:                                 handleEvaluateTrace(obj, d);
328:                         }
329:                 };
330:
331:
332:                 actionSetOkFilter = new Action("Filter ok results",Action.AS_CHECK_BOX)
333:                 {
334:                         @Override
335:                         public void run()
336:                         {
337:                                 ViewerFilter[] filters = viewer.getFilters();
338:                                 boolean isSet = false;
339:                                 for (ViewerFilter viewerFilter : filters)
340:                                 {
341:                                         if (viewerFilter.equals(okFilter))
342:                                         {
343:                                                 isSet = true;
344:                                         }
345:                                 }
346:                                 if (isSet)
347:                                 {
348:                                         viewer.removeFilter(okFilter);
349:                                 } else
350:                                 {
351:                                         viewer.addFilter(okFilter);
352:                                 }
353:
354:                         }
355:
356:                 };
357:
358:                 actionSetOkFilter.setToolTipText("Filter all ok results from tree");
359:                 actionSetOkFilter.setImageDescriptor(OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_TRACE_TEST_CASE_FILTER_SUCCES));
360:
361:                 actionSetInconclusiveFilter = new Action("Filter inconclusive results",Action.AS_CHECK_BOX)
362:                 {
363:                         @Override
364:                         public void run()
365:                         {
366:                                 ViewerFilter[] filters = viewer.getFilters();
367:                                 boolean isSet = false;
368:                                 for (ViewerFilter viewerFilter : filters)
369:                                 {
370:                                         if (viewerFilter.equals(inconclusiveFilter))
371:                                         {
372:                                                 isSet = true;
373:                                         }
374:                                 }
375:                                 if (isSet)
376:                                 {
377:                                         viewer.removeFilter(inconclusiveFilter);
378:                                 } else
379:                                 {
380:                                         viewer.addFilter(inconclusiveFilter);
381:                                 }
382:
383:                         }
384:
385:                 };
386:
387:                 actionSetInconclusiveFilter.setToolTipText("Filter all inconclusive results from tree");
388:                 actionSetInconclusiveFilter.setImageDescriptor(OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_TRACE_TEST_CASE_FILTER_UNDETERMINED));
389:
390:                 actionSetSort = new Action("Sort",Action.AS_CHECK_BOX)
391:                 {
392:                         @Override
393:                         public void run()
394:                         {
395:                                 if (!actionSetSort.isChecked())
396:                                 {
397:                                         viewer.setSorter(defaultTraceSorter);
398:                                         OvertureTracesPlugin.getDefault().getPreferenceStore().setValue(ITracesConstants.SORT_VIEW, false);
399:                                 } else
400:                                 {
401:                                         viewer.setSorter(traceSorter);
402:                                         OvertureTracesPlugin.getDefault().getPreferenceStore().setValue(ITracesConstants.SORT_VIEW, true);
403:                                 }
404:                         }
405:                 };
406:
407:                 actionSetSort.setToolTipText("Sort by verdict: Fail, Inconclusive, ok, etc.");
408:                 actionSetSort.setImageDescriptor(OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_TRACE_TEST_SORT));
409:                 actionSetSort.setChecked(OvertureTracesPlugin.getDefault().getPreferenceStore().getBoolean(ITracesConstants.SORT_VIEW));
410: actionSetSort.run();
411:                 
412:                 actionSendToInterpreter = new Action("Send to Interpreter",OvertureTracesPlugin.getImageDescriptor(OvertureTracesPlugin.IMG_INTERPRETER))
413:                 {
414:                         @Override
415:                         public void run()
416:                         {
417:                                 ISelection selection = viewer.getSelection();
418:                                 final Object obj = ((IStructuredSelection) selection).getFirstElement();
419:
420:                                 if (obj instanceof TraceTestTreeNode)
421:                                 {
422:                                         TraceTestTreeNode traceTestNode = (TraceTestTreeNode) obj;
423:
424:                                         TraceTreeNode traceNode = null;
425:                                         ITreeNode n = traceTestNode;
426:                                         while (n != null && !(n instanceof ProjectTreeNode))
427:                                         {
428:                                                 if (n instanceof TraceTreeNode)
429:                                                 {
430:                                                         traceNode = (TraceTreeNode) n;
431:                                                 }
432:                                                 n = n.getParent();
433:
434:                                         }
435:                                         new TraceDebugLauncher().Launch(TraceAstUtility.getProject(traceNode.getTraceDefinition()), traceNode.getInfo(), traceTestNode.getNumber());
436:                                 }
437:                         }
438:                 };
439:
440:         }
441:
442:         private void hookTreeAction()
443:         {
444:                 viewer.addSelectionChangedListener(new ISelectionChangedListener()
445:                 {
446:
447:                         public void selectionChanged(SelectionChangedEvent event)
448:                         {
449:
450:                                 Object selection = ((ITreeSelection) event.getSelection()).getFirstElement();
451:                                 if (selection instanceof TraceTreeNode)
452:                                 {
453:                                         TraceTreeNode tn = (TraceTreeNode) selection;
454:
455:                                         gotoTraceDefinition(tn);
456:
457:                                 } else if (selection instanceof TraceTestTreeNode)
458:                                 {
459:                                         if (!(selection instanceof NotYetReadyTreeNode)
460:                                                         && !(selection instanceof TraceTestGroup)
461:                                                         && ((TraceTestTreeNode) selection).getStatus() == null)
462:                                         {
463:                                                 try
464:                                                 {
465:                                                         PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(IPageLayout.ID_PROGRESS_VIEW);
466:                                                 } catch (PartInitException e)
467:                                                 {
468:                                                         OvertureTracesPlugin.log(e);
469:                                                 }
470:                                         } else
471:                                         {
472:                                                 try
473:                                                 {
474:                                                         IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(ITracesConstants.TRACES_TEST_ID);
475:                                                         if (view instanceof TraceTest)
476:                                                         {
477:                                                                 TraceTest traceTestView = (TraceTest) view;
478:                                                                 traceTestView.selectionChanged(TracesTreeView.this, event.getSelection());
479:                                                         }
480:                                                         gotoTraceDefinition(findTraceTreeNode((TraceTestTreeNode) selection));
481:                                                 } catch (PartInitException e)
482:                                                 {
483:                                                         OvertureTracesPlugin.log(e);
484:                                                 }
485:                                         }
486:
487:                                 }
488:                         }
489:
490:                         private TraceTreeNode findTraceTreeNode(ITreeNode selection)
491:                         {
492:                                 if (selection != null)
493:                                 {
494:                                         if (selection.getParent() == null)
495:                                         {
496:                                                 return null;
497:                                         } else if (selection.getParent() instanceof TraceTreeNode)
498:                                         {
499:                                                 return (TraceTreeNode) selection.getParent();
500:                                         } else
501:                                         {
502:                                                 return findTraceTreeNode(selection.getParent());
503:                                         }
504:                                 }
505:
506:                                 return null;
507:                         }
508:
509:                 });
510:                 viewer.addTreeListener(new ITreeViewerListener()
511:                 {
512:
513:                         public void treeCollapsed(TreeExpansionEvent event)
514:                         {
515:                                 Object expandingElement = event.getElement();
516:                                 if (expandingElement instanceof TraceTreeNode)
517:                                 {
518:                                         TraceTreeNode node = (TraceTreeNode) expandingElement;
519:                                         node.unloadTests();
520:
521:                                         refreshTree();
522:                                 } else if (expandingElement instanceof TraceTestGroup)
523:                                 {
524:                                         TraceTestGroup node = (TraceTestGroup) expandingElement;
525:                                         node.unloadTests();
526:                                         refreshTree();
527:                                 }
528:
529:                         }
530:
531:                         public void treeExpanded(TreeExpansionEvent event)
532:                         {
533:                                 Object expandingElement = event.getElement();
534:                                 if (expandingElement instanceof TraceTreeNode)
535:                                 {
536:                                         TraceTreeNode node = (TraceTreeNode) expandingElement;
537:                                         try
538:                                         {
539:                                                 node.loadTests();
540:                                         } catch (Exception e)
541:                                         {
542:                                                 OvertureTracesPlugin.log(e);
543:                                         }
544:                                         refreshTree();
545:                                 } else if (expandingElement instanceof TraceTestGroup)
546:                                 {
547:                                         TraceTestGroup node = (TraceTestGroup) expandingElement;
548:                                         try
549:                                         {
550:                                                 node.loadTests();
551:                                         } catch (Exception e)
552:                                         {
553:                                                 OvertureTracesPlugin.log(e);
554:                                         }
555:                                         refreshTree();
556:                                 }
557:                         }
558:                 });
559:
560:         }
561:
562:         private void refreshTree()
563:         {
564:                 display.asyncExec(new Runnable()
565:                 {
566:
567:                         public void run()
568:                         {
569:                                 if (viewer != null && !viewer.getControl().isDisposed())
570:                                 {
571:                                         viewer.refresh();
572:                                         viewer.getControl().update();
573:                                         actionSetSort.run();
574:                                 }
575:                         }
576:                 });
577:         }
578:
579:         /**
580:          * Passing the focus request to the viewer's control.
581:          */
582:         @Override
583:         public void setFocus()
584:         {
585:                 viewer.getControl().setFocus();
586:         }
587:
588:         private void ConsolePrint(final String message)
589:         {
590:                 display.asyncExec(new Runnable()
591:                 {
592:
593:                         public void run()
594:                         {
595:                                 try
596:                                 {
597:                                         MessageConsole myConsole = findConsole("TracesConsole");
598:                                         MessageConsoleStream out = myConsole.newMessageStream();
599:                                         out.println(message);
600:                                 } catch (Exception e)
601:                                 {
602:                                         OvertureTracesPlugin.log(e);
603:                                 }
604:                         }
605:                 });
606:
607:         }
608:
609:         private void ConsoleError(final String message)
610:         {
611:                 display.asyncExec(new Runnable()
612:                 {
613:
614:                         public void run()
615:                         {
616:                                 try
617:                                 {
618:                                         MessageConsole myConsole = findConsole("TracesConsole");
619:                                         MessageConsoleStream out = myConsole.newMessageStream();
620:
621:                                         out.setColor(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
622:                                         out.println(message);
623:
624:                                         IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
625:                                         if (activeWorkbenchWindow != null)
626:                                         {
627:                                                 IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
628:                                                 if (activePage != null)
629:                                                 {
630:                                                         activePage.showView(IConsoleConstants.ID_CONSOLE_VIEW, null, IWorkbenchPage.VIEW_VISIBLE);
631:                                                 }
632:                                         }
633:                                 } catch (Exception e)
634:                                 {
635:                                         OvertureTracesPlugin.log(e);
636:                                 }
637:                         }
638:                 });
639:
640:         }
641:
642:         private void gotoTraceDefinition(TraceTreeNode tn)
643:         {
644:                 if (tn == null || tn.getTraceDefinition() == null)
645:                 {
646:                         return;
647:                 }
648:
649:                 IVdmProject vdmProject = TraceAstUtility.getProject(tn.getTraceDefinition());
650:
651:                 IFile file = vdmProject.findIFile(tn.getTraceDefinition().getLocation().getFile());
652:
653:                 EditorUtility.gotoLocation(file, tn.getTraceDefinition().getLocation(), tn.getName());
654:         }
655:
656:         private MessageConsole findConsole(String name)
657:         {
658:                 ConsolePlugin plugin = ConsolePlugin.getDefault();
659:                 IConsoleManager conMan = plugin.getConsoleManager();
660:                 IConsole[] existing = conMan.getConsoles();
661:                 for (int i = 0; i < existing.length; i++)
662:                 {
663:                         if (name.equals(existing[i].getName()))
664:                         {
665:                                 return (MessageConsole) existing[i];
666:                         }
667:                 }
668:                 // no console found, so create a new one
669:                 MessageConsole myConsole = new MessageConsole(name, null);
670:                 conMan.addConsoles(new IConsole[] { myConsole });
671:                 return myConsole;
672:         }
673:
674:         private void handleEvaluateTrace(Object selectedItem,
675:                         final TraceOptionsDialog optionsDialog)
676:         {
677:                 IVdmProject project = null;
678:                 INode container = null;
679:                 ANamedTraceDefinition traceDef = null;
680:
681:                 if (selectedItem instanceof ProjectTreeNode)
682:                 {
683:                         ProjectTreeNode pn = (ProjectTreeNode) selectedItem;
684:                         project = pn.project;
685:                 } else if (selectedItem instanceof SClassDefinition
686:                                 || selectedItem instanceof AModuleModules)
687:                 {
688:                         project = TraceAstUtility.getProject((INode) selectedItem);
689:                         container = (INode) selectedItem;
690:                 } else if (selectedItem instanceof TraceTreeNode)
691:                 {
692:                         traceDef = ((TraceTreeNode) selectedItem).getTraceDefinition();
693:                         container = TraceAstUtility.getTraceDefinitionContainer(traceDef);
694:                         project = TraceAstUtility.getProject(traceDef);
695:                 } else if (selectedItem instanceof IVdmProject)
696:                 {
697:                         project = (IVdmProject) selectedItem;
698:                 }
699:
700:                 final IVdmProject finalProject = project;
701:                 final INode finalContainer = container;
702:                 final ANamedTraceDefinition finalTraceDef = traceDef;
703:
704:                 Job executeTestJob = new Job("CT evaluating selected tests")
705:                 {
706:                         @Override
707:                         protected IStatus run(IProgressMonitor monitor)
708:                         {
709:                                 try
710:                                 {
711:                                         try
712:                                         {
713:                                                 evaluateTraces(finalProject, finalContainer, finalTraceDef, optionsDialog, monitor);
714:                                         } catch (CancellationException e)
715:                                         {
716:                                                 ConsolePrint(e.getMessage());
717:                                         } catch (Exception e)
718:                                         {
719:                                                 ConsoleError(e.getMessage());
720:                                                 OvertureTracesPlugin.log(e);
721:                                         }
722:
723:                                         monitor.done();
724:
725:                                 } catch (Exception e)
726:                                 {
727:                                         OvertureTracesPlugin.log(e);
728:                                 }
729:
730:                                 // expandTraces(0);
731:                                 return new Status(IStatus.OK, ITracesConstants.PLUGIN_ID, IStatus.OK, "CT Test evaluation finished", null);
732:                         }
733:                 };
734:                 executeTestJob.schedule();
735:         }
736:
737:         private void evaluateTraces(final IVdmProject project, INode container,
738:                         ANamedTraceDefinition traceDef, TraceOptionsDialog filterDialog,
739:                         IProgressMonitor monitor) throws Exception
740:         {
741:                 if (project == null)
742:                 {
743:                         return;
744:                 }
745:
746:                 VdmjTracesHelper traceRunner = new VdmjTracesHelper(getSite().getShell(), project);
747:
748:                 if (filterDialog == null)
749:                 {
750:                         traceRunner.evaluateTraces(container, traceDef, monitor, this);
751:                 } else
752:                 {
753:                         traceRunner.evaluateTraces(container, traceDef, filterDialog.getSubset(), filterDialog.getTraceReductionType(), filterDialog.getSeed(), monitor, this);
754:                 }
755:
756:         }
757:
758:         public void updateView(final IVdmProject project)
759:         {
760:                 display.asyncExec(new Runnable()
761:                 {
762:
763:                         public void run()
764:                         {
765:
766:                                 if (viewer == null || viewer.getControl().isDisposed())// TODO
767:                                 {
768:                                         return; // skip if disposed
769:                                 }
770:                                 TreeItem[] aa = viewer.getTree().getItems();
771:                                 // boolean insertProject = true;
772:                                 for (TreeItem treeItem : aa)
773:                                 {
774:                                         if (treeItem.getData() instanceof ProjectTreeNode
775:                                                         && ((ProjectTreeNode) treeItem.getData()).getName().equals(project.getName()))
776:                                         {
777:                                                 if (viewer.getContentProvider() instanceof ViewContentProvider)
778:                                                 {
779:                                                         ((ViewContentProvider) viewer.getContentProvider()).resetCache(project);
780:                                                 }
781:                                                 viewer.refresh();
782:                                                 viewer.getControl().update();
783:                                                 actionSetSort.run();
784:                                         }
785:                                 }
786:                         }
787:
788:                 });
789:                 try
790:                 {
791:                         ((IProject) project.getAdapter(IProject.class)).refreshLocal(IResource.DEPTH_INFINITE, null);
792:                 } catch (CoreException e)
793:                 {
794:                 }
795:         }
796: }