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 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.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.lttng.ui.views.control.ControlView; | |
ccc66d01 BH |
22 | import org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType; |
23 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel; | |
24 | import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState; | |
498704b3 | 25 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceChannelComponent; |
ccc66d01 BH |
26 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceDomainComponent; |
27 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent; | |
498704b3 BH |
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 | * The channel component the command is to be executed on. | |
43 | */ | |
44 | private TraceChannelComponent fChannel = null; | |
45 | ||
46 | // ------------------------------------------------------------------------ | |
47 | // Operations | |
48 | // ------------------------------------------------------------------------ | |
49 | /* | |
50 | * (non-Javadoc) | |
ccc66d01 | 51 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(java.util.List, boolean, org.eclipse.core.runtime.IProgressMonitor) |
498704b3 BH |
52 | */ |
53 | @Override | |
ccc66d01 | 54 | public void enableEvents(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
498704b3 BH |
55 | fChannel.enableEvents(eventNames, monitor); |
56 | } | |
57 | ||
58 | /* | |
59 | * (non-Javadoc) | |
60 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.core.runtime.IProgressMonitor) | |
61 | */ | |
62 | @Override | |
ccc66d01 | 63 | public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException { |
498704b3 BH |
64 | fChannel.enableSyscalls(monitor); |
65 | } | |
66 | ||
67 | /* | |
68 | * (non-Javadoc) | |
69 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
70 | */ | |
71 | @Override | |
ccc66d01 | 72 | public void enableProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException { |
498704b3 BH |
73 | fChannel.enableProbe(eventName, probe, monitor); |
74 | } | |
75 | ||
76 | /* | |
77 | * (non-Javadoc) | |
78 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableFunctionProbe(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
79 | */ | |
80 | @Override | |
ccc66d01 | 81 | public void enableFunctionProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException { |
498704b3 BH |
82 | fChannel.enableFunctionProbe(eventName, probe, monitor); |
83 | } | |
84 | ||
ccc66d01 BH |
85 | /* |
86 | * (non-Javadoc) | |
87 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableLogLevel(java.lang.String, org.eclipse.linuxtools.lttng.ui.views.control.model.LogLevelType, org.eclipse.linuxtools.lttng.ui.views.control.model.TraceLogLevel, org.eclipse.core.runtime.IProgressMonitor) | |
88 | */ | |
89 | @Override | |
90 | public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException { | |
91 | fChannel.enableLogLevel(eventName, logLevelType, level, monitor); | |
92 | } | |
93 | ||
94 | /* | |
95 | * (non-Javadoc) | |
96 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#getDomain() | |
97 | */ | |
98 | @Override | |
99 | public TraceDomainComponent getDomain() { | |
100 | return (TraceDomainComponent) fChannel.getParent(); | |
101 | } | |
102 | ||
498704b3 BH |
103 | /* |
104 | * (non-Javadoc) | |
105 | * @see org.eclipse.core.commands.AbstractHandler#isEnabled() | |
106 | */ | |
107 | @Override | |
108 | public boolean isEnabled() { | |
109 | // Get workbench page for the Control View | |
110 | IWorkbenchPage page = getWorkbenchPage(); | |
111 | if (page == null) { | |
112 | return false; | |
113 | } | |
114 | ||
115 | fChannel = null; | |
116 | ISelection selection = page.getSelection(ControlView.ID); | |
117 | if (selection instanceof StructuredSelection) { | |
118 | StructuredSelection structered = ((StructuredSelection) selection); | |
119 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
120 | Object element = (Object) iterator.next(); | |
121 | if (element instanceof TraceChannelComponent) { | |
ccc66d01 BH |
122 | // Add only if corresponding TraceSessionComponents is inactive and not destroyed |
123 | TraceChannelComponent channel = (TraceChannelComponent) element; | |
124 | TraceSessionComponent session = channel.getSession(); | |
125 | if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) { | |
126 | fChannel = channel; | |
127 | fSession = session; | |
128 | } | |
498704b3 BH |
129 | } |
130 | } | |
131 | } | |
132 | return fChannel != null; | |
133 | } | |
134 | ||
135 | } |