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