1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.handlers
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.IHandler
;
17 import org
.eclipse
.core
.commands
.IHandlerListener
;
18 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
19 import org
.eclipse
.jface
.window
.Window
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.ControlView
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.Messages
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
.INewConnectionDialog
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
.NewConnectionDialog
;
24 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
25 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
26 import org
.eclipse
.rse
.core
.IRSESystemType
;
27 import org
.eclipse
.rse
.core
.RSECorePlugin
;
28 import org
.eclipse
.rse
.core
.model
.IHost
;
29 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
30 import org
.eclipse
.ui
.IWorkbenchPage
;
31 import org
.eclipse
.ui
.IWorkbenchPart
;
32 import org
.eclipse
.ui
.IWorkbenchWindow
;
33 import org
.eclipse
.ui
.PlatformUI
;
36 * <b><u>NewConnectionHandler</u></b>
38 * Command handler for creation new connection for trace control.
41 public class NewConnectionHandler
implements IHandler
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 * The trace control system type defined for LTTng version 2.0 and later.
49 public final static String TRACE_CONTROL_SYSTEM_TYPE
= "org.eclipse.linuxtools.lttng.ui.control.systemType"; //$NON-NLS-1$
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 * The parent trace control component the new node will be added to.
57 private ITraceControlComponent fParent
= null;
61 * @see org.eclipse.core.commands.IHandler#dispose()
64 public void dispose() {
69 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
72 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
73 assert (fParent
!= null);
75 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
80 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
82 // get system type definition for LTTng 2.x connection
83 IRSESystemType sysType
= RSECorePlugin
.getTheCoreRegistry().getSystemTypeById(TRACE_CONTROL_SYSTEM_TYPE
);
85 // get all hosts for this system type
86 IHost
[] hosts
= registry
.getHostsBySystemType(sysType
);
88 // Open dialog box for the node name and address
89 INewConnectionDialog dialog
= new NewConnectionDialog(window
.getShell(), fParent
, hosts
);
91 if (dialog
.open() == Window
.OK
) {
93 String hostName
= dialog
.getNodeName();
94 String hostAddress
= dialog
.getNodeAddress();
96 // String hostName = "hallo";
97 // String hostAddress = "142.133.166.54";
98 // String hostName = "ha";
99 // String hostAddress = "192.168.0.196";
100 // get the singleton RSE registry
103 for (int i
= 0; i
< hosts
.length
; i
++) {
104 if (hosts
[i
].getAliasName().equals(hostName
)) {
111 // if there's no host then we will create it
114 // create the host object as an SSH Only connection
115 host
= registry
.createHost(
116 sysType
, //System Type Name
117 hostName
, //Connection name
118 hostAddress
, //IP Address
119 "Connection to Host"); //description //$NON-NLS-1$
121 catch (Exception e
) {
122 MessageDialog
.openError(window
.getShell(),
123 Messages
.TraceControl_EclipseCommandFailure
,
124 Messages
.TraceControl_NewNodeCreationFailure
+ " (" + hostName
+ ", " + hostAddress
+ ")" + ":\n" + e
.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
130 // successful creation of host
131 TargetNodeComponent node
= null;
132 if (!fParent
.containsChild(hostName
)) {
133 node
= new TargetNodeComponent(hostName
, fParent
, host
);
134 fParent
.addChild(node
);
137 node
= (TargetNodeComponent
)fParent
.getChild(hostName
);
148 * @see org.eclipse.core.commands.IHandler#isEnabled()
151 public boolean isEnabled() {
154 // Check if we are closing down
155 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
156 if (window
== null) {
160 // Check if we are in the Project View
161 IWorkbenchPage page
= window
.getActivePage();
162 if (page
== null) return false;
163 IWorkbenchPart part
= page
.getActivePart();
164 if (!(part
instanceof ControlView
)) {
168 fParent
= ((ControlView
) part
).getTraceControlRoot();
170 return (fParent
!= null);
175 * @see org.eclipse.core.commands.IHandler#isHandled()
178 public boolean isHandled() {
179 // TODO Auto-generated method stub
183 // ------------------------------------------------------------------------
185 // ------------------------------------------------------------------------
189 * @see org.eclipse.core.commands.IHandler#addHandlerListener(org.eclipse.core.commands.IHandlerListener)
192 public void addHandlerListener(IHandlerListener handlerListener
) {
197 * @see org.eclipse.core.commands.IHandler#removeHandlerListener(org.eclipse.core.commands.IHandlerListener)
200 public void removeHandlerListener(IHandlerListener handlerListener
) {