Allow LTTng Control to connect to LTTng 2.x.y nodes (Bug 388545)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / model / impl / TargetNodeComponent.java
index 3f1639f6c953c042c20cba108d5994efbe533466..94a6678ba0ce6f7af535a330d66aa8bd9f233431 100644 (file)
@@ -1,12 +1,12 @@
 /**********************************************************************
  * Copyright (c) 2012 Ericsson
- * 
+ *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
  * accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors: 
+ *
+ * Contributors:
  *   Bernd Hufmann - Initial API and implementation
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl;
@@ -18,14 +18,14 @@ import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TargetNodeState;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TargetNodePropertySource;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.ICommandShell;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.RemoteSystemProxy;
-import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ICommandShell;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.LTTngControlServiceFactory;
 import org.eclipse.rse.core.RSECorePlugin;
@@ -38,10 +38,11 @@ import org.eclipse.swt.graphics.Image;
 import org.eclipse.ui.views.properties.IPropertySource;
 
 /**
- * <b><u>TargetNodeComponent</u></b>
  * <p>
  * Implementation of the trace node component.
  * </p>
+ *
+ * @author Bernd Hufmann
  */
 public class TargetNodeComponent extends TraceControlComponent implements ICommunicationsListener {
 
@@ -89,7 +90,7 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
     // Constructors
     // ------------------------------------------------------------------------
     /**
-     * Constructor 
+     * Constructor
      * @param name - the name of the component
      * @param parent - the parent of the component
      * @param host - the host connection implementation
@@ -105,7 +106,7 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
     }
 
     /**
-     * Constructor (using default proxy) 
+     * Constructor (using default proxy)
      * @param name - the name of the component
      * @param parent - the parent of the component
      * @param host - the host connection implementation
@@ -128,7 +129,7 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
         }
         return fDisconnectedImage;
     }
-    
+
     /*
      * (non-Javadoc)
      * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getTargetNodeState()
@@ -137,7 +138,7 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
     public TargetNodeState getTargetNodeState() {
         return fState;
     }
-    
+
     /*
      * (non-Javadoc)
      * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#setTargetNodeState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent.TargetNodeState)
@@ -147,7 +148,7 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
         fState = state;
         fireComponentChanged(TargetNodeComponent.this);
     }
-    
+
     /*
      * (non-Javadoc)
      * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getControlService()
@@ -163,22 +164,21 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
      */
     @Override
     public void setControlService(ILttngControlService service) {
-        fService = (ILttngControlService)service;
+        fService = service;
     }
 
     /*
      * (non-Javadoc)
      * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
      */
-    @SuppressWarnings("rawtypes")
     @Override
     public Object getAdapter(Class adapter) {
         if (adapter == IPropertySource.class) {
             return new TargetNodePropertySource(this);
         }
         return null;
-    } 
-    
+    }
+
     /**
      * @return remote host name
      */
@@ -199,17 +199,28 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
     public TraceSessionComponent[] getSessions() {
         List<ITraceControlComponent> compenents = getChildren(TraceSessionGroup.class);
         if (compenents.size() > 0) {
-            TraceSessionGroup group = (TraceSessionGroup)compenents.get(0); 
+            TraceSessionGroup group = (TraceSessionGroup)compenents.get(0);
             List<ITraceControlComponent> sessions = group.getChildren(TraceSessionComponent.class);
-            return (TraceSessionComponent[])sessions.toArray(new TraceSessionComponent[sessions.size()]);
+            return sessions.toArray(new TraceSessionComponent[sessions.size()]);
         }
         return new TraceSessionComponent[0];
     }
-    
+
+    /**
+     * @return node version
+     */
+    public String getNodeVersion() {
+        // Control service is null during connection to node
+        if (getControlService() != null) {
+            return getControlService().getVersion();
+        }
+        return ""; //$NON-NLS-1$
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
-    
+
    /*
     * @see org.eclipse.rse.core.subsystems.ICommunicationsListener#communicationsStateChange(org.eclipse.rse.core.subsystems.CommunicationsEvent)
     */
@@ -260,8 +271,7 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
                });
            } catch (Exception e) {
                setTargetNodeState(TargetNodeState.DISCONNECTED);
-               Activator.getDefault().getLog().log(
-                       new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ConnectionFailure + " (" + getName() + "). \n", e)); //$NON-NLS-1$ //$NON-NLS-2$
+               Activator.getDefault().logError(Messages.TraceControl_ConnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$
            }
        }
     }
@@ -275,19 +285,16 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
                 setTargetNodeState(TargetNodeState.DISCONNECTING);
                 fRemoteProxy.disconnect();
             } catch (Exception e) {
-                Activator.getDefault().getLog().log(
-                        new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_DisconnectionFailure + " (" + getName() + "). \n", e)); //$NON-NLS-1$ //$NON-NLS-2$
+                Activator.getDefault().logError(Messages.TraceControl_DisconnectionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$
             } finally {
-                handleDisconnected();                    
+                handleDisconnected();
             }
         }
     }
 
     /**
-     * Retrieves the trace configuration from the target node and populates the information
-     * in the tree model. The execution is done in a own job.
-     * 
-     * @throws ExecutionException
+     * Retrieves the trace configuration from the target node and populates the
+     * information in the tree model. The execution is done in a own job.
      */
     public void getConfigurationFromNode() {
         Job job = new Job(Messages.TraceControl_RetrieveNodeConfigurationJob) {
@@ -299,15 +306,15 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
                     TraceProviderGroup providerGroup = new TraceProviderGroup(Messages.TraceControl_ProviderDisplayName, TargetNodeComponent.this);
                     addChild(providerGroup);
                     providerGroup.getProviderFromNode(monitor);
-                    
+
                     // Get session information from node
                     TraceSessionGroup sessionGroup = new TraceSessionGroup(Messages.TraceControl_AllSessionsDisplayName, TargetNodeComponent.this);
                     addChild(sessionGroup);
                     sessionGroup.getSessionsFromNode(monitor);
                 } catch (ExecutionException e) {
                     removeAllChildren();
-                    return new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ListSessionFailure, e);
-                } 
+                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ListSessionFailure, e);
+                }
 
                 return Status.OK_STATUS;
             }
@@ -323,7 +330,7 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
         removeAllChildren();
         getConfigurationFromNode();
     }
-    
+
     /**
      * Deregisters host from registry.
      */
@@ -349,7 +356,7 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
     }
 
     /**
-     * Handles the connected event. 
+     * Handles the connected event.
      */
     private void handleConnected() {
         setTargetNodeState(TargetNodeState.CONNECTED);
@@ -357,13 +364,12 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
             createControlService();
             getConfigurationFromNode();
         } catch (ExecutionException e) {
-            Activator.getDefault().getLog().log(
-                    new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_ListSessionFailure + " (" + getName() + "). \n", e)); //$NON-NLS-1$ //$NON-NLS-2$
+            Activator.getDefault().logError(Messages.TraceControl_ListSessionFailure + " (" + getName() + "). \n", e); //$NON-NLS-1$ //$NON-NLS-2$
         }
     }
 
     /**
-     * Handles the disconnected event. 
+     * Handles the disconnected event.
      */
     private void handleDisconnected() {
         removeAllChildren();
This page took 0.027349 seconds and 5 git commands to generate.