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
.lttng2
.ui
.tests
.control
.model
.component
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.commands
.NotEnabledException
;
16 import org
.eclipse
.core
.commands
.NotHandledException
;
17 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
18 import org
.eclipse
.core
.runtime
.jobs
.Job
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.ui
.IViewPart
;
22 import org
.eclipse
.ui
.PartInitException
;
23 import org
.eclipse
.ui
.PlatformUI
;
24 import org
.eclipse
.ui
.handlers
.IHandlerService
;
27 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
28 * utility methods for interacting with the loader/view.
30 public class TraceControlTestFacility
{
32 // ------------------------------------------------------------------------
34 // ------------------------------------------------------------------------
35 final static public int WAIT_FOR_JOBS_DELAY
= 1000;
36 final static public int GUI_REFESH_DELAY
= 500;
38 final static public String COMMAND_CATEGORY_PREFIX
= "org.eclipse.linuxtools.internal.lttng2.ui.commands.control."; //$NON-NLS-1$
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
43 private static TraceControlTestFacility fInstance
= null;
44 private ControlView fControlView
= null;
45 private boolean fIsInitialized
= false;
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
50 private TraceControlTestFacility() {
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
56 public static TraceControlTestFacility
getInstance() {
57 if (fInstance
== null) {
58 fInstance
= new TraceControlTestFacility();
64 * Initial the test facility.
68 if (!fIsInitialized
) {
72 view
= PlatformUI
.getWorkbench()
73 .getActiveWorkbenchWindow()
75 .showView(ControlView
.ID
);
77 } catch (PartInitException e
) {
78 throw new RuntimeException(e
);
81 fControlView
= (ControlView
) view
;
84 fIsInitialized
= true;
89 public void dispose() {
93 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fControlView
);
94 fIsInitialized
= false;
98 public void delay(long waitTimeMillis
) {
99 Display display
= Display
.getCurrent();
100 if (display
!= null) {
101 long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
102 while(System
.currentTimeMillis() < endTimeMillis
) {
103 if (!display
.readAndDispatch()) {
110 Thread
.sleep(waitTimeMillis
);
111 } catch (InterruptedException e
) {
118 * Waits for all Eclipse jobs to finish
120 public void waitForJobs() {
121 while (!Job
.getJobManager().isIdle()) {
122 delay(WAIT_FOR_JOBS_DELAY
);
128 * @return current control view
130 public ControlView
getControlView() {
134 public void executeCommand(String commandId
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
135 // ICommandService commandService = (ICommandService) fControlView.getSite().getService(ICommandService.class);
136 IHandlerService handlerService
= (IHandlerService
) fControlView
.getSite().getService(IHandlerService
.class);
137 handlerService
.executeCommand(COMMAND_CATEGORY_PREFIX
+ commandId
, null);