Fix NLS-related Javadoc warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / BaseEnableEventHandler.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
14
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionEvent;
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.Status;
22 import org.eclipse.core.runtime.jobs.Job;
23 import org.eclipse.jface.window.Window;
24 import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
25 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
26 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
27 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog;
28 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
29 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
30 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
31 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
32 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
33 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProviderGroup;
34 import org.eclipse.ui.IWorkbenchWindow;
35 import org.eclipse.ui.PlatformUI;
36
37 /**
38 * <p>
39 * Base command handler implementation to enable events.
40 * </p>
41 *
42 * @author Bernd Hufmann
43 */
44 abstract public class BaseEnableEventHandler extends BaseControlViewHandler {
45
46 // ------------------------------------------------------------------------
47 // Attributes
48 // ------------------------------------------------------------------------
49 /**
50 * The command execution parameter.
51 */
52 protected CommandParameter fParam = null;
53
54 // ------------------------------------------------------------------------
55 // Operations
56 // ------------------------------------------------------------------------
57
58 /**
59 * Enables a list of events for given parameters.
60 *
61 * @param param
62 * - a parameter instance with data for the command execution
63 * @param eventNames
64 * - list of event names
65 * @param isKernel
66 * - true if kernel domain else false
67 * @param filterExpression
68 * - a filter expression
69 * @param monitor
70 * - a progress monitor
71 * @throws ExecutionException
72 * If the command fails for some reason
73 */
74 abstract public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException;
75
76 /**
77 * Enables all syscall events.
78 *
79 * @param param
80 * - a parameter instance with data for the command execution
81 * @param monitor
82 * - a progress monitor
83 * @throws ExecutionException
84 * If the command fails for some reason
85 */
86 abstract public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException;
87
88 /**
89 * Enables a dynamic probe.
90 *
91 * @param param
92 * - a parameter instance with data for the command execution
93 * @param eventName
94 * - a event name
95 * @param isFunction
96 * - true for dynamic function entry/return probe else false
97 * @param probe
98 * - a dynamic probe information
99 * @param monitor
100 * - a progress monitor
101 * @throws ExecutionException
102 * If the command fails for some reason
103 */
104 abstract public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException;
105
106 /**
107 * Enables events using log level
108 *
109 * @param param
110 * - a parameter instance with data for the command execution
111 * @param eventName
112 * - a event name
113 * @param logLevelType
114 * - a log level type
115 * @param level
116 * - a log level
117 * @param filterExpression
118 * - a filter expression
119 * @param monitor
120 * - a progress monitor
121 * @throws ExecutionException
122 * If the command fails for some reason
123 */
124 abstract public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException;
125
126 /**
127 * @param param
128 * - a parameter instance with data for the command execution
129 * @return returns the relevant domain (null if domain is not known)
130 */
131 abstract TraceDomainComponent getDomain(CommandParameter param);
132
133 /*
134 * (non-Javadoc)
135 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
136 */
137 @Override
138 public Object execute(ExecutionEvent event) throws ExecutionException {
139
140 final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
141
142 if (window == null) {
143 return false;
144 }
145 fLock.lock();
146 try {
147 // Make a copy for thread safety
148 final CommandParameter param = fParam.clone();
149
150 TargetNodeComponent node = param.getSession().getTargetNode();
151 List<ITraceControlComponent> providers = node.getChildren(TraceProviderGroup.class);
152
153 final IEnableEventsDialog dialog = TraceControlDialogFactory.getInstance().getEnableEventsDialog();
154 dialog.setTraceProviderGroup((TraceProviderGroup)providers.get(0));
155 dialog.setTraceDomainComponent(getDomain(param));
156
157 if (dialog.open() != Window.OK) {
158 return null;
159 }
160
161 Job job = new Job(Messages.TraceControl_ChangeEventStateJob) {
162 @Override
163 protected IStatus run(IProgressMonitor monitor) {
164 Exception error = null;
165
166 try {
167 String filter = dialog.getFilterExpression();
168
169 // Enable tracepoint events
170 if (dialog.isTracepoints()) {
171 if (dialog.isAllTracePoints()) {
172 enableEvents(param, null, dialog.isKernel(), filter, monitor);
173 } else {
174 List<String> eventNames = dialog.getEventNames();
175 if (!eventNames.isEmpty()) {
176 enableEvents(param, eventNames, dialog.isKernel(), filter, monitor);
177 }
178 }
179 }
180
181 // Enable syscall events
182 if (dialog.isAllSysCalls()) {
183 enableSyscalls(param, monitor);
184 }
185
186 // Enable dynamic probe
187 if (dialog.isDynamicProbe() && (dialog.getProbeEventName() != null) && (dialog.getProbeName() != null)) {
188 enableProbe(param, dialog.getProbeEventName(), false, dialog.getProbeName(), monitor);
189 }
190
191 // Enable dynamic function probe
192 if (dialog.isDynamicFunctionProbe() && (dialog.getFunctionEventName() != null) && (dialog.getFunction() != null)) {
193 enableProbe(param, dialog.getFunctionEventName(), true, dialog.getFunction(), monitor);
194 }
195
196 // Enable event using a wildcard
197 if (dialog.isWildcard()) {
198 List<String> eventNames = dialog.getEventNames();
199 eventNames.add(dialog.getWildcard());
200
201 if (!eventNames.isEmpty()) {
202 enableEvents(param, eventNames, dialog.isKernel(), filter, monitor);
203 }
204 }
205
206 // Enable events using log level
207 if (dialog.isLogLevel()) {
208 enableLogLevel(param, dialog.getLogLevelEventName(), dialog.getLogLevelType(), dialog.getLogLevel(), filter, monitor);
209 }
210
211 } catch (ExecutionException e) {
212 error = e;
213 }
214
215 // refresh in all cases
216 refresh(param);
217
218 if (error != null) {
219 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ChangeEventStateFailure, error);
220 }
221 return Status.OK_STATUS;
222 }
223 };
224 job.setUser(true);
225 job.schedule();
226 } finally {
227 fLock.unlock();
228 }
229 return null;
230 }
231 }
This page took 0.036369 seconds and 5 git commands to generate.