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
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 **********************************************************************/
12 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
13
14 import java.util.Iterator;
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.tracecompass.internal.lttng2.control.core.model.IChannelInfo;
22 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
23 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
24 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
25 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
26 import org.eclipse.ui.IWorkbenchPage;
27
28 /**
29 * <p>
30 * Command handler implementation to enable a trace channel for unknown domain
31 * (on session level).
32 * </p>
33 *
34 * @author Bernd Hufmann
35 */
36 public class EnableChannelOnSessionHandler extends BaseEnableChannelHandler {
37
38 // ------------------------------------------------------------------------
39 // Attributes
40 // ------------------------------------------------------------------------
41
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 }
46
47 @Override
48 public TraceDomainComponent getDomain(CommandParameter param) {
49 return null;
50 }
51
52 // ------------------------------------------------------------------------
53 // Operations
54 // ------------------------------------------------------------------------
55
56 @Override
57 public boolean isEnabled() {
58 // Get workbench page for the Control View
59 IWorkbenchPage page = getWorkbenchPage();
60 if (page == null) {
61 return false;
62 }
63
64 TraceSessionComponent session = null;
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();) {
70 Object element = iterator.next();
71 if (element instanceof TraceSessionComponent) {
72 // Add only TraceSessionComponents that are inactive and not destroyed
73 TraceSessionComponent tmpSession = (TraceSessionComponent) element;
74 if ((tmpSession.getSessionState() == TraceSessionState.INACTIVE) && (!tmpSession.isDestroyed())) {
75 session = tmpSession;
76 }
77 }
78 }
79 }
80 boolean isEnabled = session != null;
81
82 fLock.lock();
83 try {
84 fParam = null;
85 if (isEnabled) {
86 fParam = new CommandParameter(session);
87 }
88 } finally {
89 fLock.unlock();
90 }
91
92 return isEnabled;
93 }
94 }
This page took 0.033511 seconds and 5 git commands to generate.