Add support for filter feature of LTTng Tools 2.1
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / EnableEventOnSessionHandler.java
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 **********************************************************************/
12 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
13
14 import java.util.Iterator;
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
22 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
23 import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
24 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
25 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
26 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
27 import org.eclipse.ui.IWorkbenchPage;
28
29 /**
30 * <p>
31 * Command handler implementation to enable events for a known session and default channel 'channel0'
32 * (which will be created if doesn't exist).
33 * </p>
34 *
35 * @author Bernd Hufmann
36 */
37 public class EnableEventOnSessionHandler extends BaseEnableEventHandler {
38
39 // ------------------------------------------------------------------------
40 // Attributes
41 // ------------------------------------------------------------------------
42
43 //-------------------------------------------------------------------------
44 // Operations
45 // ------------------------------------------------------------------------
46 /*
47 * (non-Javadoc)
48 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
49 */
50 @Override
51 public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
52 param.getSession().enableEvents(eventNames, isKernel, filterExpression, monitor);
53 }
54
55 /*
56 * (non-Javadoc)
57 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, org.eclipse.core.runtime.IProgressMonitor)
58 */
59 @Override
60 public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException {
61 param.getSession().enableSyscalls(monitor);
62 }
63
64 /*
65 * (non-Javadoc)
66 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, boolean, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
67 */
68 @Override
69 public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
70 param.getSession().enableProbe(eventName, isFunction, probe, monitor);
71 }
72
73 /*
74 * (non-Javadoc)
75 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#enableLogLevel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.lang.String, org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
76 */
77 @Override
78 public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
79 param.getSession().enableLogLevel(eventName, logLevelType, level, filterExpression, monitor);
80 }
81
82 /*
83 * (non-Javadoc)
84 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter)
85 */
86 @Override
87 public TraceDomainComponent getDomain(CommandParameter param) {
88 return null;
89 }
90
91 /*
92 * (non-Javadoc)
93 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
94 */
95 @Override
96 public boolean isEnabled() {
97 // Get workbench page for the Control View
98 IWorkbenchPage page = getWorkbenchPage();
99 if (page == null) {
100 return false;
101 }
102
103 TraceSessionComponent session = null;
104 // Check if one session is selected
105 ISelection selection = page.getSelection(ControlView.ID);
106 if (selection instanceof StructuredSelection) {
107 StructuredSelection structered = ((StructuredSelection) selection);
108 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
109 Object element = iterator.next();
110 if (element instanceof TraceSessionComponent) {
111 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
112 TraceSessionComponent tmpSession = (TraceSessionComponent) element;
113 if(tmpSession.getSessionState() == TraceSessionState.INACTIVE && !tmpSession.isDestroyed()) {
114 session = tmpSession;
115 }
116 }
117 }
118 }
119 boolean isEnabled = (session != null);
120 fLock.lock();
121 try {
122 fParam = null;
123 if(isEnabled) {
124 fParam = new CommandParameter(session);
125 }
126 } finally {
127 fLock.unlock();
128 }
129 return isEnabled;
130 }
131 }
This page took 0.032976 seconds and 5 git commands to generate.