gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / handlers / CalibrateHandler.java
CommitLineData
b720ac44 1/**********************************************************************
11252342 2 * Copyright (c) 2012, 2013 Ericsson
cfdb727a 3 *
b720ac44
BH
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
cfdb727a
AM
8 *
9 * Contributors:
b720ac44
BH
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
8e8c0226 12package org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers;
b720ac44
BH
13
14import java.util.Iterator;
15
16import org.eclipse.core.commands.ExecutionEvent;
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.runtime.IProgressMonitor;
19import org.eclipse.core.runtime.IStatus;
20import org.eclipse.core.runtime.Status;
21import org.eclipse.core.runtime.jobs.Job;
22import org.eclipse.jface.viewers.ISelection;
23import org.eclipse.jface.viewers.StructuredSelection;
8e8c0226
AM
24import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator;
25import org.eclipse.linuxtools.internal.lttng2.control.ui.views.ControlView;
26import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
27import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
28import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
b720ac44
BH
29import org.eclipse.ui.IWorkbenchPage;
30import org.eclipse.ui.IWorkbenchWindow;
31import org.eclipse.ui.PlatformUI;
32
33/**
b720ac44
BH
34 * <p>
35 * Command handler implementation to execute command calibrate to quantify LTTng overhead.
36 * </p>
cfdb727a 37 *
dbd4432d 38 * @author Bernd Hufmann
b720ac44
BH
39 */
40public class CalibrateHandler extends BaseControlViewHandler {
41
42 // ------------------------------------------------------------------------
43 // Attributes
44 // ------------------------------------------------------------------------
45 /**
46 * The command execution parameter.
47 */
48 protected DomainCommandParameter fParam = null;
49
50 // ------------------------------------------------------------------------
51 // Operations
52 // ------------------------------------------------------------------------
cfdb727a 53
b720ac44
BH
54 @Override
55 public Object execute(ExecutionEvent event) throws ExecutionException {
56
57 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
58
59 if (window == null) {
60 return false;
61 }
62 fLock.lock();
63 try {
64 // Make a copy for thread safety
65 final DomainCommandParameter param = fParam.clone();
66
67 Job addJob = new Job(Messages.TraceControl_AddCalibrateJob) {
68 @Override
69 protected IStatus run(IProgressMonitor monitor) {
70 try {
71 param.getDomain().calibrate(monitor);
72 } catch (ExecutionException e) {
cfdb727a 73 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_AddCalibrateFailure, e);
b720ac44
BH
74 }
75
76 return Status.OK_STATUS;
77 }
78 };
79 addJob.setUser(true);
80 addJob.schedule();
81
82 } finally {
83 fLock.unlock();
84 }
85 return Status.OK_STATUS;
86 }
87
b720ac44
BH
88 @Override
89 public boolean isEnabled() {
cfdb727a 90
b720ac44
BH
91 // Get workbench page for the Control View
92 IWorkbenchPage page = getWorkbenchPage();
93 if (page == null) {
94 return false;
95 }
96
97 TraceDomainComponent domain = null;
98 TraceSessionComponent session = null;
99
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();) {
cfdb727a 105 Object element = iterator.next();
b720ac44
BH
106 if (element instanceof TraceDomainComponent) {
107 TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
108 session = (TraceSessionComponent) tmpDomain.getParent();
cfdb727a 109
b720ac44
BH
110 // Add only TraceDomainComponent whose TraceSessionComponent parent is not destroyed
111 if ((!session.isDestroyed())) {
112 domain = tmpDomain;
113 }
114 }
115 }
116 }
117
118 boolean isEnabled = domain != null;
119
120 fLock.lock();
121 try {
122 fParam = null;
123 if (isEnabled) {
124 fParam = new DomainCommandParameter(session, domain);
125 }
126 } finally {
127 fLock.unlock();
128 }
129
130 return isEnabled;
131 }
132}
This page took 0.049057 seconds and 5 git commands to generate.