1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
;
14 import java
.util
.List
;
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
;
30 * <b><u>TraceSessionComponent</u></b>
32 * Implementation of the trace session component.
35 public class TraceSessionComponent
extends TraceControlComponent
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
41 * Path to icon file for this component (inactive state).
43 public static final String TRACE_SESSION_ICON_FILE_INACTIVE
= "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
45 * Path to icon file for this component (active state).
47 public static final String TRACE_SESSION_ICON_FILE_ACTIVE
= "icons/obj16/session_active.gif"; //$NON-NLS-1$
49 * Path to icon file for this component (destroyed state).
51 public static final String TRACE_SESSION_ICON_FILE_DESTROYED
= "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 * The session information.
59 private ISessionInfo fSessionInfo
= null;
61 * A flag to indicate if session has been destroyed.
63 private boolean fIsDestroyed
= false;
65 * The image to be displayed in state active.
67 private Image fActiveImage
= null;
69 * The image to be displayed in state destroyed
71 private Image fDestroyedImage
= null;
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
78 * @param name - the name of the component.
79 * @param parent - the parent of this component.
81 public TraceSessionComponent(String name
, ITraceControlComponent 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
);
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
95 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage()
98 public Image
getImage() {
100 return fDestroyedImage
;
103 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
104 return super.getImage();
111 * @return the whether the session is destroyed or not.
113 public boolean isDestroyed() {
118 * Sets the session destroyed state to the given value.
119 * @param destroyed - value to set.
121 public void setDestroyed(boolean destroyed
) {
122 fIsDestroyed
= destroyed
;
126 * @return the session state state (active or inactive).
128 public TraceSessionState
getSessionState() {
129 return fSessionInfo
.getSessionState();
133 * Sets the session state to the given value.
134 * @param state - state to set.
136 public void setSessionState(TraceSessionState state
) {
137 fSessionInfo
.setSessionState(state
);
141 * Sets the event state to the value specified by the given name.
142 * @param stateName - state to set.
144 public void setSessionState(String stateName
) {
145 fSessionInfo
.setSessionState(stateName
);
149 * @return path string where session is located.
151 public String
getSessionPath() {
152 return fSessionInfo
.getSessionPath();
156 * Sets the path string (where session is located) to the given value.
157 * @param path - session path to set.
159 public void setSessionPath(String sessionPath
) {
160 fSessionInfo
.setSessionPath(sessionPath
);
165 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
167 @SuppressWarnings("rawtypes")
169 public Object
getAdapter(Class adapter
) {
170 if (adapter
== IPropertySource
.class) {
171 return new TraceSessionPropertySource(this);
177 * @return all available domains of this session.
179 public TraceDomainComponent
[] getDomains() {
180 List
<ITraceControlComponent
> sessions
= getChildren(TraceDomainComponent
.class);
181 return (TraceDomainComponent
[])sessions
.toArray(new TraceDomainComponent
[sessions
.size()]);
184 // ------------------------------------------------------------------------
186 // ------------------------------------------------------------------------
188 * Retrieves the session configuration from the node.
189 * @throws ExecutionException
191 public void getConfigurationFromNode() throws ExecutionException
{
192 getConfigurationFromNode(new NullProgressMonitor());
196 * Retrieves the session configuration from the node.
197 * @param monitor - a progress monitor
198 * @throws ExecutionException
200 public void getConfigurationFromNode(IProgressMonitor monitor
) throws ExecutionException
{
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
]);
212 * Starts the session.
213 * throws ExecutionExecption
215 public void startSession() throws ExecutionException
{
216 startSession(new NullProgressMonitor());
220 * Starts the session.
221 * @param monitor - a progress monitor
222 * throws ExecutionExecption
224 public void startSession(IProgressMonitor monitor
) throws ExecutionException
{
225 getControlService().startSession(getName(), monitor
);
229 * Starts the session.
230 * throws ExecutionExecption
232 public void stopSession() throws ExecutionException
{
233 startSession(new NullProgressMonitor());
237 * Starts the session.
238 * @param monitor - a progress monitor
239 * throws ExecutionExecption
241 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
242 getControlService().stopSession(getName(), monitor
);
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
251 public void enableEvent(List
<String
> eventNames
, boolean isKernel
) throws ExecutionException
{
252 enableEvent(eventNames
, isKernel
, new NullProgressMonitor());
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
262 public void enableEvent(List
<String
> eventNames
, boolean isKernel
, IProgressMonitor monitor
) throws ExecutionException
{
263 getControlService().enableEvent(getName(), null, eventNames
, isKernel
, monitor
);