Update internal packages export in LTTng 2.0 control + update java doc
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / CalibrateHandler.java
CommitLineData
b720ac44
BH
1/**********************************************************************
2 * Copyright (c) 2012 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 **********************************************************************/
12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
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;
24import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
25import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
9315aeee 26import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
b720ac44
BH
27import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
28import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
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>
dbd4432d
BH
37 *
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 // ------------------------------------------------------------------------
53
54 /*
55 * (non-Javadoc)
56 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
57 */
58 @Override
59 public Object execute(ExecutionEvent event) throws ExecutionException {
60
61 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
62
63 if (window == null) {
64 return false;
65 }
66 fLock.lock();
67 try {
68 // Make a copy for thread safety
69 final DomainCommandParameter param = fParam.clone();
70
71 Job addJob = new Job(Messages.TraceControl_AddCalibrateJob) {
72 @Override
73 protected IStatus run(IProgressMonitor monitor) {
74 try {
75 param.getDomain().calibrate(monitor);
76 } catch (ExecutionException e) {
77 return new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_AddCalibrateFailure, e);
78 }
79
80 return Status.OK_STATUS;
81 }
82 };
83 addJob.setUser(true);
84 addJob.schedule();
85
86 } finally {
87 fLock.unlock();
88 }
89 return Status.OK_STATUS;
90 }
91
92 /*
93 * (non-Javadoc)
94 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
95 */
96 @Override
97 public boolean isEnabled() {
98
99 // Get workbench page for the Control View
100 IWorkbenchPage page = getWorkbenchPage();
101 if (page == null) {
102 return false;
103 }
104
105 TraceDomainComponent domain = null;
106 TraceSessionComponent session = null;
107
108 // Check if one domain is selected
109 ISelection selection = page.getSelection(ControlView.ID);
110 if (selection instanceof StructuredSelection) {
111 StructuredSelection structered = ((StructuredSelection) selection);
112 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
113 Object element = (Object) iterator.next();
114 if (element instanceof TraceDomainComponent) {
115 TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
116 session = (TraceSessionComponent) tmpDomain.getParent();
117
118 // Add only TraceDomainComponent whose TraceSessionComponent parent is not destroyed
119 if ((!session.isDestroyed())) {
120 domain = tmpDomain;
121 }
122 }
123 }
124 }
125
126 boolean isEnabled = domain != null;
127
128 fLock.lock();
129 try {
130 fParam = null;
131 if (isEnabled) {
132 fParam = new DomainCommandParameter(session, domain);
133 }
134 } finally {
135 fLock.unlock();
136 }
137
138 return isEnabled;
139 }
140}
This page took 0.043313 seconds and 5 git commands to generate.