ctf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / handlers / EnableEventOnSessionHandler.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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
14
15 import java.util.Iterator;
16 import java.util.List;
17
18 import org.eclipse.core.commands.ExecutionException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.StructuredSelection;
22 import org.eclipse.tracecompass.internal.lttng2.control.core.model.LogLevelType;
23 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceLogLevel;
24 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
25 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
26 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceDomainComponent;
27 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
28 import org.eclipse.ui.IWorkbenchPage;
29
30 /**
31 * <p>
32 * Command handler implementation to enable events for a known session and default channel 'channel0'
33 * (which will be created if doesn't exist).
34 * </p>
35 *
36 * @author Bernd Hufmann
37 */
38 public class EnableEventOnSessionHandler extends BaseEnableEventHandler {
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43
44 //-------------------------------------------------------------------------
45 // Operations
46 // ------------------------------------------------------------------------
47
48 @Override
49 public void enableEvents(CommandParameter param, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
50 param.getSession().enableEvents(eventNames, isKernel, filterExpression, monitor);
51 }
52
53 @Override
54 public void enableSyscalls(CommandParameter param, IProgressMonitor monitor) throws ExecutionException {
55 param.getSession().enableSyscalls(monitor);
56 }
57
58 @Override
59 public void enableProbe(CommandParameter param, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
60 param.getSession().enableProbe(eventName, isFunction, probe, monitor);
61 }
62
63 @Override
64 public void enableLogLevel(CommandParameter param, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
65 param.getSession().enableLogLevel(eventName, logLevelType, level, filterExpression, monitor);
66 }
67
68 @Override
69 public TraceDomainComponent getDomain(CommandParameter param) {
70 return null;
71 }
72
73 @Override
74 public boolean isEnabled() {
75 // Get workbench page for the Control View
76 IWorkbenchPage page = getWorkbenchPage();
77 if (page == null) {
78 return false;
79 }
80
81 TraceSessionComponent session = null;
82 // Check if one session is selected
83 ISelection selection = page.getSelection(ControlView.ID);
84 if (selection instanceof StructuredSelection) {
85 StructuredSelection structered = ((StructuredSelection) selection);
86 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
87 Object element = iterator.next();
88 if (element instanceof TraceSessionComponent) {
89 // Add only if corresponding TraceSessionComponents is inactive and not destroyed
90 TraceSessionComponent tmpSession = (TraceSessionComponent) element;
91 if(tmpSession.getSessionState() == TraceSessionState.INACTIVE && !tmpSession.isDestroyed()) {
92 session = tmpSession;
93 }
94 }
95 }
96 }
97 boolean isEnabled = (session != null);
98 fLock.lock();
99 try {
100 fParam = null;
101 if(isEnabled) {
102 fParam = new CommandParameter(session);
103 }
104 } finally {
105 fLock.unlock();
106 }
107 return isEnabled;
108 }
109 }
This page took 0.041996 seconds and 5 git commands to generate.