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
.internal
.lttng2
.ui
.views
.control
.handlers
;
14 import org
.eclipse
.core
.commands
.ExecutionEvent
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
17 import org
.eclipse
.jface
.window
.Window
;
18 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.INewConnectionDialog
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
24 import org
.eclipse
.rse
.core
.IRSESystemType
;
25 import org
.eclipse
.rse
.core
.RSECorePlugin
;
26 import org
.eclipse
.rse
.core
.model
.IHost
;
27 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
28 import org
.eclipse
.ui
.IWorkbenchPage
;
29 import org
.eclipse
.ui
.IWorkbenchPart
;
30 import org
.eclipse
.ui
.IWorkbenchWindow
;
31 import org
.eclipse
.ui
.PlatformUI
;
34 * <b><u>NewConnectionHandler</u></b>
36 * Command handler for creation new connection for trace control.
39 public class NewConnectionHandler
extends BaseControlViewHandler
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
45 * The trace control system type defined for LTTng version 2.0 and later.
47 public final static String TRACE_CONTROL_SYSTEM_TYPE
= "org.eclipse.linuxtools.internal.lttng2.ui.control.systemType"; //$NON-NLS-1$
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
53 * The parent trace control component the new node will be added to.
55 private ITraceControlComponent fRoot
= null;
59 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
62 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
63 assert (fRoot
!= null);
65 IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
70 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
72 // get system type definition for LTTng 2.x connection
73 IRSESystemType sysType
= RSECorePlugin
.getTheCoreRegistry().getSystemTypeById(TRACE_CONTROL_SYSTEM_TYPE
);
75 // get all hosts for this system type
76 IHost
[] hosts
= registry
.getHostsBySystemType(sysType
);
78 // Open dialog box for the node name and address
79 final INewConnectionDialog dialog
= TraceControlDialogFactory
.getInstance().getNewConnectionDialog();
80 dialog
.setTraceControlParent(fRoot
);
81 dialog
.setHosts(hosts
);
83 if (dialog
.open() != Window
.OK
) {
87 String hostName
= dialog
.getConnectionName();
88 String hostAddress
= dialog
.getHostName();
90 // get the singleton RSE registry
93 for (int i
= 0; i
< hosts
.length
; i
++) {
94 if (hosts
[i
].getAliasName().equals(hostName
)) {
101 // if there's no host then we will create it
103 // create the host object as an SSH Only connection
104 host
= registry
.createHost(
105 sysType
, //System Type Name
106 hostName
, //Connection name
107 hostAddress
, //IP Address
108 "Connection to Host"); //description //$NON-NLS-1$
110 catch (Exception e
) {
111 MessageDialog
.openError(window
.getShell(),
112 Messages
.TraceControl_EclipseCommandFailure
,
113 Messages
.TraceControl_NewNodeCreationFailure
+ " (" + hostName
+ ", " + hostAddress
+ ")" + ":\n" + e
.toString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
119 // successful creation of host
120 TargetNodeComponent node
= null;
121 if (!fRoot
.containsChild(hostName
)) {
122 node
= new TargetNodeComponent(hostName
, fRoot
, host
);
123 fRoot
.addChild(node
);
126 node
= (TargetNodeComponent
)fRoot
.getChild(hostName
);
137 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
140 public boolean isEnabled() {
142 // Get workbench page for the Control View
143 IWorkbenchPage page
= getWorkbenchPage();
150 // no need to verify part because it has been already done in getWorkbenchPage()
151 IWorkbenchPart part
= page
.getActivePart();
152 fRoot
= ((ControlView
) part
).getTraceControlRoot();
154 return (fRoot
!= null);