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