Commit | Line | Data |
---|---|---|
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 | **********************************************************************/ | |
115b4a01 | 12 | package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl; |
eb1bab5b BH |
13 | |
14 | import org.eclipse.core.commands.ExecutionException; | |
15 | import org.eclipse.core.runtime.IProgressMonitor; | |
16 | import org.eclipse.core.runtime.NullProgressMonitor; | |
9315aeee | 17 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo; |
115b4a01 | 18 | import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent; |
eb1bab5b BH |
19 | |
20 | /** | |
21 | * <b><u>TraceSessionGroup</u></b> | |
22 | * <p> | |
23 | * Implementation of the trace session group. | |
24 | * </p> | |
25 | */ | |
26 | public class TraceSessionGroup extends TraceControlComponent { | |
27 | // ------------------------------------------------------------------------ | |
28 | // Constants | |
29 | // ------------------------------------------------------------------------ | |
30 | /** | |
31 | * Path to icon file for this component. | |
32 | */ | |
33 | public static final String TRACE_SESSIONS_ICON_FILE = "icons/obj16/sessions.gif"; //$NON-NLS-1$ | |
34 | ||
35 | // ------------------------------------------------------------------------ | |
36 | // Attributes | |
37 | // ------------------------------------------------------------------------ | |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Constructors | |
41 | // ------------------------------------------------------------------------ | |
42 | /** | |
43 | * Constructor | |
44 | * @param name - the name of the component. | |
45 | * @param parent - the parent of this component. | |
46 | */ | |
47 | public TraceSessionGroup(String name, ITraceControlComponent parent) { | |
48 | super(name, parent); | |
49 | setImage(TRACE_SESSIONS_ICON_FILE); | |
50 | } | |
bbb3538a | 51 | |
eb1bab5b BH |
52 | // ------------------------------------------------------------------------ |
53 | // Accessors | |
54 | // ------------------------------------------------------------------------ | |
55 | ||
498704b3 BH |
56 | /** |
57 | * @return the parent target node | |
58 | */ | |
59 | public TargetNodeComponent getTargetNode() { | |
60 | return (TargetNodeComponent)getParent(); | |
61 | } | |
62 | ||
eb1bab5b BH |
63 | // ------------------------------------------------------------------------ |
64 | // Operations | |
65 | // ------------------------------------------------------------------------ | |
66 | /** | |
67 | * Retrieves the sessions information from the node. | |
68 | * @throws ExecutionException | |
69 | */ | |
70 | public void getSessionsFromNode() throws ExecutionException { | |
71 | getSessionsFromNode(new NullProgressMonitor()); | |
72 | } | |
73 | ||
74 | /** | |
75 | * Retrieves the sessions information from the node. | |
76 | * @param monitor - a progress monitor | |
77 | * @throws ExecutionException | |
78 | */ | |
79 | public void getSessionsFromNode(IProgressMonitor monitor) throws ExecutionException { | |
80 | String[] sessionNames = getControlService().getSessionNames(monitor); | |
81 | for (int i = 0; i < sessionNames.length; i++) { | |
82 | TraceSessionComponent session = new TraceSessionComponent(sessionNames[i], this); | |
83 | addChild(session); | |
84 | session.getConfigurationFromNode(monitor); | |
85 | } | |
86 | } | |
bbb3538a BH |
87 | |
88 | /** | |
89 | * Creates a session with given session name and location. | |
90 | * @param sessionName - a session name to create | |
91 | * @param sessionPath - a path for storing the traces (use null for default) | |
92 | * @return the session information | |
93 | * throws ExecutionExecption | |
94 | */ | |
6503ae0f | 95 | public void createSession(String sessionName, String sessionPath) throws ExecutionException { |
bbb3538a BH |
96 | createSession(sessionName, sessionPath, new NullProgressMonitor()); |
97 | } | |
98 | ||
99 | /** | |
100 | * Creates a session with given session name and location. | |
101 | * @param sessionName - a session name to create | |
102 | * @param sessionPath - a path for storing the traces (use null for default) | |
103 | * @Param monitor - a progress monitor | |
104 | * @return the session information | |
105 | * throws ExecutionExecption | |
106 | */ | |
6503ae0f | 107 | public void createSession(String sessionName, String sessionPath, IProgressMonitor monitor) throws ExecutionException { |
bbb3538a BH |
108 | ISessionInfo sessionInfo = getControlService().createSession(sessionName, sessionPath, monitor); |
109 | if (sessionInfo != null) { | |
110 | TraceSessionComponent session = new TraceSessionComponent(sessionInfo.getName(), TraceSessionGroup.this); | |
111 | addChild(session); | |
112 | session.getConfigurationFromNode(monitor); | |
113 | } | |
114 | } | |
115 | ||
116 | /** | |
117 | * Destroys a session with given session name. | |
6503ae0f | 118 | * @param session - a session component to destroy |
bbb3538a BH |
119 | * throws ExecutionExecption |
120 | */ | |
6503ae0f BH |
121 | public void destroySession(TraceSessionComponent session) throws ExecutionException { |
122 | destroySession(session, new NullProgressMonitor()); | |
bbb3538a BH |
123 | } |
124 | ||
125 | /** | |
126 | * Destroys a session with given session name. | |
6503ae0f | 127 | * @param session - a session component to destroy |
bbb3538a BH |
128 | * @param monitor - a progress monitor |
129 | * throws ExecutionExecption | |
130 | */ | |
6503ae0f BH |
131 | public void destroySession(TraceSessionComponent session, IProgressMonitor monitor) throws ExecutionException { |
132 | getControlService().destroySession(session.getName(), monitor); | |
bbb3538a BH |
133 | session.removeAllChildren(); |
134 | removeChild(session); | |
135 | } | |
eb1bab5b | 136 | } |