Added command support for enabling/disabling events (first part)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / control / model / impl / TraceSessionComponent.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.model.impl;
13
14 import java.util.List;
15
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.NullProgressMonitor;
19 import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin;
20 import org.eclipse.linuxtools.lttng.ui.views.control.Messages;
21 import org.eclipse.linuxtools.lttng.ui.views.control.model.IDomainInfo;
22 import org.eclipse.linuxtools.lttng.ui.views.control.model.ISessionInfo;
23 import org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent;
24 import org.eclipse.linuxtools.lttng.ui.views.control.model.TraceSessionState;
25 import org.eclipse.linuxtools.lttng.ui.views.control.property.TraceSessionPropertySource;
26 import org.eclipse.swt.graphics.Image;
27 import org.eclipse.ui.views.properties.IPropertySource;
28
29 /**
30 * <b><u>TraceSessionComponent</u></b>
31 * <p>
32 * Implementation of the trace session component.
33 * </p>
34 */
35 public class TraceSessionComponent extends TraceControlComponent {
36
37 // ------------------------------------------------------------------------
38 // Constants
39 // ------------------------------------------------------------------------
40 /**
41 * Path to icon file for this component (inactive state).
42 */
43 public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
44 /**
45 * Path to icon file for this component (active state).
46 */
47 public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$
48 /**
49 * Path to icon file for this component (destroyed state).
50 */
51 public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
52
53 // ------------------------------------------------------------------------
54 // Attributes
55 // ------------------------------------------------------------------------
56 /**
57 * The session information.
58 */
59 private ISessionInfo fSessionInfo = null;
60 /**
61 * A flag to indicate if session has been destroyed.
62 */
63 private boolean fIsDestroyed = false;
64 /**
65 * The image to be displayed in state active.
66 */
67 private Image fActiveImage = null;
68 /**
69 * The image to be displayed in state destroyed
70 */
71 private Image fDestroyedImage = null;
72
73 // ------------------------------------------------------------------------
74 // Constructors
75 // ------------------------------------------------------------------------
76 /**
77 * Constructor
78 * @param name - the name of the component.
79 * @param parent - the parent of this component.
80 */
81 public TraceSessionComponent(String name, ITraceControlComponent parent) {
82 super(name, parent);
83 setImage(TRACE_SESSION_ICON_FILE_INACTIVE);
84 setToolTip(Messages.TraceControl_SessionDisplayName);
85 fSessionInfo = new SessionInfo(name);
86 fActiveImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE);
87 fDestroyedImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED);
88 }
89
90 // ------------------------------------------------------------------------
91 // Accessors
92 // ------------------------------------------------------------------------
93 /*
94 * (non-Javadoc)
95 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage()
96 */
97 @Override
98 public Image getImage() {
99 if (fIsDestroyed) {
100 return fDestroyedImage;
101 }
102
103 if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) {
104 return super.getImage();
105 }
106
107 return fActiveImage;
108 }
109
110 /**
111 * @return the whether the session is destroyed or not.
112 */
113 public boolean isDestroyed() {
114 return fIsDestroyed;
115 }
116
117 /**
118 * Sets the session destroyed state to the given value.
119 * @param destroyed - value to set.
120 */
121 public void setDestroyed(boolean destroyed) {
122 fIsDestroyed = destroyed;
123 }
124
125 /**
126 * @return the session state state (active or inactive).
127 */
128 public TraceSessionState getSessionState() {
129 return fSessionInfo.getSessionState();
130 }
131
132 /**
133 * Sets the session state to the given value.
134 * @param state - state to set.
135 */
136 public void setSessionState(TraceSessionState state) {
137 fSessionInfo.setSessionState(state);
138 }
139
140 /**
141 * Sets the event state to the value specified by the given name.
142 * @param stateName - state to set.
143 */
144 public void setSessionState(String stateName) {
145 fSessionInfo.setSessionState(stateName);
146 }
147
148 /**
149 * @return path string where session is located.
150 */
151 public String getSessionPath() {
152 return fSessionInfo.getSessionPath();
153 }
154
155 /**
156 * Sets the path string (where session is located) to the given value.
157 * @param path - session path to set.
158 */
159 public void setSessionPath(String sessionPath) {
160 fSessionInfo.setSessionPath(sessionPath);
161 }
162
163 /*
164 * (non-Javadoc)
165 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
166 */
167 @SuppressWarnings("rawtypes")
168 @Override
169 public Object getAdapter(Class adapter) {
170 if (adapter == IPropertySource.class) {
171 return new TraceSessionPropertySource(this);
172 }
173 return null;
174 }
175
176 /**
177 * @return all available domains of this session.
178 */
179 public TraceDomainComponent[] getDomains() {
180 List<ITraceControlComponent> sessions = getChildren(TraceDomainComponent.class);
181 return (TraceDomainComponent[])sessions.toArray(new TraceDomainComponent[sessions.size()]);
182 }
183
184 // ------------------------------------------------------------------------
185 // Operations
186 // ------------------------------------------------------------------------
187 /**
188 * Retrieves the session configuration from the node.
189 * @throws ExecutionException
190 */
191 public void getConfigurationFromNode() throws ExecutionException {
192 getConfigurationFromNode(new NullProgressMonitor());
193 }
194
195 /**
196 * Retrieves the session configuration from the node.
197 * @param monitor - a progress monitor
198 * @throws ExecutionException
199 */
200 public void getConfigurationFromNode(IProgressMonitor monitor) throws ExecutionException {
201 removeAllChildren();
202 fSessionInfo = getControlService().getSession(getName(), monitor);
203 IDomainInfo[] domains = fSessionInfo.getDomains();
204 for (int i = 0; i < domains.length; i++) {
205 TraceDomainComponent domainComponent = new TraceDomainComponent(domains[i].getName(), this);
206 addChild(domainComponent);
207 domainComponent.setDomainInfo(domains[i]);
208 }
209 }
210
211 /**
212 * Starts the session.
213 * throws ExecutionExecption
214 */
215 public void startSession() throws ExecutionException {
216 startSession(new NullProgressMonitor());
217 }
218
219 /**
220 * Starts the session.
221 * @param monitor - a progress monitor
222 * throws ExecutionExecption
223 */
224 public void startSession(IProgressMonitor monitor) throws ExecutionException {
225 getControlService().startSession(getName(), monitor);
226 }
227
228 /**
229 * Starts the session.
230 * throws ExecutionExecption
231 */
232 public void stopSession() throws ExecutionException {
233 startSession(new NullProgressMonitor());
234 }
235
236 /**
237 * Starts the session.
238 * @param monitor - a progress monitor
239 * throws ExecutionExecption
240 */
241 public void stopSession(IProgressMonitor monitor) throws ExecutionException {
242 getControlService().stopSession(getName(), monitor);
243 }
244
245 /**
246 * Enables a list of events with no additional parameters.
247 * @param eventNames - a list of event names to enabled.
248 * @param isKernel - a flag for indicating kernel or UST.
249 * @throws ExecutionException
250 */
251 public void enableEvent(List<String> eventNames, boolean isKernel) throws ExecutionException {
252 enableEvent(eventNames, isKernel, new NullProgressMonitor());
253 }
254
255 /**
256 * Enables a list of events with no additional parameters.
257 * @param eventNames - a list of event names to enabled.
258 * @param isKernel - a flag for indicating kernel or UST.
259 * @param monitor - a progress monitor
260 * @throws ExecutionException
261 */
262 public void enableEvent(List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
263 getControlService().enableEvent(getName(), null, eventNames, isKernel, monitor);
264 }
265 }
This page took 0.059158 seconds and 5 git commands to generate.