1 /**********************************************************************
2 * Copyright (c) 2012, 2015 Ericsson and others
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 * Anna Dushistova(Montavista) - [382684] Allow reusing already defined connections that have Files and Shells subsystems
12 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
13 **********************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.handlers
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
20 import org
.eclipse
.core
.commands
.ExecutionEvent
;
21 import org
.eclipse
.core
.commands
.ExecutionException
;
22 import org
.eclipse
.jface
.window
.Window
;
23 import org
.eclipse
.remote
.core
.IRemoteConnection
;
24 import org
.eclipse
.remote
.core
.IRemoteConnectionType
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.ControlView
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.INewConnectionDialog
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
30 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.RemoteSystemProxy
;
31 import org
.eclipse
.ui
.IWorkbenchPage
;
32 import org
.eclipse
.ui
.IWorkbenchPart
;
33 import org
.eclipse
.ui
.IWorkbenchWindow
;
34 import org
.eclipse
.ui
.PlatformUI
;
38 * Command handler for creation of a new connection for trace control.
39 * <br> By supplying arguments for the parameters with id {@link #PARAMETER_REMOTE_SERVICES_ID} and
40 * {@link #PARAMETER_CONNECTION_NAME}, the caller can specify the remote connection that will
41 * be added to the trace control. In case one of the optional arguments is not supplied, the handler
42 * opens a dialog for selecting a remote connection.
45 * @author Bernd Hufmann
47 public class NewConnectionHandler
extends BaseControlViewHandler
{
50 * Id of the parameter for the remote services id.
51 * @see NewConnectionHandler
52 * @see IRemoteConnectionType#getId()
54 public static final String PARAMETER_REMOTE_SERVICES_ID
= "org.eclipse.linuxtools.lttng2.control.ui.remoteServicesIdParameter"; //$NON-NLS-1$
56 * Id of the parameter for the name of the remote connection.
57 * @see NewConnectionHandler
58 * @see IRemoteConnection#getName()
60 public static final String PARAMETER_CONNECTION_NAME
= "org.eclipse.linuxtools.lttng2.control.ui.connectionNameParameter"; //$NON-NLS-1$
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
67 * The parent trace control component the new node will be added to.
69 private ITraceControlComponent fRoot
= null;
72 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
73 assert (fRoot
!= null);
75 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
80 IRemoteConnection connection
= getConnection(event
.getParameters());
81 if (connection
!= null) {
84 // successful creation of host
85 TargetNodeComponent node
= null;
86 if (!fRoot
.containsChild(connection
.getName())) {
87 node
= new TargetNodeComponent(connection
.getName(), fRoot
, connection
);
90 node
= (TargetNodeComponent
)fRoot
.getChild(connection
.getName());
101 private static IRemoteConnection
getConnection(Map
<?
,?
> parameters
) {
102 // First check whether arguments have been supplied
103 Object remoteServicesId
= parameters
.get(PARAMETER_REMOTE_SERVICES_ID
);
104 Object connectionName
= parameters
.get(PARAMETER_CONNECTION_NAME
);
105 if ((remoteServicesId
!= null) && (connectionName
!= null)) {
106 return RemoteSystemProxy
.getRemoteConnection(
107 checkNotNull(remoteServicesId
.toString()),
108 checkNotNull(connectionName
.toString()));
111 // Without the arguments, open dialog box for the node name and address
112 final INewConnectionDialog dialog
= TraceControlDialogFactory
.getInstance().getNewConnectionDialog();
113 if (dialog
.open() == Window
.OK
) {
114 return dialog
.getConnection();
121 public boolean isEnabled() {
123 // Get workbench page for the Control View
124 IWorkbenchPage page
= getWorkbenchPage();
129 ITraceControlComponent root
= null;
131 // no need to verify part because it has been already done in getWorkbenchPage()
132 IWorkbenchPart part
= page
.getActivePart();
133 root
= ((ControlView
) part
).getTraceControlRoot();
135 boolean isEnabled
= root
!= null;