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