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