1 /**********************************************************************
2 * Copyright (c) 2012, 2014 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 **********************************************************************/
13 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.handlers
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Arrays
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import org
.eclipse
.jface
.window
.Window
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.INewConnectionDialog
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.Messages
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.remote
.IRemoteSystemProxy
;
29 import org
.eclipse
.rse
.core
.IRSESystemType
;
30 import org
.eclipse
.rse
.core
.RSECorePlugin
;
31 import org
.eclipse
.rse
.core
.model
.IHost
;
32 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
33 import org
.eclipse
.rse
.core
.subsystems
.ISubSystem
;
34 import org
.eclipse
.rse
.subsystems
.files
.core
.servicesubsystem
.IFileServiceSubSystem
;
35 import org
.eclipse
.ui
.IWorkbenchPage
;
36 import org
.eclipse
.ui
.IWorkbenchPart
;
37 import org
.eclipse
.ui
.IWorkbenchWindow
;
38 import org
.eclipse
.ui
.PlatformUI
;
42 * Command handler for creation new connection for trace control.
45 * @author Bernd Hufmann
47 public class NewConnectionHandler
extends BaseControlViewHandler
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * The trace control system type defined for LTTng version 2.0 and later.
56 public static final String TRACE_CONTROL_SYSTEM_TYPE
= "org.eclipse.linuxtools.internal.lttng2.ui.control.systemType"; //$NON-NLS-1$
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
63 * The parent trace control component the new node will be added to.
65 private ITraceControlComponent fRoot
= null;
68 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
69 assert (fRoot
!= null);
71 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
76 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
78 // get system type definition for LTTng 2.x connection
79 IRSESystemType sysType
= RSECorePlugin
.getTheCoreRegistry().getSystemTypeById(TRACE_CONTROL_SYSTEM_TYPE
);
81 // get all hosts for this system type
82 IHost
[] hosts
= getSuitableHosts();
84 // Open dialog box for the node name and address
85 final INewConnectionDialog dialog
= TraceControlDialogFactory
.getInstance().getNewConnectionDialog();
86 dialog
.setTraceControlParent(fRoot
);
87 dialog
.setHosts(hosts
);
88 dialog
.setPort(IRemoteSystemProxy
.INVALID_PORT_NUMBER
);
90 if (dialog
.open() != Window
.OK
) {
94 String hostName
= dialog
.getConnectionName();
95 String hostAddress
= dialog
.getHostName();
96 int port
= dialog
.getPort();
98 // get the singleton RSE registry
101 for (int i
= 0; i
< hosts
.length
; i
++) {
102 if (hosts
[i
].getAliasName().equals(hostName
)) {
109 // if there's no host then we will create it
111 // create the host object as an SSH Only connection
112 host
= registry
.createHost(
113 sysType
, //System Type Name
114 hostName
, //Connection name
115 hostAddress
, //IP Address
116 "Connection to Host"); //description //$NON-NLS-1$
118 catch (Exception e
) {
119 MessageDialog
.openError(window
.getShell(),
120 Messages
.TraceControl_EclipseCommandFailure
,
121 Messages
.TraceControl_NewNodeCreationFailure
+ " (" + hostName
+ ", " + hostAddress
+ ")" + ":\n" + e
.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
129 // successful creation of host
130 TargetNodeComponent node
= null;
131 if (!fRoot
.containsChild(hostName
)) {
132 node
= new TargetNodeComponent(hostName
, fRoot
, host
);
134 fRoot
.addChild(node
);
137 node
= (TargetNodeComponent
)fRoot
.getChild(hostName
);
148 private static IHost
[] getSuitableHosts() {
149 // need shells and files
150 ArrayList
<IHost
> result
= new ArrayList
<>();
151 ArrayList
<IHost
> shellConnections
= new ArrayList
<>(
152 Arrays
.asList(RSECorePlugin
.getTheSystemRegistry()
153 .getHostsBySubSystemConfigurationCategory("shells"))); //$NON-NLS-1$
155 for (IHost connection
: shellConnections
) {
156 if (!connection
.getSystemType().isLocal()) {
157 ISubSystem
[] subSystems
= connection
.getSubSystems();
158 for (int i
= 0; i
< subSystems
.length
; i
++) {
159 if (subSystems
[i
] instanceof IFileServiceSubSystem
) {
160 result
.add(connection
);
167 return result
.toArray(new IHost
[result
.size()]);
171 public boolean isEnabled() {
173 // Get workbench page for the Control View
174 IWorkbenchPage page
= getWorkbenchPage();
179 ITraceControlComponent root
= null;
181 // no need to verify part because it has been already done in getWorkbenchPage()
182 IWorkbenchPart part
= page
.getActivePart();
183 root
= ((ControlView
) part
).getTraceControlRoot();
185 boolean isEnabled
= root
!= null;