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