control: Add enhanced support for loading of sessions
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / model / impl / TraceSessionGroup.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 * Bernd Hufmann - Updated for support of LTTng Tools 2.1
12 **********************************************************************/
13 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl;
14
15 import java.util.List;
16
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.NullProgressMonitor;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.tracecompass.internal.lttng2.control.core.model.ISessionInfo;
22 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
23
24 /**
25 * <p>
26 * Implementation of the trace session group.
27 * </p>
28 *
29 * @author Bernd Hufmann
30 */
31 public class TraceSessionGroup extends TraceControlComponent {
32 // ------------------------------------------------------------------------
33 // Constants
34 // ------------------------------------------------------------------------
35 /**
36 * Path to icon file for this component.
37 */
38 public static final String TRACE_SESSIONS_ICON_FILE = "icons/obj16/sessions.gif"; //$NON-NLS-1$
39
40 // ------------------------------------------------------------------------
41 // Attributes
42 // ------------------------------------------------------------------------
43
44 // ------------------------------------------------------------------------
45 // Constructors
46 // ------------------------------------------------------------------------
47 /**
48 * Constructor
49 * @param name - the name of the component.
50 * @param parent - the parent of this component.
51 */
52 public TraceSessionGroup(String name, ITraceControlComponent parent) {
53 super(name, parent);
54 setImage(TRACE_SESSIONS_ICON_FILE);
55 }
56
57 // ------------------------------------------------------------------------
58 // Accessors
59 // ------------------------------------------------------------------------
60
61 /**
62 * @return the parent target node
63 */
64 public TargetNodeComponent getTargetNode() {
65 return (TargetNodeComponent)getParent();
66 }
67
68 /**
69 * Returns if node supports networks streaming or not
70 * @return <code>true</code> if node supports filtering else <code>false</code>
71 */
72 public boolean isNetworkStreamingSupported() {
73 return getTargetNode().isNetworkStreamingSupported();
74 }
75 /**
76 * Returns if node supports snapshots or not
77 * @return <code>true</code> if it supports snapshots else <code>false</code>
78 *
79 */ public boolean isSnapshotSupported() {
80 return getTargetNode().isSnapshotSupported();
81 }
82
83 /**
84 * Returns if node supports live or not
85 *
86 * @return <code>true</code> if it supports live else <code>false</code>
87 */
88 public boolean isLiveSupported() {
89 return getTargetNode().isLiveSupported();
90 }
91
92 // ------------------------------------------------------------------------
93 // Operations
94 // ------------------------------------------------------------------------
95 /**
96 * Retrieves the sessions information from the node.
97 *
98 * @throws ExecutionException
99 * If the command fails
100 */
101 public void getSessionsFromNode() throws ExecutionException {
102 getSessionsFromNode(new NullProgressMonitor());
103 }
104
105 /**
106 * Retrieves the sessions information from the node.
107 *
108 * @param monitor
109 * - a progress monitor
110 * @throws ExecutionException
111 * If the command fails
112 */
113 public void getSessionsFromNode(IProgressMonitor monitor)
114 throws ExecutionException {
115 List<String> sessionNames = getControlService().getSessionNames(monitor);
116 for (String sessionName : sessionNames) {
117 TraceSessionComponent session =
118 new TraceSessionComponent(sessionName, this);
119 addChild(session);
120 session.getConfigurationFromNode(monitor);
121 }
122 }
123
124 /**
125 * Creates a session with given session name and location.
126 *
127 * @param sessionInf
128 * the session information used to create the session
129 *
130 * @param monitor
131 * - a progress monitor
132 * @throws ExecutionException
133 * If the command fails
134 */
135 public void createSession(ISessionInfo sessionInf, IProgressMonitor monitor) throws ExecutionException {
136 ISessionInfo sessionInfo = getControlService().createSession(sessionInf, monitor);
137
138 if (sessionInfo != null) {
139 TraceSessionComponent session = new TraceSessionComponent(sessionInfo, TraceSessionGroup.this);
140 addChild(session);
141 session.getConfigurationFromNode(monitor);
142 }
143 }
144
145 /**
146 * Command to execute a list of commands
147 * @param monitor
148 * - a progress monitor
149 * @param commands
150 * - a list of commands to execute
151 * @throws ExecutionException
152 * If the command fails
153 */
154 public void executeCommands(IProgressMonitor monitor, List<String> commands) throws ExecutionException {
155 getControlService().runCommands(monitor, commands);
156 getTargetNode().refresh();
157 }
158
159 /**
160 * Destroys a session with given session name.
161 *
162 * @param session
163 * - a session component to destroy
164 * @param monitor
165 * - a progress monitor
166 * @throws ExecutionException
167 * If the command fails
168 */
169 public void destroySession(TraceSessionComponent session,
170 IProgressMonitor monitor) throws ExecutionException {
171 getControlService().destroySession(session.getName(), monitor);
172 session.removeAllChildren();
173 removeChild(session);
174 }
175
176 /**
177 * Load all or a given session.
178 *
179 * @param inputPath
180 * a input path to load session from or null for load all from default
181 * @param isForce
182 * flag whether to overwrite existing or not
183 * @param monitor
184 * a progress monitor
185 * @throws ExecutionException
186 * If the command fails
187 */
188 public void loadSession(@Nullable String inputPath, boolean isForce, IProgressMonitor monitor)
189 throws ExecutionException {
190 getControlService().loadSession(inputPath, isForce, monitor);
191 getTargetNode().refresh();
192 }
193 }
This page took 0.035826 seconds and 5 git commands to generate.