Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui.tests / src / org / eclipse / linuxtools / lttng / ui / tests / control / model / component / TraceControlTestFacility.java
1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.tests.control.model.component;
13
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;
20
21 /**
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.
24 */
25 public class TraceControlTestFacility {
26
27 // ------------------------------------------------------------------------
28 // Constants
29 // ------------------------------------------------------------------------
30
31 final static public int WAIT_FOR_JOBS_DELAY = 1000;
32 final static public int GUI_REFESH_DELAY = 500;
33
34 // ------------------------------------------------------------------------
35 // Attributes
36 // ------------------------------------------------------------------------
37 private static TraceControlTestFacility fInstance = null;
38 private ControlView fControlView = null;
39 private boolean fIsInitialized = false;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44 private TraceControlTestFacility() {
45 }
46
47 // ------------------------------------------------------------------------
48 // Operations
49 // ------------------------------------------------------------------------
50 public static TraceControlTestFacility getInstance() {
51 if (fInstance == null) {
52 fInstance = new TraceControlTestFacility();
53 }
54 return fInstance;
55 }
56
57 /**
58 * Initial the test facility.
59 */
60 public void init() {
61
62 if (!fIsInitialized) {
63
64 IViewPart view;
65 try {
66 view = PlatformUI.getWorkbench()
67 .getActiveWorkbenchWindow()
68 .getActivePage()
69 .showView(ControlView.ID);
70
71 } catch (PartInitException e) {
72 throw new RuntimeException(e);
73 }
74
75 fControlView = (ControlView) view;
76
77 delay(3000);
78 fIsInitialized = true;
79 }
80 }
81
82
83 public void dispose() {
84 if (fIsInitialized) {
85 waitForJobs();
86
87 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fControlView);
88 fIsInitialized = false;
89 }
90 }
91
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()) {
98 display.sleep();
99 }
100 display.update();
101 }
102 } else {
103 try {
104 Thread.sleep(waitTimeMillis);
105 } catch (InterruptedException e) {
106 // Ignored
107 }
108 }
109 }
110
111 /**
112 * Waits for all Eclipse jobs to finish
113 */
114 public void waitForJobs() {
115 while (!Job.getJobManager().isIdle()) {
116 delay(WAIT_FOR_JOBS_DELAY);
117 }
118 }
119
120
121 /**
122 * @return current control view
123 */
124 public ControlView getControlView() {
125 return fControlView;
126 }
127 }
This page took 0.03421 seconds and 6 git commands to generate.