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 / EnableEventOnChannelHandler.java
CommitLineData
498704b3
BH
1/**********************************************************************
2 * Copyright (c) 2012 Ericsson
cfdb727a 3 *
498704b3
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:
498704b3
BH
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
115b4a01 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
498704b3
BH
13
14import java.util.Iterator;
15import java.util.List;
16
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.runtime.IProgressMonitor;
19import org.eclipse.jface.viewers.ISelection;
20import org.eclipse.jface.viewers.StructuredSelection;
9315aeee
BH
21import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
22import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
115b4a01 23import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
115b4a01
BH
24import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
25import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
26import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
498704b3
BH
27import org.eclipse.ui.IWorkbenchPage;
28
29/**
498704b3
BH
30 * <p>
31 * Command handler implementation to enable events for a known channel.
32 * </p>
cfdb727a 33 *
dbd4432d 34 * @author Bernd Hufmann
498704b3
BH
35 */
36public class EnableEventOnChannelHandler extends BaseEnableEventHandler {
37
38 // ------------------------------------------------------------------------
39 // Attributes
40 // ------------------------------------------------------------------------
498704b3
BH
41
42 // ------------------------------------------------------------------------
43 // Operations
44 // ------------------------------------------------------------------------
45 /*
46 * (non-Javadoc)
d4514365 47 * @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)
498704b3
BH
48 */
49 @Override
d4514365 50 public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExression, IProgressMonitor monitor) throws ExecutionException {
c56972bb 51 if (param instanceof ChannelCommandParameter) {
d4514365 52 ((ChannelCommandParameter)param).getChannel().enableEvents(eventNames, filterExression, monitor);
c56972bb 53 }
498704b3
BH
54 }
55
56 /*
57 * (non-Javadoc)
c56972bb 58 * @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)
498704b3
BH
59 */
60 @Override
c56972bb
BH
61 public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException {
62 if (param instanceof ChannelCommandParameter) {
63 ((ChannelCommandParameter)param).getChannel().enableSyscalls(monitor);
64 }
498704b3
BH
65 }
66
67 /*
68 * (non-Javadoc)
c56972bb 69 * @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)
498704b3
BH
70 */
71 @Override
c56972bb
BH
72 public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
73 if (param instanceof ChannelCommandParameter) {
74 ((ChannelCommandParameter)param).getChannel().enableProbe(eventName, isFunction, probe, monitor);
75 }
498704b3
BH
76 }
77
ccc66d01
BH
78 /*
79 * (non-Javadoc)
d4514365 80 * @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)
ccc66d01
BH
81 */
82 @Override
d4514365 83 public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExression, IProgressMonitor monitor) throws ExecutionException {
c56972bb 84 if (param instanceof ChannelCommandParameter) {
d4514365 85 ((ChannelCommandParameter)param).getChannel().enableLogLevel(eventName, logLevelType, level, filterExression, monitor);
c56972bb 86 }
ccc66d01
BH
87 }
88
89 /*
90 * (non-Javadoc)
c56972bb 91 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter)
ccc66d01
BH
92 */
93 @Override
c56972bb
BH
94 public TraceDomainComponent getDomain(CommandParameter param) {
95 if (param instanceof ChannelCommandParameter) {
96 return (TraceDomainComponent) ((ChannelCommandParameter)param).getChannel().getParent();
cfdb727a 97 }
c56972bb 98 return null;
ccc66d01
BH
99 }
100
498704b3
BH
101 /*
102 * (non-Javadoc)
103 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
104 */
105 @Override
106 public boolean isEnabled() {
107 // Get workbench page for the Control View
108 IWorkbenchPage page = getWorkbenchPage();
109 if (page == null) {
110 return false;
111 }
112
c56972bb
BH
113 TraceChannelComponent channel = null;
114 TraceSessionComponent session = null;
498704b3
BH
115 ISelection selection = page.getSelection(ControlView.ID);
116 if (selection instanceof StructuredSelection) {
117 StructuredSelection structered = ((StructuredSelection) selection);
118 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
cfdb727a 119 Object element = iterator.next();
498704b3 120 if (element instanceof TraceChannelComponent) {
ccc66d01 121 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
cfdb727a 122 TraceChannelComponent tmpChannel = (TraceChannelComponent) element;
c56972bb 123 session = tmpChannel.getSession();
f455db37 124 if(!session.isDestroyed()) {
c56972bb 125 channel = tmpChannel;
ccc66d01 126 }
498704b3
BH
127 }
128 }
129 }
cfdb727a 130
c56972bb
BH
131 boolean isEnabled = (channel != null);
132 fLock.lock();
133 try {
134 fParam = null;
135 if(isEnabled) {
136 fParam = new ChannelCommandParameter(session, channel);
137 }
138 } finally {
139 fLock.unlock();
140 }
141 return isEnabled;
498704b3 142 }
498704b3 143}
c56972bb 144
This page took 0.050956 seconds and 5 git commands to generate.