1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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
.internal
.lttng2
.ui
.views
.control
.handlers
;
14 import java
.util
.Iterator
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.IStatus
;
20 import org
.eclipse
.core
.runtime
.Status
;
21 import org
.eclipse
.core
.runtime
.jobs
.Job
;
22 import org
.eclipse
.jface
.viewers
.ISelection
;
23 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
29 import org
.eclipse
.ui
.IWorkbenchPage
;
30 import org
.eclipse
.ui
.IWorkbenchWindow
;
31 import org
.eclipse
.ui
.PlatformUI
;
35 * Command handler implementation to execute command calibrate to quantify LTTng overhead.
38 * @author Bernd Hufmann
40 public class CalibrateHandler
extends BaseControlViewHandler
{
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
46 * The command execution parameter.
48 protected DomainCommandParameter fParam
= null;
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
55 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
57 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
64 // Make a copy for thread safety
65 final DomainCommandParameter param
= fParam
.clone();
67 Job addJob
= new Job(Messages
.TraceControl_AddCalibrateJob
) {
69 protected IStatus
run(IProgressMonitor monitor
) {
71 param
.getDomain().calibrate(monitor
);
72 } catch (ExecutionException e
) {
73 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_AddCalibrateFailure
, e
);
76 return Status
.OK_STATUS
;
85 return Status
.OK_STATUS
;
89 public boolean isEnabled() {
91 // Get workbench page for the Control View
92 IWorkbenchPage page
= getWorkbenchPage();
97 TraceDomainComponent domain
= null;
98 TraceSessionComponent session
= null;
100 // Check if one domain is selected
101 ISelection selection
= page
.getSelection(ControlView
.ID
);
102 if (selection
instanceof StructuredSelection
) {
103 StructuredSelection structered
= ((StructuredSelection
) selection
);
104 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
105 Object element
= iterator
.next();
106 if (element
instanceof TraceDomainComponent
) {
107 TraceDomainComponent tmpDomain
= (TraceDomainComponent
) element
;
108 session
= (TraceSessionComponent
) tmpDomain
.getParent();
110 // Add only TraceDomainComponent whose TraceSessionComponent parent is not destroyed
111 if ((!session
.isDestroyed())) {
118 boolean isEnabled
= domain
!= null;
124 fParam
= new DomainCommandParameter(session
, domain
);