Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / handlers / EnableEventOnSessionHandler.java
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 **********************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.views.control.handlers;
13
14 import java.util.Iterator;
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.linuxtools.lttng.ui.views.control.ControlView;
22 import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState;
23 import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent;
24 import org.eclipse.ui.IWorkbenchPage;
25
26 /**
27 * <b><u>EnableEventOnSessionHandler</u></b>
28 * <p>
29 * Command handler implementation to enable events for a known session and default channel 'channel0'
30 * (which will be created if doesn't exist).
31 * </p>
32 */
33 public class EnableEventOnSessionHandler extends BaseEnableEventHandler {
34
35 // ------------------------------------------------------------------------
36 // Attributes
37 // ------------------------------------------------------------------------
38
39 //-------------------------------------------------------------------------
40 // Operations
41 // ------------------------------------------------------------------------
42 /*
43 * (non-Javadoc)
44 * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(java.util.List, org.eclipse.core.runtime.IProgressMonitor)
45 */
46 @Override
47 void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException {
48 fSession.enableEvents(eventNames, true, monitor);
49 }
50
51 /*
52 * (non-Javadoc)
53 * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.core.runtime.IProgressMonitor)
54 */
55 @Override
56 void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
57 fSession.enableSyscalls(monitor);
58 }
59
60 /*
61 * (non-Javadoc)
62 * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
63 */
64 @Override
65 void enableProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException {
66 fSession.enableProbe(eventName, probe, monitor);
67 }
68
69 /*
70 * (non-Javadoc)
71 * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableFunctionProbe(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
72 */
73 @Override
74 void enableFunctionProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException {
75 fSession.enableFunctionProbe(eventName, probe, monitor);
76 }
77
78 /*
79 * (non-Javadoc)
80 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
81 */
82 @Override
83 public boolean isEnabled() {
84 // Get workbench page for the Control View
85 IWorkbenchPage page = getWorkbenchPage();
86 if (page == null) {
87 return false;
88 }
89
90 fSession = null;
91
92 // Check if one session is selected
93 ISelection selection = page.getSelection(ControlView.ID);
94 if (selection instanceof StructuredSelection) {
95 StructuredSelection structered = ((StructuredSelection) selection);
96 for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
97 Object element = (Object) iterator.next();
98 if (element instanceof TraceSessionComponent) {
99 // Add only TraceSessionComponents is inactive and not destroyed
100 TraceSessionComponent session = (TraceSessionComponent) element;
101 if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
102 fSession = session;
103 }
104 }
105 }
106 }
107 return fSession != null;
108 }
109 }
This page took 0.034505 seconds and 6 git commands to generate.