Bug 448058: Replace RSE by org.eclipse.remote
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui / src / org / eclipse / tracecompass / internal / lttng2 / control / ui / views / handlers / NewConnectionHandler.java
1 /**********************************************************************
2 * Copyright (c) 2012, 2014 Ericsson and others
3 *
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
8 *
9 * Contributors:
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;
15
16 import org.eclipse.core.commands.ExecutionEvent;
17 import org.eclipse.core.commands.ExecutionException;
18 import org.eclipse.jface.window.Window;
19 import org.eclipse.remote.core.IRemoteConnection;
20 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
21 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.INewConnectionDialog;
22 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
23 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
24 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
25 import org.eclipse.ui.IWorkbenchPage;
26 import org.eclipse.ui.IWorkbenchPart;
27 import org.eclipse.ui.IWorkbenchWindow;
28 import org.eclipse.ui.PlatformUI;
29
30 /**
31 * <p>
32 * Command handler for creation new connection for trace control.
33 * </p>
34 *
35 * @author Bernd Hufmann
36 */
37 public class NewConnectionHandler extends BaseControlViewHandler {
38
39 // ------------------------------------------------------------------------
40 // Attributes
41 // ------------------------------------------------------------------------
42
43 /**
44 * The parent trace control component the new node will be added to.
45 */
46 private ITraceControlComponent fRoot = null;
47
48 @Override
49 public Object execute(ExecutionEvent event) throws ExecutionException {
50 assert (fRoot != null);
51
52 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
53 if (window == null) {
54 return false;
55 }
56
57 // Open dialog box for the node name and address
58 final INewConnectionDialog dialog = TraceControlDialogFactory.getInstance().getNewConnectionDialog();
59
60 if (dialog.open() != Window.OK) {
61 return null;
62 }
63
64 IRemoteConnection host = dialog.getConnection();
65 if (host != null) {
66 fLock.lock();
67 try {
68 // successful creation of host
69 TargetNodeComponent node = null;
70 if (!fRoot.containsChild(host.getName())) {
71 node = new TargetNodeComponent(host.getName(), fRoot, host);
72 fRoot.addChild(node);
73 } else {
74 node = (TargetNodeComponent)fRoot.getChild(host.getName());
75 }
76
77 node.connect();
78 } finally {
79 fLock.unlock();
80 }
81 }
82 return null;
83 }
84
85 @Override
86 public boolean isEnabled() {
87
88 // Get workbench page for the Control View
89 IWorkbenchPage page = getWorkbenchPage();
90 if (page == null) {
91 return false;
92 }
93
94 ITraceControlComponent root = null;
95
96 // no need to verify part because it has been already done in getWorkbenchPage()
97 IWorkbenchPart part = page.getActivePart();
98 root = ((ControlView) part).getTraceControlRoot();
99
100 boolean isEnabled = root != null;
101
102 fLock.lock();
103 try {
104 fRoot = null;
105 if (isEnabled) {
106 fRoot = root;
107 }
108 } finally {
109 fLock.unlock();
110 }
111
112 return isEnabled;
113 }
114 }
This page took 0.035269 seconds and 5 git commands to generate.