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
.internal
.lttng2
.ui
.views
.control
.model
.impl
;
14 import java
.util
.List
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.core
.runtime
.IStatus
;
19 import org
.eclipse
.core
.runtime
.Status
;
20 import org
.eclipse
.core
.runtime
.jobs
.Job
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TargetNodeState
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.property
.TargetNodePropertySource
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.IRemoteSystemProxy
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.RemoteSystemProxy
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.ICommandShell
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.ILttngControlService
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.service
.LTTngControlServiceFactory
;
31 import org
.eclipse
.rse
.core
.model
.IHost
;
32 import org
.eclipse
.rse
.core
.model
.IRSECallback
;
33 import org
.eclipse
.rse
.core
.subsystems
.CommunicationsEvent
;
34 import org
.eclipse
.rse
.core
.subsystems
.ICommunicationsListener
;
35 import org
.eclipse
.swt
.graphics
.Image
;
36 import org
.eclipse
.ui
.views
.properties
.IPropertySource
;
39 * <b><u>TargetNodeComponent</u></b>
41 * Implementation of the trace node component.
44 public class TargetNodeComponent
extends TraceControlComponent
implements ICommunicationsListener
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 * Path to icon file for this component (state connected).
52 public static final String TARGET_NODE_CONNECTED_ICON_FILE
= "icons/obj16/target_connected.gif"; //$NON-NLS-1$
54 * Path to icon file for this component (state disconnected).
56 public static final String TARGET_NODE_DISCONNECTED_ICON_FILE
= "icons/obj16/target_disconnected.gif"; //$NON-NLS-1$
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 * The node connection state.
64 private TargetNodeState fState
= TargetNodeState
.DISCONNECTED
;
66 * The image to be displayed in state disconnected.
68 private Image fDisconnectedImage
= null;
70 * The connection implementation.
72 private IHost fHost
= null;
74 * The remote proxy implementation.
76 private IRemoteSystemProxy fRemoteProxy
= null;
78 * The control service for LTTng specific commands.
80 private ILttngControlService fService
= null;
82 * The command shell for issuing commands.
84 private ICommandShell fShell
= null;
86 // ------------------------------------------------------------------------
88 // ------------------------------------------------------------------------
91 * @param name - the name of the component
92 * @param parent - the parent of the component
93 * @param host - the host connection implementation
94 * @param proxy - the remote proxy implementation
96 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
, IRemoteSystemProxy proxy
) {
98 setImage(TARGET_NODE_CONNECTED_ICON_FILE
);
99 fDisconnectedImage
= Activator
.getDefault().loadIcon(TARGET_NODE_DISCONNECTED_ICON_FILE
);
101 fRemoteProxy
= proxy
;
102 setToolTip(fHost
.getHostName());
106 * Constructor (using default proxy)
107 * @param name - the name of the component
108 * @param parent - the parent of the component
109 * @param host - the host connection implementation
111 public TargetNodeComponent(String name
, ITraceControlComponent parent
, IHost host
) {
112 this(name
, parent
, host
, new RemoteSystemProxy(host
));
115 // ------------------------------------------------------------------------
117 // ------------------------------------------------------------------------
120 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
123 public Image
getImage() {
124 if (fState
== TargetNodeState
.CONNECTED
) {
125 return super.getImage();
127 return fDisconnectedImage
;
132 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getTargetNodeState()
135 public TargetNodeState
getTargetNodeState() {
141 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setTargetNodeState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent.TargetNodeState)
144 public void setTargetNodeState(TargetNodeState state
) {
146 fireComponentChanged(TargetNodeComponent
.this);
151 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getControlService()
154 public ILttngControlService
getControlService() {
160 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setControlService(org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService)
163 public void setControlService(ILttngControlService service
) {
164 fService
= (ILttngControlService
)service
;
169 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
171 @SuppressWarnings("rawtypes")
173 public Object
getAdapter(Class adapter
) {
174 if (adapter
== IPropertySource
.class) {
175 return new TargetNodePropertySource(this);
181 * @return remote host name
183 public String
getHostName() {
184 return fHost
.getHostName();
188 * @return remote system proxy implementation
190 public IRemoteSystemProxy
getRemoteSystemProxy() {
195 * @return all available sessions.
197 public TraceSessionComponent
[] getSessions() {
198 List
<ITraceControlComponent
> compenents
= getChildren(TraceSessionGroup
.class);
199 if (compenents
.size() > 0) {
200 TraceSessionGroup group
= (TraceSessionGroup
)compenents
.get(0);
201 List
<ITraceControlComponent
> sessions
= group
.getChildren(TraceSessionComponent
.class);
202 return (TraceSessionComponent
[])sessions
.toArray(new TraceSessionComponent
[sessions
.size()]);
204 return new TraceSessionComponent
[0];
207 // ------------------------------------------------------------------------
209 // ------------------------------------------------------------------------
212 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
215 public void communicationsStateChange(CommunicationsEvent e
) {
216 if (e
.getState() == CommunicationsEvent
.AFTER_DISCONNECT
||
217 e
.getState() == CommunicationsEvent
.CONNECTION_ERROR
) {
218 handleDisconnected();
219 } if ((e
.getState() == CommunicationsEvent
.AFTER_CONNECT
) && (fState
!= TargetNodeState
.CONNECTING
)) {
225 * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#isPassiveCommunicationsListener()
228 public boolean isPassiveCommunicationsListener() {
234 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceControlComponent#dispose()
237 public void dispose() {
238 fRemoteProxy
.removeCommunicationListener(this);
242 * Method to connect this node component to the remote target node.
244 public void connect() {
245 if (fState
== TargetNodeState
.DISCONNECTED
) {
247 setTargetNodeState(TargetNodeState
.CONNECTING
);
248 fRemoteProxy
.connect(new IRSECallback() {
250 public void done(IStatus status
, Object result
) {
251 // Note: result might be null!
255 handleDisconnected();
259 } catch (Exception e
) {
260 setTargetNodeState(TargetNodeState
.DISCONNECTED
);
261 Activator
.getDefault().getLog().log(
262 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ConnectionFailure
+ " (" + getName() + "). \n", e
)); //$NON-NLS-1$ //$NON-NLS-2$
268 * Method to disconnect this node component to the remote target node.
270 public void disconnect() {
271 if (fState
== TargetNodeState
.CONNECTED
) {
273 setTargetNodeState(TargetNodeState
.DISCONNECTING
);
274 fRemoteProxy
.disconnect();
275 } catch (Exception e
) {
276 Activator
.getDefault().getLog().log(
277 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_DisconnectionFailure
+ " (" + getName() + "). \n", e
)); //$NON-NLS-1$ //$NON-NLS-2$
279 handleDisconnected();
285 * Retrieves the trace configuration from the target node and populates the information
286 * in the tree model. The execution is done in a own job.
288 * @throws ExecutionException
290 public void getConfigurationFromNode() {
291 Job job
= new Job(Messages
.TraceControl_RetrieveNodeConfigurationJob
) {
293 protected IStatus
run(IProgressMonitor monitor
) {
296 // Get provider information from node
297 TraceProviderGroup providerGroup
= new TraceProviderGroup(Messages
.TraceControl_ProviderDisplayName
, TargetNodeComponent
.this);
298 addChild(providerGroup
);
299 providerGroup
.getProviderFromNode(monitor
);
301 // Get session information from node
302 TraceSessionGroup sessionGroup
= new TraceSessionGroup(Messages
.TraceControl_AllSessionsDisplayName
, TargetNodeComponent
.this);
303 addChild(sessionGroup
);
304 sessionGroup
.getSessionsFromNode(monitor
);
305 } catch (ExecutionException e
) {
307 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ListSessionFailure
, e
);
310 return Status
.OK_STATUS
;
317 public void refresh() {
319 getConfigurationFromNode();
322 // ------------------------------------------------------------------------
324 // ------------------------------------------------------------------------
326 * @return returns the control service for LTTng specific commands.
327 * @throws ExecutionException
329 private ILttngControlService
createControlService() throws ExecutionException
{
330 if (fShell
== null) {
331 fShell
= fRemoteProxy
.createCommandShell();
332 fRemoteProxy
.addCommunicationListener(this);
334 fService
= LTTngControlServiceFactory
.getInstance().getLttngControlService(fShell
);
339 * Handles the connected event.
341 private void handleConnected() {
342 setTargetNodeState(TargetNodeState
.CONNECTED
);
344 createControlService();
345 getConfigurationFromNode();
346 } catch (ExecutionException e
) {
347 Activator
.getDefault().getLog().log(
348 new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_ListSessionFailure
+ " (" + getName() + "). \n", e
)); //$NON-NLS-1$ //$NON-NLS-2$
353 * Handles the disconnected event.
355 private void handleDisconnected() {
357 setTargetNodeState(TargetNodeState
.DISCONNECTED
);