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