Commit | Line | Data |
---|---|---|
498704b3 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 | **********************************************************************/ | |
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.TraceDomainComponent; | |
24 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent; | |
25 | import org.eclipse.ui.IWorkbenchPage; | |
26 | ||
27 | /** | |
28 | * <b><u>EnableEventOnDomainHandler</u></b> | |
29 | * <p> | |
30 | * Command handler implementation to enable events for a known domain and default channel 'channel0' | |
31 | * (which will be created if doesn't exist). | |
32 | * </p> | |
33 | */ | |
34 | public class EnableEventOnDomainHandler extends BaseEnableEventHandler { | |
35 | ||
36 | // ------------------------------------------------------------------------ | |
37 | // Attributes | |
38 | // ------------------------------------------------------------------------ | |
39 | /** | |
40 | * The domain component the command is to be executed on. | |
41 | */ | |
42 | private TraceDomainComponent fDomain = null; | |
43 | ||
44 | // ------------------------------------------------------------------------ | |
45 | // Operations | |
46 | // ------------------------------------------------------------------------ | |
47 | /* | |
48 | * (non-Javadoc) | |
49 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableEvents(java.util.List, org.eclipse.core.runtime.IProgressMonitor) | |
50 | */ | |
51 | @Override | |
52 | void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException { | |
53 | fDomain.enableEvents(eventNames, monitor); | |
54 | } | |
55 | ||
56 | /* | |
57 | * (non-Javadoc) | |
58 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableSyscalls(org.eclipse.core.runtime.IProgressMonitor) | |
59 | */ | |
60 | @Override | |
61 | void enableSyscalls(IProgressMonitor monitor) throws ExecutionException { | |
62 | fDomain.enableSyscalls(monitor); | |
63 | } | |
64 | ||
65 | /* | |
66 | * (non-Javadoc) | |
67 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableProbe(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
68 | */ | |
69 | @Override | |
70 | void enableProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException { | |
71 | fDomain.enableProbe(eventName, probe, monitor); | |
72 | } | |
73 | ||
74 | /* | |
75 | * (non-Javadoc) | |
76 | * @see org.eclipse.linuxtools.lttng.ui.views.control.handlers.BaseEnableEventHandler#enableFunctionProbe(java.lang.String, java.lang.String, org.eclipse.core.runtime.IProgressMonitor) | |
77 | */ | |
78 | @Override | |
79 | void enableFunctionProbe(String eventName, String probe, IProgressMonitor monitor) throws ExecutionException { | |
80 | fDomain.enableFunctionProbe(eventName, probe, monitor); | |
81 | } | |
82 | ||
83 | /* | |
84 | * (non-Javadoc) | |
85 | * @see org.eclipse.core.commands.AbstractHandler#isEnabled() | |
86 | */ | |
87 | @Override | |
88 | public boolean isEnabled() { | |
89 | // Get workbench page for the Control View | |
90 | IWorkbenchPage page = getWorkbenchPage(); | |
91 | if (page == null) { | |
92 | return false; | |
93 | } | |
94 | ||
95 | fDomain = null; | |
96 | ISelection selection = page.getSelection(ControlView.ID); | |
97 | if (selection instanceof StructuredSelection) { | |
98 | StructuredSelection structered = ((StructuredSelection) selection); | |
99 | for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) { | |
100 | Object element = (Object) iterator.next(); | |
101 | if (element instanceof TraceDomainComponent) { | |
102 | // Add only TraceSessionComponents is inactive and not destroyed | |
103 | TraceDomainComponent domain = (TraceDomainComponent) element; | |
104 | TraceSessionComponent session = domain.getSession(); | |
105 | if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed() && domain.isKernel()) { | |
106 | fDomain = domain; | |
107 | fSession = session; | |
108 | } | |
109 | } | |
110 | } | |
111 | } | |
112 | return fDomain != null; | |
113 | } | |
114 | } |