Merge branch 'master' into lttng_2_0_control_dev
[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 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;
26
27 /**
28 * <b><u>TraceSessionComponent</u></b>
29 * <p>
30 * Implementation of the trace session component.
31 * </p>
32 */
33 public 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
108
109 /**
110 * @return the whether the session is destroyed or not.
111 */
112 public boolean isDestroyed() {
113 return fIsDestroyed;
114 }
115
116 /**
117 * Sets the session destroyed state to the given value.
118 * @param destroyed - value to set.
119 */
120 public void setDestroyed(boolean destroyed) {
121 fIsDestroyed = destroyed;
122 }
123
124 /**
125 * @return the session state state (active or inactive).
126 */
127 public TraceSessionState getSessionState() {
128 return fSessionInfo.getSessionState();
129 }
130
131 /**
132 * Sets the session state to the given value.
133 * @param state - state to set.
134 */
135 public void setSessionState(TraceSessionState state) {
136 fSessionInfo.setSessionState(state);
137 }
138
139 /**
140 * Sets the event state to the value specified by the given name.
141 * @param stateName - state to set.
142 */
143 public void setSessionState(String stateName) {
144 fSessionInfo.setSessionState(stateName);
145 }
146
147 /**
148 * @return path string where session is located.
149 */
150 public String getSessionPath() {
151 return fSessionInfo.getSessionPath();
152 }
153
154 /**
155 * Sets the path string (where session is located) to the given value.
156 * @param path - session path to set.
157 */
158 public void setSessionPath(String sessionPath) {
159 fSessionInfo.setSessionPath(sessionPath);
160 }
161
162 /*
163 * (non-Javadoc)
164 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
165 */
166 @SuppressWarnings("rawtypes")
167 @Override
168 public Object getAdapter(Class adapter) {
169 if (adapter == IPropertySource.class) {
170 return new TraceSessionPropertySource(this);
171 }
172 return null;
173 }
174
175 // ------------------------------------------------------------------------
176 // Operations
177 // ------------------------------------------------------------------------
178 /**
179 * Retrieves the session configuration from the node.
180 * @throws ExecutionException
181 */
182 public void getConfigurationFromNode() throws ExecutionException {
183 getConfigurationFromNode(new NullProgressMonitor());
184 }
185
186 /**
187 * Retrieves the session configuration from the node.
188 * @param monitor - a progress monitor
189 * @throws ExecutionException
190 */
191 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 domainComponenent = new TraceDomainComponent(domains[i].getName(), this);
196 addChild(domainComponenent);
197 domainComponenent.setDomainInfo(domains[i]);
198 }
199 }
200 }
This page took 0.035294 seconds and 6 git commands to generate.