From cf9fcae0723c7b9f20c865312fc564e1b51a83ad Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Fri, 28 Nov 2014 11:20:01 +0100 Subject: [PATCH] Bug 453499: Allow for programmatically adding a connection to the Control UI Change-Id: I0b0dab26c455c371d7fab8fb0aaedf2f4401c19d Signed-off-by: Markus Schorn Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/37481 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam Reviewed-by: Bernd Hufmann --- .../plugin.properties | 5 +- .../plugin.xml | 10 +++ .../ui/views/Workaround_Bug449362.java | 2 +- .../views/handlers/NewConnectionHandler.java | 66 +++++++++++++++---- 4 files changed, 68 insertions(+), 15 deletions(-) diff --git a/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties b/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties index 5c14a87db7..26987c9b0e 100644 --- a/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties +++ b/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties @@ -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 diff --git a/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml b/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml index cacd8e60de..2da1f5e96e 100644 --- a/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml +++ b/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml @@ -31,6 +31,16 @@ description="%commands.control.new.description" id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.newConnection" name="%commands.control.new"> + + + + - * Command handler for creation new connection for trace control. + * Command handler for creation of a new connection for trace control. + *
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. *

* * @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() { -- 2.34.1