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
.Command
;
21 import org
.eclipse
.core
.commands
.ExecutionEvent
;
22 import org
.eclipse
.core
.commands
.ExecutionException
;
23 import org
.eclipse
.jface
.window
.Window
;
24 import org
.eclipse
.remote
.core
.IRemoteConnection
;
25 import org
.eclipse
.remote
.core
.IRemoteConnectionType
;
26 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.ControlView
;
27 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.INewConnectionDialog
;
28 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
29 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
30 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
31 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
32 import org
.eclipse
.ui
.IWorkbenchPage
;
33 import org
.eclipse
.ui
.IWorkbenchPart
;
34 import org
.eclipse
.ui
.IWorkbenchWindow
;
35 import org
.eclipse
.ui
.PlatformUI
;
36 import org
.eclipse
.ui
.commands
.ICommandService
;
37 import org
.eclipse
.ui
.services
.IServiceLocator
;
41 * Command handler for creation of a new connection for trace control.
42 * <br> By supplying arguments for the parameters with id {@link #PARAMETER_REMOTE_SERVICES_ID} and
43 * {@link #PARAMETER_CONNECTION_NAME}, the caller can specify the remote connection that will
44 * be added to the trace control. In case one of the optional arguments is not supplied, the handler
45 * opens a dialog for selecting a remote connection.
48 * @author Bernd Hufmann
50 public class NewConnectionHandler
extends BaseControlViewHandler
{
53 * Id of the parameter for the remote services id.
54 * @see NewConnectionHandler
55 * @see IRemoteConnectionType#getId()
57 public static final String PARAMETER_REMOTE_SERVICES_ID
= "org.eclipse.linuxtools.lttng2.control.ui.remoteServicesIdParameter"; //$NON-NLS-1$
59 * Id of the parameter for the name of the remote connection.
60 * @see NewConnectionHandler
61 * @see IRemoteConnection#getName()
63 public static final String PARAMETER_CONNECTION_NAME
= "org.eclipse.linuxtools.lttng2.control.ui.connectionNameParameter"; //$NON-NLS-1$
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
70 * The parent trace control component the new node will be added to.
72 private ITraceControlComponent fRoot
= null;
75 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
76 assert (fRoot
!= null);
78 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
83 IRemoteConnection connection
= getConnection(event
.getParameters());
84 if (connection
!= null) {
90 // successful creation of host
91 TargetNodeComponent node
= null;
92 if (!fRoot
.containsChild(connection
.getName())) {
93 node
= new TargetNodeComponent(connection
.getName(), fRoot
, connection
);
96 node
= (TargetNodeComponent
)fRoot
.getChild(connection
.getName());
105 // Obtain IServiceLocator implementer, e.g. from PlatformUI.getWorkbench():
106 IServiceLocator serviceLocator
= PlatformUI
.getWorkbench();
107 // or a site from within a editor or view:
108 // IServiceLocator serviceLocator = getSite();
110 ICommandService commandService
= serviceLocator
.getService(ICommandService
.class);
113 // Lookup commmand with its ID
114 Command command
= commandService
.getCommand("org.eclipse.linuxtools.internal.lttng2.ui.commands.control.createSession"); //$NON-NLS-1$
116 // Optionally pass a ExecutionEvent instance, default no-param arg creates blank event
118 // execute new connection command directly
119 command
.executeWithChecks(new ExecutionEvent());
120 // FIX THIS OH GOD THE INHUMANITY
121 } catch (Exception e
) {
129 private static IRemoteConnection
getConnection(Map
<?
,?
> parameters
) {
130 // First check whether arguments have been supplied
131 Object remoteServicesId
= parameters
.get(PARAMETER_REMOTE_SERVICES_ID
);
132 Object connectionName
= parameters
.get(PARAMETER_CONNECTION_NAME
);
133 if ((remoteServicesId
!= null) && (connectionName
!= null)) {
134 return TmfRemoteConnectionFactory
.getRemoteConnection(
135 checkNotNull(remoteServicesId
.toString()),
136 checkNotNull(connectionName
.toString()));
139 // Without the arguments, open dialog box for the node name and address
140 final INewConnectionDialog dialog
= TraceControlDialogFactory
.getInstance().getNewConnectionDialog();
141 if (dialog
.open() == Window
.OK
) {
142 return dialog
.getConnection();
149 public boolean isEnabled() {
151 // Get workbench page for the Control View
152 IWorkbenchPage page
= getWorkbenchPage();
157 ITraceControlComponent root
= null;
159 // no need to verify part because it has been already done in getWorkbenchPage()
160 IWorkbenchPart part
= page
.getActivePart();
161 root
= ((ControlView
) part
).getTraceControlRoot();
163 boolean isEnabled
= root
!= null;