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 org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
17 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
18 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.Messages
;
19 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.IDomainInfo
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ISessionInfo
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TraceSessionState
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.property
.TraceSessionPropertySource
;
24 import org
.eclipse
.swt
.graphics
.Image
;
25 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
28 * <b><u>TraceSessionComponent</u></b>
30 * Implementation of the trace session component.
33 public class TraceSessionComponent
extends TraceControlComponent
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 * Path to icon file for this component (inactive state).
41 public static final String TRACE_SESSION_ICON_FILE_INACTIVE
= "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
43 * Path to icon file for this component (active state).
45 public static final String TRACE_SESSION_ICON_FILE_ACTIVE
= "icons/obj16/session_active.gif"; //$NON-NLS-1$
47 * Path to icon file for this component (destroyed state).
49 public static final String TRACE_SESSION_ICON_FILE_DESTROYED
= "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 * The session information.
57 private ISessionInfo fSessionInfo
= null;
59 * A flag to indicate if session has been destroyed.
61 private boolean fIsDestroyed
= false;
63 * The image to be displayed in state active.
65 private Image fActiveImage
= null;
67 * The image to be displayed in state destroyed
69 private Image fDestroyedImage
= null;
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 * @param name - the name of the component.
77 * @param parent - the parent of this component.
79 public TraceSessionComponent(String name
, ITraceControlComponent parent
) {
81 setImage(TRACE_SESSION_ICON_FILE_INACTIVE
);
82 setToolTip(Messages
.TraceControl_SessionDisplayName
);
83 fSessionInfo
= new SessionInfo(name
);
84 fActiveImage
= LTTngUiPlugin
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE
);
85 fDestroyedImage
= LTTngUiPlugin
.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED
);
88 // ------------------------------------------------------------------------
90 // ------------------------------------------------------------------------
93 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage()
96 public Image
getImage() {
98 return fDestroyedImage
;
101 if (fSessionInfo
.getSessionState() == TraceSessionState
.INACTIVE
) {
102 return super.getImage();
109 * @return the whether the session is destroyed or not.
111 public boolean isDestroyed() {
116 * Sets the session destroyed state to the given value.
117 * @param destroyed - value to set.
119 public void setDestroyed(boolean destroyed
) {
120 fIsDestroyed
= destroyed
;
124 * @return the session state state (active or inactive).
126 public TraceSessionState
getSessionState() {
127 return fSessionInfo
.getSessionState();
131 * Sets the session state to the given value.
132 * @param state - state to set.
134 public void setSessionState(TraceSessionState state
) {
135 fSessionInfo
.setSessionState(state
);
139 * Sets the event state to the value specified by the given name.
140 * @param stateName - state to set.
142 public void setSessionState(String stateName
) {
143 fSessionInfo
.setSessionState(stateName
);
147 * @return path string where session is located.
149 public String
getSessionPath() {
150 return fSessionInfo
.getSessionPath();
154 * Sets the path string (where session is located) to the given value.
155 * @param path - session path to set.
157 public void setSessionPath(String sessionPath
) {
158 fSessionInfo
.setSessionPath(sessionPath
);
163 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
165 @SuppressWarnings("rawtypes")
167 public Object
getAdapter(Class adapter
) {
168 if (adapter
== IPropertySource
.class) {
169 return new TraceSessionPropertySource(this);
174 // ------------------------------------------------------------------------
176 // ------------------------------------------------------------------------
178 * Retrieves the session configuration from the node.
179 * @throws ExecutionException
181 public void getConfigurationFromNode() throws ExecutionException
{
182 getConfigurationFromNode(new NullProgressMonitor());
186 * Retrieves the session configuration from the node.
187 * @param monitor - a progress monitor
188 * @throws ExecutionException
190 public void getConfigurationFromNode(IProgressMonitor monitor
) throws ExecutionException
{
192 fSessionInfo
= getControlService().getSession(getName(), monitor
);
193 IDomainInfo
[] domains
= fSessionInfo
.getDomains();
194 for (int i
= 0; i
< domains
.length
; i
++) {
195 TraceDomainComponent domainComponent
= new TraceDomainComponent(domains
[i
].getName(), this);
196 addChild(domainComponent
);
197 domainComponent
.setDomainInfo(domains
[i
]);
202 * Starts the session.
203 * throws ExecutionExecption
205 public void startSession() throws ExecutionException
{
206 startSession(new NullProgressMonitor());
210 * Starts the session.
211 * @param monitor - a progress monitor
212 * throws ExecutionExecption
214 public void startSession(IProgressMonitor monitor
) throws ExecutionException
{
215 getControlService().startSession(getName(), monitor
);
219 * Starts the session.
220 * throws ExecutionExecption
222 public void stopSession() throws ExecutionException
{
223 startSession(new NullProgressMonitor());
227 * Starts the session.
228 * @param monitor - a progress monitor
229 * throws ExecutionExecption
231 public void stopSession(IProgressMonitor monitor
) throws ExecutionException
{
232 getControlService().stopSession(getName(), monitor
);