Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / EnableEventOnChannelHandler.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.ui.views.control.ControlView;
22 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.LogLevelType;
23 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel;
24 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
25 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
26 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
27 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
28 import org.eclipse.ui.IWorkbenchPage;
29
30 /**
31 * <b><u>EnableEventOnChannelHandler</u></b>
32 * <p>
33 * Command handler implementation to enable events for a known channel.
34 * </p>
35 */
36 public class EnableEventOnChannelHandler extends BaseEnableEventHandler {
37
38 // ------------------------------------------------------------------------
39 // Attributes
40 // ------------------------------------------------------------------------
41
42 // ------------------------------------------------------------------------
43 // Operations
44 // ------------------------------------------------------------------------
45 /*
46 * (non-Javadoc)
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, org.eclipse.core.runtime.IProgressMonitor)
48 */
49 @Override
50 public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
51 if (param instanceof ChannelCommandParameter) {
52 ((ChannelCommandParameter)param).getChannel().enableEvents(eventNames, monitor);
53 }
54 }
55
56 /*
57 * (non-Javadoc)
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)
59 */
60 @Override
61 public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException {
62 if (param instanceof ChannelCommandParameter) {
63 ((ChannelCommandParameter)param).getChannel().enableSyscalls(monitor);
64 }
65 }
66
67 /*
68 * (non-Javadoc)
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)
70 */
71 @Override
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 }
76 }
77
78 /*
79 * (non-Javadoc)
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.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor)
81 */
82 @Override
83 public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
84 if (param instanceof ChannelCommandParameter) {
85 ((ChannelCommandParameter)param).getChannel().enableLogLevel(eventName, logLevelType, level, monitor);
86 }
87 }
88
89 /*
90 * (non-Javadoc)
91 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseEnableEventHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter)
92 */
93 @Override
94 public TraceDomainComponent getDomain(CommandParameter param) {
95 if (param instanceof ChannelCommandParameter) {
96 return (TraceDomainComponent) ((ChannelCommandParameter)param).getChannel().getParent();
97 }
98 return null;
99 }
100
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
113 TraceChannelComponent channel = null;
114 TraceSessionComponent session = null;
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();) {
119 Object element = (Object) iterator.next();
120 if (element instanceof TraceChannelComponent) {
121 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
122 TraceChannelComponent tmpChannel = (TraceChannelComponent) element;
123 session = tmpChannel.getSession();
124 if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
125 channel = tmpChannel;
126 }
127 }
128 }
129 }
130
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;
142 }
143 }
144
This page took 0.047805 seconds and 6 git commands to generate.