lttng: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / handlers / EnableChannelOnSessionHandler.java
CommitLineData
bbb3538a 1/**********************************************************************
ed902a2b 2 * Copyright (c) 2012, 2014 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 **********************************************************************/
9bc60be7 12package org.eclipse.tracecompass.internal.lttng2.control.ui.views.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;
9bc60be7
AM
21import org.eclipse.tracecompass.internal.lttng2.control.core.model.IChannelInfo;
22import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
23import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
24import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
25import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
bbb3538a 26import 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 36public class EnableChannelOnSessionHandler extends BaseEnableChannelHandler {
bbb3538a
BH
37
38 // ------------------------------------------------------------------------
39 // Attributes
40 // ------------------------------------------------------------------------
11252342 41
c56972bb
BH
42 @Override
43 public void enableChannel(CommandParameter param, List<String> channelNames, IChannelInfo info, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
44 param.getSession().enableChannels(channelNames, info, isKernel, monitor);
45 }
cfdb727a 46
bbb3538a 47 @Override
c56972bb 48 public TraceDomainComponent getDomain(CommandParameter param) {
bbb3538a
BH
49 return null;
50 }
51
c56972bb
BH
52 // ------------------------------------------------------------------------
53 // Operations
54 // ------------------------------------------------------------------------
55
bbb3538a
BH
56 @Override
57 public boolean isEnabled() {
498704b3
BH
58 // Get workbench page for the Control View
59 IWorkbenchPage page = getWorkbenchPage();
bbb3538a
BH
60 if (page == null) {
61 return false;
62 }
63
c56972bb 64 TraceSessionComponent session = null;
bbb3538a
BH
65 // Check if one session is selected
66 ISelection selection = page.getSelection(ControlView.ID);
67 if (selection instanceof StructuredSelection) {
68 StructuredSelection structered = ((StructuredSelection) selection);
69 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
cfdb727a 70 Object element = iterator.next();
bbb3538a
BH
71 if (element instanceof TraceSessionComponent) {
72 // Add only TraceSessionComponents that are inactive and not destroyed
c56972bb
BH
73 TraceSessionComponent tmpSession = (TraceSessionComponent) element;
74 if ((tmpSession.getSessionState() == TraceSessionState.INACTIVE) && (!tmpSession.isDestroyed())) {
75 session = tmpSession;
bbb3538a
BH
76 }
77 }
78 }
79 }
c56972bb 80 boolean isEnabled = session != null;
cfdb727a 81
c56972bb
BH
82 fLock.lock();
83 try {
84 fParam = null;
85 if (isEnabled) {
86 fParam = new CommandParameter(session);
87 }
88 } finally {
89 fLock.unlock();
90 }
cfdb727a 91
c56972bb 92 return isEnabled;
bbb3538a
BH
93 }
94}
This page took 0.080327 seconds and 5 git commands to generate.