First part of LTTng 2.0 support
[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.swt.graphics.Image;
24
25 /**
26 * <b><u>TraceSessionComponent</u></b>
27 * <p>
28 * Implementation of the trace session component.
29 * </p>
30 */
31 public class TraceSessionComponent extends TraceControlComponent {
32
33 // ------------------------------------------------------------------------
34 // Constants
35 // ------------------------------------------------------------------------
36 /**
37 * Path to icon file for this component (inactive state).
38 */
39 public static final String TRACE_SESSION_ICON_FILE_INACTIVE = "icons/obj16/session_inactive.gif"; //$NON-NLS-1$
40 /**
41 * Path to icon file for this component (active state).
42 */
43 public static final String TRACE_SESSION_ICON_FILE_ACTIVE = "icons/obj16/session_active.gif"; //$NON-NLS-1$
44 /**
45 * Path to icon file for this component (destroyed state).
46 */
47 public static final String TRACE_SESSION_ICON_FILE_DESTROYED = "icons/obj16/session_destroyed.gif"; //$NON-NLS-1$
48
49 // ------------------------------------------------------------------------
50 // Attributes
51 // ------------------------------------------------------------------------
52 /**
53 * The session information.
54 */
55 private ISessionInfo fSessionInfo = null;
56 /**
57 * A flag to indicate if session has been destroyed.
58 */
59 private boolean fIsDestroyed = false;
60 /**
61 * The image to be displayed in state active.
62 */
63 private Image fActiveImage = null;
64 /**
65 * The image to be displayed in state destroyed
66 */
67 private Image fDestroyedImage = null;
68
69 // ------------------------------------------------------------------------
70 // Constructors
71 // ------------------------------------------------------------------------
72 /**
73 * Constructor
74 * @param name - the name of the component.
75 * @param parent - the parent of this component.
76 */
77 public TraceSessionComponent(String name, ITraceControlComponent parent) {
78 super(name, parent);
79 setImage(TRACE_SESSION_ICON_FILE_INACTIVE);
80 setToolTip(Messages.TraceControl_SessionDisplayName);
81 fSessionInfo = new SessionInfo(name);
82 fActiveImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_ACTIVE);
83 fDestroyedImage = LTTngUiPlugin.getDefault().loadIcon(TRACE_SESSION_ICON_FILE_DESTROYED);
84 }
85
86 // ------------------------------------------------------------------------
87 // Accessors
88 // ------------------------------------------------------------------------
89 /*
90 * (non-Javadoc)
91 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage()
92 */
93 @Override
94 public Image getImage() {
95 if (fIsDestroyed) {
96 return fDestroyedImage;
97 }
98
99 if (fSessionInfo.getSessionState() == TraceSessionState.INACTIVE) {
100 return super.getImage();
101 }
102
103 return fActiveImage;
104 }
105
106
107 /**
108 * @return the whether the session is destroyed or not.
109 */
110 public boolean isDestroyed() {
111 return fIsDestroyed;
112 }
113
114 /**
115 * Sets the session destroyed state to the given value.
116 * @param destroyed - value to set.
117 */
118 public void setDestroyed(boolean destroyed) {
119 fIsDestroyed = destroyed;
120 }
121
122 /**
123 * @return the session state state (active or inactive).
124 */
125 public TraceSessionState getSessionState() {
126 return fSessionInfo.getSessionState();
127 }
128
129 /**
130 * Sets the session state to the given value.
131 * @param state - state to set.
132 */
133 public void setSessionState(TraceSessionState state) {
134 fSessionInfo.setSessionState(state);
135 }
136
137 /**
138 * Sets the event state to the value specified by the given name.
139 * @param stateName - state to set.
140 */
141 public void setSessionState(String stateName) {
142 fSessionInfo.setSessionState(stateName);
143 }
144
145 /**
146 * @return path string where session is located.
147 */
148 public String getSessionPath() {
149 return fSessionInfo.getSessionPath();
150 }
151
152 /**
153 * Sets the path string (where session is located) to the given value.
154 * @param path - session path to set.
155 */
156 public void setSessionPath(String sessionPath) {
157 fSessionInfo.setSessionPath(sessionPath);
158 }
159
160 // ------------------------------------------------------------------------
161 // Operations
162 // ------------------------------------------------------------------------
163 /**
164 * Retrieves the session configuration from the node.
165 * @throws ExecutionException
166 */
167 public void getConfigurationFromNode() throws ExecutionException {
168 getConfigurationFromNode(new NullProgressMonitor());
169 }
170
171 /**
172 * Retrieves the session configuration from the node.
173 * @param monitor - a progress monitor
174 * @throws ExecutionException
175 */
176 public void getConfigurationFromNode(IProgressMonitor monitor) throws ExecutionException {
177 fSessionInfo = getControlService().getSession(getName(), monitor);
178 IDomainInfo[] domains = fSessionInfo.getDomains();
179 for (int i = 0; i < domains.length; i++) {
180 TraceDomainComponent domainComponenent = new TraceDomainComponent(domains[i].getName(), this);
181 addChild(domainComponenent);
182 domainComponenent.setDomainInfo(domains[i]);
183 }
184 }
185 }
This page took 0.037158 seconds and 6 git commands to generate.