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
.commands
.Command
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.NotEnabledException
;
17 import org
.eclipse
.core
.commands
.NotHandledException
;
18 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
19 import org
.eclipse
.core
.runtime
.jobs
.Job
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.ControlView
;
21 import org
.eclipse
.swt
.widgets
.Display
;
22 import org
.eclipse
.ui
.IViewPart
;
23 import org
.eclipse
.ui
.PartInitException
;
24 import org
.eclipse
.ui
.PlatformUI
;
25 import org
.eclipse
.ui
.commands
.ICommandService
;
26 import org
.eclipse
.ui
.handlers
.IHandlerService
;
29 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
30 * utility methods for interacting with the loader/view.
32 public class TraceControlTestFacility
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
38 final static public int WAIT_FOR_JOBS_DELAY
= 1000;
39 final static public int GUI_REFESH_DELAY
= 500;
41 final static public String COMMAND_CATEGORY_PREFIX
= "org.eclipse.linuxtools.lttng.ui.commands.control."; //$NON-NLS-1$
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
46 private static TraceControlTestFacility fInstance
= null;
47 private ControlView fControlView
= null;
48 private boolean fIsInitialized
= false;
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
53 private TraceControlTestFacility() {
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
59 public static TraceControlTestFacility
getInstance() {
60 if (fInstance
== null) {
61 fInstance
= new TraceControlTestFacility();
67 * Initial the test facility.
71 if (!fIsInitialized
) {
75 view
= PlatformUI
.getWorkbench()
76 .getActiveWorkbenchWindow()
78 .showView(ControlView
.ID
);
80 } catch (PartInitException e
) {
81 throw new RuntimeException(e
);
84 fControlView
= (ControlView
) view
;
87 fIsInitialized
= true;
92 public void dispose() {
96 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fControlView
);
97 fIsInitialized
= false;
101 public void delay(long waitTimeMillis
) {
102 Display display
= Display
.getCurrent();
103 if (display
!= null) {
104 long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
105 while(System
.currentTimeMillis() < endTimeMillis
) {
106 if (!display
.readAndDispatch()) {
113 Thread
.sleep(waitTimeMillis
);
114 } catch (InterruptedException e
) {
121 * Waits for all Eclipse jobs to finish
123 public void waitForJobs() {
124 while (!Job
.getJobManager().isIdle()) {
125 delay(WAIT_FOR_JOBS_DELAY
);
131 * @return current control view
133 public ControlView
getControlView() {
137 public void executeCommand(String commandId
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
138 // ICommandService commandService = (ICommandService) fControlView.getSite().getService(ICommandService.class);
139 IHandlerService handlerService
= (IHandlerService
) fControlView
.getSite().getService(IHandlerService
.class);
140 handlerService
.executeCommand(COMMAND_CATEGORY_PREFIX
+ commandId
, null);