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; | |
115b4a01 BH |
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.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>EnableEventOnDomainHandler</u></b> | |
31 | * <p> | |
32 | * Command handler implementation to enable events for a known domain and default channel 'channel0' | |
33 | * (which will be created if doesn't exist). | |
34 | * </p> | |
35 | */ | |
36 | public class EnableEventOnDomainHandler extends BaseEnableEventHandler { | |
37 | ||
38 | // ------------------------------------------------------------------------ | |
39 | // Attributes | |
40 | // ------------------------------------------------------------------------ | |
498704b3 BH |
41 | |
42 | // ------------------------------------------------------------------------ | |
43 | // Operations | |
44 | // ------------------------------------------------------------------------ | |
45 | /* | |
46 | * (non-Javadoc) | |
c56972bb | 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) |
498704b3 BH |
48 | */ |
49 | @Override | |
c56972bb BH |
50 | public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { |
51 | if (param instanceof DomainCommandParameter) { | |
52 | ((DomainCommandParameter)param).getDomain().enableEvents(eventNames, monitor); | |
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 DomainCommandParameter) { | |
63 | ((DomainCommandParameter)param).getDomain().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 DomainCommandParameter) { | |
74 | ((DomainCommandParameter)param).getDomain().enableProbe(eventName, isFunction, probe, monitor); | |
75 | } | |
498704b3 BH |
76 | } |
77 | ||
ccc66d01 BH |
78 | /* |
79 | * (non-Javadoc) | |
c56972bb | 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) |
ccc66d01 BH |
81 | */ |
82 | @Override | |
c56972bb BH |
83 | public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException { |
84 | if (param instanceof DomainCommandParameter) { | |
85 | ((DomainCommandParameter)param).getDomain().enableLogLevel(eventName, logLevelType, level, monitor); | |
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 DomainCommandParameter) { | |
96 | return ((DomainCommandParameter)param).getDomain(); | |
97 | } | |
98 | return null; | |
ccc66d01 | 99 | } |
c56972bb | 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 | TraceDomainComponent domain = 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();) { | |
119 | Object element = (Object) iterator.next(); | |
120 | if (element instanceof TraceDomainComponent) { | |
ccc66d01 | 121 | // Add only if corresponding TraceSessionComponents is inactive and not destroyed |
c56972bb BH |
122 | TraceDomainComponent tmpDomain = (TraceDomainComponent) element; |
123 | session = tmpDomain.getSession(); | |
ccc66d01 | 124 | if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) { |
c56972bb | 125 | domain = tmpDomain; |
498704b3 BH |
126 | } |
127 | } | |
128 | } | |
129 | } | |
c56972bb BH |
130 | |
131 | boolean isEnabled = (domain != null); | |
132 | fLock.lock(); | |
133 | try { | |
134 | fParam = null; | |
135 | if(isEnabled) { | |
136 | fParam = new DomainCommandParameter(session, domain); | |
137 | } | |
138 | } finally { | |
139 | fLock.unlock(); | |
140 | } | |
141 | return isEnabled; | |
498704b3 BH |
142 | } |
143 | } |