gdbtrace: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui / src / org / eclipse / linuxtools / internal / lttng2 / control / ui / views / handlers / AddContextOnChannelHandler.java
CommitLineData
b793fbe1 1/**********************************************************************
11252342 2 * Copyright (c) 2012, 2013 Ericsson
cfdb727a 3 *
b793fbe1
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:
b793fbe1
BH
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
8e8c0226 12package org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers;
b793fbe1
BH
13
14import java.util.Iterator;
15import java.util.List;
16
17import org.eclipse.core.commands.ExecutionException;
18import org.eclipse.core.runtime.IProgressMonitor;
19import org.eclipse.jface.viewers.ISelection;
20import org.eclipse.jface.viewers.StructuredSelection;
8e8c0226
AM
21import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
22import org.eclipse.linuxtools.internal.lttng2.control.ui.views.ControlView;
23import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceChannelComponent;
24import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
b793fbe1
BH
25import org.eclipse.ui.IWorkbenchPage;
26
27/**
b793fbe1
BH
28 * <p>
29 * Command handler implementation to add contexts to a given channel and all of its events.
30 * </p>
cfdb727a 31 *
dbd4432d 32 * @author Bernd Hufmann
b793fbe1
BH
33 */
34public class AddContextOnChannelHandler extends BaseAddContextHandler {
35
36 // ------------------------------------------------------------------------
37 // Attributes
38 // ------------------------------------------------------------------------
cfdb727a 39
b793fbe1
BH
40 // ------------------------------------------------------------------------
41 // Operations
42 // ------------------------------------------------------------------------
11252342 43
b793fbe1
BH
44 @Override
45 public void addContexts(CommandParameter param, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
46 if (param instanceof ChannelCommandParameter) {
47 TraceChannelComponent channel = ((ChannelCommandParameter)param).getChannel();
48 channel.addContexts(contextNames, monitor);
49 }
50 }
51
b793fbe1
BH
52 @Override
53 public boolean isEnabled() {
54 // Get workbench page for the Control View
55 IWorkbenchPage page = getWorkbenchPage();
56 if (page == null) {
57 return false;
58 }
59
60 TraceChannelComponent channel = null;
61 TraceSessionComponent session = null;
62 ISelection selection = page.getSelection(ControlView.ID);
63 if (selection instanceof StructuredSelection) {
64 StructuredSelection structered = ((StructuredSelection) selection);
65 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
cfdb727a 66 Object element = iterator.next();
b793fbe1
BH
67 if (element instanceof TraceChannelComponent) {
68 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
cfdb727a 69 TraceChannelComponent tmpChannel = (TraceChannelComponent) element;
b793fbe1
BH
70 session = tmpChannel.getSession();
71 if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
72 channel = tmpChannel;
73 }
74 }
75 }
76 }
cfdb727a 77
b793fbe1
BH
78 boolean isEnabled = (channel != null);
79 fLock.lock();
80 try {
81 fParam = null;
82 if(isEnabled) {
83 fParam = new ChannelCommandParameter(session, channel);
84 }
85 } finally {
86 fLock.unlock();
87 }
88 return isEnabled;
89 }
90}
This page took 0.049196 seconds and 5 git commands to generate.