Bug 453499: Allow for programmatically adding a connection to the
authorMarkus Schorn <markus.schorn@windriver.com>
Fri, 28 Nov 2014 10:20:01 +0000 (11:20 +0100)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Thu, 4 Dec 2014 11:00:06 +0000 (06:00 -0500)
Control UI

Change-Id: I0b0dab26c455c371d7fab8fb0aaedf2f4401c19d
Signed-off-by: Markus Schorn <markus.schorn@windriver.com>
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/37481
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.tracecompass.lttng2.control.ui/plugin.properties
org.eclipse.tracecompass.lttng2.control.ui/plugin.xml
org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/Workaround_Bug449362.java
org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/handlers/NewConnectionHandler.java

index 5c14a87db7c5b9387a9b10b09c0e99648a9e8949..26987c9b0ee0c7860b7ee71d04b5a1ae4c0aa536 100644 (file)
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2013 Ericsson
+# Copyright (c) 2013, 2014 Ericsson and others.
 #
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License v1.0
@@ -137,3 +137,6 @@ commands.control.snapshot=Record Snapshot
 commands.control.snapshot.description=Record a snapshot
 
 preference.page.control.name=LTTng Tracer Control Preferences
+
+commandParameter.remoteServicesId.name = Remote Services ID
+commandParameter.connectionName.name = Connection Name
index cacd8e60de859e35b109e2895387f4f4b691af9a..2da1f5e96e2fcf61997e59a8cb79c8de5b05621e 100644 (file)
             description="%commands.control.new.description"
             id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.newConnection"
             name="%commands.control.new">
+         <commandParameter
+               id="org.eclipse.linuxtools.lttng2.control.ui.remoteServicesIdParameter"
+               name="%commandParameter.remoteServicesId.name"
+               optional="true">
+         </commandParameter>
+         <commandParameter
+               id="org.eclipse.linuxtools.lttng2.control.ui.connectionNameParameter"
+               name="%commandParameter.connectionName.name"
+               optional="true">
+         </commandParameter>
       </command>
       <command
             categoryId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.category"
index 7ebd6f16701c5bc0d8be7d7757f5aae1490dc691..31e6db7a40e00c2889fb08a8fcff7ef39c6454b7 100644 (file)
@@ -21,7 +21,7 @@ import org.eclipse.ui.IStartup;
 /**
  * Collection of workarounds needed for dealing with the RSE adapter.
  */
-class Workaround_Bug449362 {
+public class Workaround_Bug449362 {
 
     private static final String RSE_ADAPTER_ID = "org.eclipse.ptp.remote.RSERemoteServices"; //$NON-NLS-1$
 
index ecfbbbf3372483db0f683120e152786679ff3beb..ad5714a4116433090eeed4350616c83189dcd464 100644 (file)
  **********************************************************************/
 package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers;
 
+import java.util.Map;
+
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.window.Window;
 import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteServices;
+import org.eclipse.remote.core.RemoteServices;
 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.views.Workaround_Bug449362;
 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.INewConnectionDialog;
 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
@@ -29,13 +34,30 @@ import org.eclipse.ui.PlatformUI;
 
 /**
  * <p>
- * Command handler for creation new connection for trace control.
+ * Command handler for creation of a new connection for trace control.
+ * <br> By supplying arguments for the parameters with id {@link #PARAMETER_REMOTE_SERVICES_ID} and
+ * {@link #PARAMETER_CONNECTION_NAME}, the caller can specify the remote connection that will
+ * be added to the trace control. In case one of the optional arguments is not supplied, the handler
+ * opens a dialog for selecting a remote connection.
  * </p>
  *
  * @author Bernd Hufmann
  */
 public class NewConnectionHandler extends BaseControlViewHandler {
 
+    /**
+     * Id of the parameter for the remote services id.
+     * @see NewConnectionHandler
+     * @see IRemoteServices#getId()
+     */
+    public static final String PARAMETER_REMOTE_SERVICES_ID = "org.eclipse.linuxtools.lttng2.control.ui.remoteServicesIdParameter"; //$NON-NLS-1$
+    /**
+     * Id of the parameter for the name of the remote connection.
+     * @see NewConnectionHandler
+     * @see IRemoteServices#getName()
+     */
+    public static final String PARAMETER_CONNECTION_NAME = "org.eclipse.linuxtools.lttng2.control.ui.connectionNameParameter"; //$NON-NLS-1$
+
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -54,24 +76,17 @@ public class NewConnectionHandler extends BaseControlViewHandler {
             return false;
         }
 
-        // Open dialog box for the node name and address
-        final INewConnectionDialog dialog = TraceControlDialogFactory.getInstance().getNewConnectionDialog();
-
-        if (dialog.open() != Window.OK) {
-            return null;
-        }
-
-        IRemoteConnection host = dialog.getConnection();
-        if (host != null) {
+        IRemoteConnection connection = getConnection(event.getParameters());
+        if (connection != null) {
             fLock.lock();
             try {
                 // successful creation of host
                 TargetNodeComponent node = null;
-                if (!fRoot.containsChild(host.getName())) {
-                    node = new TargetNodeComponent(host.getName(), fRoot, host);
+                if (!fRoot.containsChild(connection.getName())) {
+                    node = new TargetNodeComponent(connection.getName(), fRoot, connection);
                     fRoot.addChild(node);
                 } else {
-                    node = (TargetNodeComponent)fRoot.getChild(host.getName());
+                    node = (TargetNodeComponent)fRoot.getChild(connection.getName());
                 }
 
                 node.connect();
@@ -82,6 +97,31 @@ public class NewConnectionHandler extends BaseControlViewHandler {
         return null;
     }
 
+    private static IRemoteConnection getConnection(Map<?,?> parameters) {
+        // First check whether arguments have been supplied
+        Object remoteServicesId = parameters.get(PARAMETER_REMOTE_SERVICES_ID);
+        Object connectionName = parameters.get(PARAMETER_CONNECTION_NAME);
+        if (remoteServicesId != null && connectionName != null) {
+            if (!Workaround_Bug449362.triggerRSEStartup(remoteServicesId.toString())) {
+                // Skip the connection in order to avoid an infinite loop
+            } else {
+                IRemoteServices rs = RemoteServices.getRemoteServices(remoteServicesId.toString());
+                if (rs != null) {
+                    return rs.getConnectionManager().getConnection(connectionName.toString());
+                }
+            }
+            return null;
+        }
+
+        // Without the arguments, open dialog box for the node name and address
+        final INewConnectionDialog dialog = TraceControlDialogFactory.getInstance().getNewConnectionDialog();
+        if (dialog.open() == Window.OK) {
+            return dialog.getConnection();
+        }
+
+        return null;
+    }
+
     @Override
     public boolean isEnabled() {
 
This page took 0.037955 seconds and 5 git commands to generate.