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