Add support for LTTng 2.0 command add-context
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / handlers / AddContextOnChannelHandler.java
CommitLineData
b793fbe1
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 **********************************************************************/
12package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
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;
21import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
22import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
23import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
24import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
25import org.eclipse.ui.IWorkbenchPage;
26
27/**
28 * <b><u>AddContextOnChannelHandler</u></b>
29 * <p>
30 * Command handler implementation to add contexts to a given channel and all of its events.
31 * </p>
32 */
33public class AddContextOnChannelHandler extends BaseAddContextHandler {
34
35 // ------------------------------------------------------------------------
36 // Attributes
37 // ------------------------------------------------------------------------
38
39 // ------------------------------------------------------------------------
40 // Operations
41 // ------------------------------------------------------------------------
42 /*
43 * (non-Javadoc)
44 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseAddContextHandler#addContexts(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
45 */
46 @Override
47 public void addContexts(CommandParameter param, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
48 if (param instanceof ChannelCommandParameter) {
49 TraceChannelComponent channel = ((ChannelCommandParameter)param).getChannel();
50 channel.addContexts(contextNames, monitor);
51 }
52 }
53
54 /*
55 * (non-Javadoc)
56 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
57 */
58 @Override
59 public boolean isEnabled() {
60 // Get workbench page for the Control View
61 IWorkbenchPage page = getWorkbenchPage();
62 if (page == null) {
63 return false;
64 }
65
66 TraceChannelComponent channel = null;
67 TraceSessionComponent session = null;
68 ISelection selection = page.getSelection(ControlView.ID);
69 if (selection instanceof StructuredSelection) {
70 StructuredSelection structered = ((StructuredSelection) selection);
71 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
72 Object element = (Object) iterator.next();
73 if (element instanceof TraceChannelComponent) {
74 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
75 TraceChannelComponent tmpChannel = (TraceChannelComponent) element;
76 session = tmpChannel.getSession();
77 if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
78 channel = tmpChannel;
79 }
80 }
81 }
82 }
83
84 boolean isEnabled = (channel != null);
85 fLock.lock();
86 try {
87 fParam = null;
88 if(isEnabled) {
89 fParam = new ChannelCommandParameter(session, channel);
90 }
91 } finally {
92 fLock.unlock();
93 }
94 return isEnabled;
95 }
96}
This page took 0.034301 seconds and 5 git commands to generate.