lttng: Add a diagram showing the dependencies between plugins
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / EnableChannelOnDomainHandler.java
CommitLineData
bbb3538a 1/**********************************************************************
11252342 2 * Copyright (c) 2012, 2013 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 12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
bbb3538a 13
bbb3538a
BH
14import java.util.Iterator;
15import java.util.List;
16
bbb3538a
BH
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.runtime.IProgressMonitor;
bbb3538a
BH
19import org.eclipse.jface.viewers.ISelection;
20import org.eclipse.jface.viewers.StructuredSelection;
9315aeee
BH
21import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
22import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
115b4a01 23import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
115b4a01
BH
24import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
25import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
bbb3538a 26import 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 35public class EnableChannelOnDomainHandler extends BaseEnableChannelHandler {
bbb3538a
BH
36
37 // ------------------------------------------------------------------------
38 // Attributes
39 // ------------------------------------------------------------------------
bbb3538a
BH
40
41 // ------------------------------------------------------------------------
42 // Operations
43 // ------------------------------------------------------------------------
11252342 44
bbb3538a 45 @Override
c56972bb
BH
46 public void enableChannel(CommandParameter param, List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
47 if (param instanceof DomainCommandParameter) {
48 ((DomainCommandParameter)param).getDomain().enableChannels(channelNames, info, monitor);
49 }
50 }
cfdb727a 51
c56972bb
BH
52 @Override
53 public TraceDomainComponent getDomain(CommandParameter param) {
54 if (param instanceof DomainCommandParameter) {
55 return ((DomainCommandParameter)param).getDomain();
6503ae0f 56 }
bbb3538a
BH
57 return null;
58 }
59
bbb3538a
BH
60 @Override
61 public boolean isEnabled() {
cfdb727a 62
498704b3
BH
63 // Get workbench page for the Control View
64 IWorkbenchPage page = getWorkbenchPage();
bbb3538a
BH
65 if (page == null) {
66 return false;
67 }
cfdb727a 68
c56972bb
BH
69 TraceDomainComponent domain = null;
70 TraceSessionComponent session = null;
cfdb727a 71
bbb3538a
BH
72 // Check if one domain is selected
73 ISelection selection = page.getSelection(ControlView.ID);
74 if (selection instanceof StructuredSelection) {
75 StructuredSelection structered = ((StructuredSelection) selection);
76 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
cfdb727a 77 Object element = iterator.next();
bbb3538a 78 if (element instanceof TraceDomainComponent) {
c56972bb
BH
79 TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
80 session = (TraceSessionComponent) tmpDomain.getParent();
cfdb727a 81
bbb3538a
BH
82 // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed
83 if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
c56972bb 84 domain = tmpDomain;
bbb3538a
BH
85 }
86 }
87 }
88 }
cfdb727a 89
c56972bb 90 boolean isEnabled = domain != null;
cfdb727a 91
c56972bb
BH
92 fLock.lock();
93 try {
94 fParam = null;
95 if (isEnabled) {
96 fParam = new DomainCommandParameter(session, domain);
97 }
98 } finally {
99 fLock.unlock();
100 }
cfdb727a 101
c56972bb 102 return isEnabled;
bbb3538a 103 }
cfdb727a 104
bbb3538a 105}
This page took 0.051516 seconds and 5 git commands to generate.