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 fireComponentChanged(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);
179 * @return remote host name
181 public String
getHostName() {
182 return fHost
.getHostName();
186 * @return remote system proxy implementation
188 public IRemoteSystemProxy
getRemoteSystemProxy() {
192 // ------------------------------------------------------------------------
194 // ------------------------------------------------------------------------
197 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
200 public void communicationsStateChange(CommunicationsEvent e
) {
201 if (e
.getState() == CommunicationsEvent
.AFTER_DISCONNECT
||
202 e
.getState() == CommunicationsEvent
.CONNECTION_ERROR
) {
203 handleDisconnected();
204 } if ((e
.getState() == CommunicationsEvent
.AFTER_CONNECT
) && (fState
!= TargetNodeState
.CONNECTING
)) {
210 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
213 public boolean isPassiveCommunicationsListener() {
219 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.TraceControlComponent#dispose()
222 public void dispose() {
223 fRemoteProxy
.removeCommunicationListener(this);
227 * Method to connect this node component to the remote target node.
229 public void connect() {
230 if (fState
== TargetNodeState
.DISCONNECTED
) {
232 setTargetNodeState(TargetNodeState
.CONNECTING
);
233 fRemoteProxy
.connect(new IRSECallback() {
235 public void done(IStatus status
, Object result
) {
236 // Note: result might be null!
240 handleDisconnected();
244 } catch (Exception e
) {
245 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
246 LTTngUiPlugin
.logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + ").", e
); //$NON-NLS-1$ //$NON-NLS-2$
252 * Method to disconnect this node component to the remote target node.
254 public void disconnect() {
255 if (fState
== TargetNodeState
.CONNECTED
) {
257 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
258 fRemoteProxy
.disconnect();
259 } catch (Exception e
) {
260 LTTngUiPlugin
.logError(Messages
.TraceControl_DisconnectionFailure
+ getName(), e
);
262 handleDisconnected();
268 * Retrieves the trace configuration from the target node and populates the information
269 * in the tree model. The execution is done in a own job.
271 * @throws ExecutionException
273 public void getConfigurationFromNode() throws ExecutionException
{
274 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
276 protected IStatus
run(IProgressMonitor monitor
) {
279 // Get provider information from node
280 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
281 addChild(providerGroup
);
282 providerGroup
.getProviderFromNode(monitor
);
284 // Get session information from node
285 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
286 addChild(sessionGroup
);
287 sessionGroup
.getSessionsFromNode(monitor
);
288 } catch (ExecutionException e
) {
290 return new Status(Status
.ERROR
, LTTngUiPlugin
.PLUGIN_ID
, e
.toString());
293 return Status
.OK_STATUS
;
301 // ------------------------------------------------------------------------
303 // ------------------------------------------------------------------------
305 * @return returns the control service for LTTng specific commands.
306 * @throws ExecutionException
308 private ILttngControlService
createControlService() throws ExecutionException
{
309 if (fShell
== null) {
310 fShell
= fRemoteProxy
.createCommandShell();
311 fRemoteProxy
.addCommunicationListener(this);
313 fService
= new LTTngControlService(fShell
);
318 * Handles the connected event.
320 private void handleConnected() {
321 setTargetNodeState(TargetNodeState
.CONNECTED
);
323 createControlService();
324 getConfigurationFromNode();
325 } catch (ExecutionException e
) {
326 LTTngUiPlugin
.logError(Messages
.TraceControl_ListSessionFailure
, e
);
331 * Handles the disconnected event.
333 private void handleDisconnected() {
335 setTargetNodeState(TargetNodeState
.DISCONNECTED
);