1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
16 import org
.eclipse
.core
.runtime
.IStatus
;
17 import org
.eclipse
.core
.runtime
.Status
;
18 import org
.eclipse
.core
.runtime
.jobs
.Job
;
19 import org
.eclipse
.linuxtools
.lttng
.ui
.LTTngUiPlugin
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.Messages
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.TargetNodeState
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.property
.TargetNodePropertySource
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.remote
.IRemoteSystemProxy
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.remote
.RemoteSystemProxy
;
26 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.ICommandShell
;
27 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.ILttngControlService
;
28 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.service
.LTTngControlService
;
29 import org
.eclipse
.rse
.core
.model
.IHost
;
30 import org
.eclipse
.rse
.core
.model
.IRSECallback
;
31 import org
.eclipse
.rse
.core
.subsystems
.CommunicationsEvent
;
32 import org
.eclipse
.rse
.core
.subsystems
.ICommunicationsListener
;
33 import org
.eclipse
.swt
.graphics
.Image
;
34 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
37 * <b><u>TargetNodeComponent</u></b>
39 * Implementation of the trace node component.
42 public class TargetNodeComponent
extends TraceControlComponent
implements ICommunicationsListener
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * Path to icon file for this component (state connected).
50 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
52 * Path to icon file for this component (state disconnected).
54 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
56 // ------------------------------------------------------------------------
58 // ------------------------------------------------------------------------
60 * The node connection state.
62 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
64 * The image to be displayed in state disconnected.
66 private Image fDisconnectedImage
= null;
68 * The connection implementation.
70 private IHost fHost
= null;
72 * The remote proxy implementation.
74 private IRemoteSystemProxy fRemoteProxy
= null;
76 * The control service for LTTng specific commands.
78 private ILttngControlService fService
= null;
80 * The command shell for issuing commands.
82 private ICommandShell fShell
= null;
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
89 * @param name - the name of the component
90 * @param parent - the parent of the component
91 * @param host - the host connection implementation
92 * @param proxy - the remote proxy implementation
94 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
, IRemoteSystemProxy proxy
) {
96 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
97 fDisconnectedImage
= LTTngUiPlugin
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
100 setToolTip(fHost
.getHostName());
104 * Constructor (using default proxy)
105 * @param name - the name of the component
106 * @param parent - the parent of the component
107 * @param host - the host connection implementation
109 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
) {
110 this(name
, parent
, host
, new RemoteSystemProxy(host
));
113 // ------------------------------------------------------------------------
115 // ------------------------------------------------------------------------
118 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getImage()
121 public Image
getImage() {
122 if (fState
== TargetNodeState
.CONNECTED
) {
123 return super.getImage();
125 return fDisconnectedImage
;
130 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getTargetNodeState()
133 public TargetNodeState
getTargetNodeState() {
139 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#setTargetNodeState(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent.TargetNodeState)
142 public void setTargetNodeState(TargetNodeState state
) {
144 fireCompenentChanged(TargetNodeComponent
.this);
149 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getControlService()
152 public ILttngControlService
getControlService() {
158 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#setControlService(org.eclipse.linuxtools.lttng.ui.views.control.service.ILttngControlService)
161 public void setControlService(ILttngControlService service
) {
162 fService
= (ILttngControlService
)service
;
167 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
169 @SuppressWarnings("rawtypes")
171 public Object
getAdapter(Class adapter
) {
172 if (adapter
== IPropertySource
.class) {
173 return new TargetNodePropertySource(this);
178 public String
getHostName() {
179 return fHost
.getHostName();
182 // ------------------------------------------------------------------------
184 // ------------------------------------------------------------------------
187 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
190 public void communicationsStateChange(CommunicationsEvent e
) {
191 if (e
.getState() == CommunicationsEvent
.AFTER_DISCONNECT
||
192 e
.getState() == CommunicationsEvent
.CONNECTION_ERROR
) {
193 handleDisconnected();
194 } if ((e
.getState() == CommunicationsEvent
.AFTER_CONNECT
) && (fState
!= TargetNodeState
.CONNECTING
)) {
200 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
203 public boolean isPassiveCommunicationsListener() {
209 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.TraceControlComponent#dispose()
212 public void dispose() {
213 fRemoteProxy
.removeCommunicationListener(this);
217 * Method to connect this node component to the remote target node.
219 public void connect() {
220 if (fState
== TargetNodeState
.DISCONNECTED
) {
222 setTargetNodeState(TargetNodeState
.CONNECTING
);
223 fRemoteProxy
.connect(new IRSECallback() {
225 public void done(IStatus status
, Object result
) {
226 // Note: result might be null!
232 } catch (Exception e
) {
233 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
234 LTTngUiPlugin
.logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + ").", e
); //$NON-NLS-1$ //$NON-NLS-2$
240 * Method to disconnect this node component to the remote target node.
242 public void disconnect() {
243 if (fState
== TargetNodeState
.CONNECTED
) {
245 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
246 fRemoteProxy
.disconnect();
247 } catch (Exception e
) {
248 LTTngUiPlugin
.logError(Messages
.TraceControl_DisconnectionFailure
+ getName(), e
);
250 handleDisconnected();
256 * Retrieves the trace configuration from the target node and populates the information
257 * in the tree model. The execution is done in a own job.
259 * @throws ExecutionException
261 public void getConfigurationFromNode() throws ExecutionException
{
262 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
264 protected IStatus
run(IProgressMonitor monitor
) {
267 // Get provider information from node
268 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
269 addChild(providerGroup
);
270 providerGroup
.getProviderFromNode(monitor
);
272 // Get session information from node
273 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
274 addChild(sessionGroup
);
275 sessionGroup
.getSessionsFromNode(monitor
);
276 } catch (ExecutionException e
) {
278 return new Status(Status
.ERROR
, LTTngUiPlugin
.PLUGIN_ID
, e
.toString());
281 return Status
.OK_STATUS
;
289 // ------------------------------------------------------------------------
291 // ------------------------------------------------------------------------
293 * @return returns the control service for LTTng specific commands.
294 * @throws ExecutionException
296 private ILttngControlService
createControlService() throws ExecutionException
{
297 if (fShell
== null) {
298 fShell
= fRemoteProxy
.createCommandShell();
299 fRemoteProxy
.addCommunicationListener(this);
301 fService
= new LTTngControlService(fShell
);
306 * Handles the connected event.
308 private void handleConnected() {
309 setTargetNodeState(TargetNodeState
.CONNECTED
);
311 createControlService();
312 getConfigurationFromNode();
313 } catch (ExecutionException e
) {
314 LTTngUiPlugin
.logError(Messages
.TraceControl_ListSessionFailure
, e
);
319 * Handles the disconnected event.
321 private void handleDisconnected() {
323 setTargetNodeState(TargetNodeState
.DISCONNECTED
);