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);
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!
230 handleDisconnected();
234 } catch (Exception e
) {
235 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
236 LTTngUiPlugin
.logError(Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + ").", e
); //$NON-NLS-1$ //$NON-NLS-2$
242 * Method to disconnect this node component to the remote target node.
244 public void disconnect() {
245 if (fState
== TargetNodeState
.CONNECTED
) {
247 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
248 fRemoteProxy
.disconnect();
249 } catch (Exception e
) {
250 LTTngUiPlugin
.logError(Messages
.TraceControl_DisconnectionFailure
+ getName(), e
);
252 handleDisconnected();
258 * Retrieves the trace configuration from the target node and populates the information
259 * in the tree model. The execution is done in a own job.
261 * @throws ExecutionException
263 public void getConfigurationFromNode() throws ExecutionException
{
264 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
266 protected IStatus
run(IProgressMonitor monitor
) {
269 // Get provider information from node
270 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
271 addChild(providerGroup
);
272 providerGroup
.getProviderFromNode(monitor
);
274 // Get session information from node
275 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
276 addChild(sessionGroup
);
277 sessionGroup
.getSessionsFromNode(monitor
);
278 } catch (ExecutionException e
) {
280 return new Status(Status
.ERROR
, LTTngUiPlugin
.PLUGIN_ID
, e
.toString());
283 return Status
.OK_STATUS
;
291 // ------------------------------------------------------------------------
293 // ------------------------------------------------------------------------
295 * @return returns the control service for LTTng specific commands.
296 * @throws ExecutionException
298 private ILttngControlService
createControlService() throws ExecutionException
{
299 if (fShell
== null) {
300 fShell
= fRemoteProxy
.createCommandShell();
301 fRemoteProxy
.addCommunicationListener(this);
303 fService
= new LTTngControlService(fShell
);
308 * Handles the connected event.
310 private void handleConnected() {
311 setTargetNodeState(TargetNodeState
.CONNECTED
);
313 createControlService();
314 getConfigurationFromNode();
315 } catch (ExecutionException e
) {
316 LTTngUiPlugin
.logError(Messages
.TraceControl_ListSessionFailure
, e
);
321 * Handles the disconnected event.
323 private void handleDisconnected() {
325 setTargetNodeState(TargetNodeState
.DISCONNECTED
);