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