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