1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.tests
.control
.model
.component
;
14 import org
.eclipse
.core
.runtime
.jobs
.Job
;
15 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.ControlView
;
16 import org
.eclipse
.swt
.widgets
.Display
;
17 import org
.eclipse
.ui
.IViewPart
;
18 import org
.eclipse
.ui
.PartInitException
;
19 import org
.eclipse
.ui
.PlatformUI
;
22 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
23 * utility methods for interacting with the loader/view.
25 public class TraceControlTestFacility
{
27 // ------------------------------------------------------------------------
29 // ------------------------------------------------------------------------
31 final static public int WAIT_FOR_JOBS_DELAY
= 1000;
32 final static public int GUI_REFESH_DELAY
= 500;
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
37 private static TraceControlTestFacility fInstance
= null;
38 private ControlView fControlView
= null;
39 private boolean fIsInitialized
= false;
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
44 private TraceControlTestFacility() {
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
50 public static TraceControlTestFacility
getInstance() {
51 if (fInstance
== null) {
52 fInstance
= new TraceControlTestFacility();
58 * Initial the test facility.
62 if (!fIsInitialized
) {
66 view
= PlatformUI
.getWorkbench()
67 .getActiveWorkbenchWindow()
69 .showView(ControlView
.ID
);
71 } catch (PartInitException e
) {
72 throw new RuntimeException(e
);
75 fControlView
= (ControlView
) view
;
78 fIsInitialized
= true;
83 public void dispose() {
87 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fControlView
);
88 fIsInitialized
= false;
92 public void delay(long waitTimeMillis
) {
93 Display display
= Display
.getCurrent();
94 if (display
!= null) {
95 long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
96 while(System
.currentTimeMillis() < endTimeMillis
) {
97 if (!display
.readAndDispatch()) {
104 Thread
.sleep(waitTimeMillis
);
105 } catch (InterruptedException e
) {
112 * Waits for all Eclipse jobs to finish
114 public void waitForJobs() {
115 while (!Job
.getJobManager().isIdle()) {
116 delay(WAIT_FOR_JOBS_DELAY
);
122 * @return current control view
124 public ControlView
getControlView() {