Commit | Line | Data |
---|---|---|
bbb3538a 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; |
bbb3538a | 13 | |
bbb3538a BH |
14 | import java.util.Iterator; |
15 | import java.util.List; | |
16 | ||
bbb3538a BH |
17 | import org.eclipse.core.commands.ExecutionException; |
18 | import org.eclipse.core.runtime.IProgressMonitor; | |
bbb3538a BH |
19 | import org.eclipse.jface.viewers.ISelection; |
20 | import org.eclipse.jface.viewers.StructuredSelection; | |
115b4a01 | 21 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView; |
c56972bb | 22 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo; |
115b4a01 BH |
23 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState; |
24 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent; | |
25 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent; | |
bbb3538a | 26 | import org.eclipse.ui.IWorkbenchPage; |
bbb3538a BH |
27 | |
28 | /** | |
d62bfa55 | 29 | * <b><u>EnableChannelOnSessionHandler</u></b> |
bbb3538a | 30 | * <p> |
d62bfa55 | 31 | * Command handler implementation to enable a trace channel for unknown domain |
bbb3538a BH |
32 | * (on session level). |
33 | * </p> | |
34 | */ | |
d62bfa55 | 35 | public class EnableChannelOnSessionHandler extends BaseEnableChannelHandler { |
bbb3538a BH |
36 | |
37 | // ------------------------------------------------------------------------ | |
38 | // Attributes | |
39 | // ------------------------------------------------------------------------ | |
c56972bb BH |
40 | /* |
41 | * (non-Javadoc) | |
42 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseCreateChannelHandler#enableChannel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo, boolean, org.eclipse.core.runtime.IProgressMonitor) | |
bbb3538a | 43 | */ |
c56972bb BH |
44 | @Override |
45 | public void enableChannel(CommandParameter param, List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException { | |
46 | param.getSession().enableChannels(channelNames, info, isKernel, monitor); | |
47 | } | |
48 | ||
bbb3538a BH |
49 | /* |
50 | * (non-Javadoc) | |
c56972bb | 51 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseCreateChannelHandler#getDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter) |
bbb3538a BH |
52 | */ |
53 | @Override | |
c56972bb | 54 | public TraceDomainComponent getDomain(CommandParameter param) { |
bbb3538a BH |
55 | return null; |
56 | } | |
57 | ||
c56972bb BH |
58 | // ------------------------------------------------------------------------ |
59 | // Operations | |
60 | // ------------------------------------------------------------------------ | |
61 | ||
bbb3538a BH |
62 | /* |
63 | * (non-Javadoc) | |
64 | * @see org.eclipse.core.commands.AbstractHandler#isEnabled() | |
65 | */ | |
66 | @Override | |
67 | public boolean isEnabled() { | |
498704b3 BH |
68 | // Get workbench page for the Control View |
69 | IWorkbenchPage page = getWorkbenchPage(); | |
bbb3538a BH |
70 | if (page == null) { |
71 | return false; | |
72 | } | |
73 | ||
c56972bb | 74 | TraceSessionComponent session = null; |
bbb3538a BH |
75 | // Check if one session is selected |
76 | ISelection selection = page.getSelection(ControlView.ID); | |
77 | if (selection instanceof StructuredSelection) { | |
78 | StructuredSelection structered = ((StructuredSelection) selection); | |
79 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
80 | Object element = (Object) iterator.next(); | |
81 | if (element instanceof TraceSessionComponent) { | |
82 | // Add only TraceSessionComponents that are inactive and not destroyed | |
c56972bb BH |
83 | TraceSessionComponent tmpSession = (TraceSessionComponent) element; |
84 | if ((tmpSession.getSessionState() == TraceSessionState.INACTIVE) && (!tmpSession.isDestroyed())) { | |
85 | session = tmpSession; | |
bbb3538a BH |
86 | } |
87 | } | |
88 | } | |
89 | } | |
c56972bb BH |
90 | boolean isEnabled = session != null; |
91 | ||
92 | fLock.lock(); | |
93 | try { | |
94 | fParam = null; | |
95 | if (isEnabled) { | |
96 | fParam = new CommandParameter(session); | |
97 | } | |
98 | } finally { | |
99 | fLock.unlock(); | |
100 | } | |
101 | ||
102 | return isEnabled; | |
bbb3538a BH |
103 | } |
104 | } |