Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
60ae41e1 | 2 | * Copyright (c) 2012, 2014 Ericsson and others |
ea21cd65 | 3 | * |
eb1bab5b BH |
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 | |
ea21cd65 AM |
8 | * |
9 | * Contributors: | |
ef5356e1 BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | * Anna Dushistova(Montavista) - [382684] Allow reusing already defined connections that have Files and Shells subsystems | |
b732adaa | 12 | * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE |
eb1bab5b | 13 | **********************************************************************/ |
9bc60be7 | 14 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views.handlers; |
eb1bab5b BH |
15 | |
16 | import org.eclipse.core.commands.ExecutionEvent; | |
17 | import org.eclipse.core.commands.ExecutionException; | |
eb1bab5b | 18 | import org.eclipse.jface.window.Window; |
b732adaa | 19 | import org.eclipse.remote.core.IRemoteConnection; |
9bc60be7 AM |
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; | |
9bc60be7 AM |
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; | |
eb1bab5b BH |
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 | /** | |
eb1bab5b BH |
31 | * <p> |
32 | * Command handler for creation new connection for trace control. | |
33 | * </p> | |
ea21cd65 | 34 | * |
dbd4432d | 35 | * @author Bernd Hufmann |
eb1bab5b | 36 | */ |
498704b3 | 37 | public class NewConnectionHandler extends BaseControlViewHandler { |
eb1bab5b | 38 | |
eb1bab5b BH |
39 | // ------------------------------------------------------------------------ |
40 | // Attributes | |
41 | // ------------------------------------------------------------------------ | |
11252342 | 42 | |
eb1bab5b | 43 | /** |
ea21cd65 | 44 | * The parent trace control component the new node will be added to. |
eb1bab5b | 45 | */ |
4775bcbf | 46 | private ITraceControlComponent fRoot = null; |
eb1bab5b | 47 | |
eb1bab5b BH |
48 | @Override |
49 | public Object execute(ExecutionEvent event) throws ExecutionException { | |
4775bcbf | 50 | assert (fRoot != null); |
eb1bab5b BH |
51 | |
52 | IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); | |
53 | if (window == null) { | |
54 | return false; | |
55 | } | |
56 | ||
eb1bab5b | 57 | // Open dialog box for the node name and address |
d132bcc7 | 58 | final INewConnectionDialog dialog = TraceControlDialogFactory.getInstance().getNewConnectionDialog(); |
eb1bab5b | 59 | |
6503ae0f BH |
60 | if (dialog.open() != Window.OK) { |
61 | return null; | |
62 | } | |
eb1bab5b | 63 | |
b732adaa | 64 | IRemoteConnection host = dialog.getConnection(); |
6503ae0f | 65 | if (host != null) { |
c56972bb BH |
66 | fLock.lock(); |
67 | try { | |
68 | // successful creation of host | |
69 | TargetNodeComponent node = null; | |
b732adaa MS |
70 | if (!fRoot.containsChild(host.getName())) { |
71 | node = new TargetNodeComponent(host.getName(), fRoot, host); | |
c56972bb | 72 | fRoot.addChild(node); |
b732adaa MS |
73 | } else { |
74 | node = (TargetNodeComponent)fRoot.getChild(host.getName()); | |
c56972bb BH |
75 | } |
76 | ||
77 | node.connect(); | |
78 | } finally { | |
79 | fLock.unlock(); | |
6503ae0f | 80 | } |
6503ae0f | 81 | } |
eb1bab5b BH |
82 | return null; |
83 | } | |
84 | ||
eb1bab5b BH |
85 | @Override |
86 | public boolean isEnabled() { | |
ea21cd65 | 87 | |
498704b3 BH |
88 | // Get workbench page for the Control View |
89 | IWorkbenchPage page = getWorkbenchPage(); | |
90 | if (page == null) { | |
eb1bab5b BH |
91 | return false; |
92 | } | |
93 | ||
c56972bb | 94 | ITraceControlComponent root = null; |
eb1bab5b | 95 | |
498704b3 | 96 | // no need to verify part because it has been already done in getWorkbenchPage() |
ea21cd65 | 97 | IWorkbenchPart part = page.getActivePart(); |
c56972bb | 98 | root = ((ControlView) part).getTraceControlRoot(); |
ea21cd65 | 99 | |
c56972bb | 100 | boolean isEnabled = root != null; |
ea21cd65 | 101 | |
c56972bb BH |
102 | fLock.lock(); |
103 | try { | |
104 | fRoot = null; | |
105 | if (isEnabled) { | |
106 | fRoot = root; | |
107 | } | |
108 | } finally { | |
109 | fLock.unlock(); | |
110 | } | |
ea21cd65 | 111 | |
c56972bb | 112 | return isEnabled; |
eb1bab5b BH |
113 | } |
114 | } |