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