Commit | Line | Data |
---|---|---|
6e512b93 | 1 | /******************************************************************************* |
533d0bc3 | 2 | * Copyright (c) 2009, 2015 Ericsson |
cfdb727a | 3 | * |
6e512b93 ASL |
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 | |
cfdb727a | 8 | * |
6e512b93 ASL |
9 | * Contributors: |
10 | * Francois Chouinard - Initial API and implementation | |
eb1bab5b | 11 | * Bernd Hufmann - Filled with content |
b732adaa | 12 | * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE |
6e512b93 ASL |
13 | *******************************************************************************/ |
14 | ||
9bc60be7 | 15 | package org.eclipse.tracecompass.internal.lttng2.control.ui.views; |
6e512b93 | 16 | |
b732adaa MS |
17 | import java.util.ArrayList; |
18 | import java.util.List; | |
19 | ||
b957fb8c BH |
20 | import org.eclipse.core.runtime.IProgressMonitor; |
21 | import org.eclipse.core.runtime.IStatus; | |
22 | import org.eclipse.core.runtime.Status; | |
eb1bab5b BH |
23 | import org.eclipse.jface.action.MenuManager; |
24 | import org.eclipse.jface.viewers.ColumnViewerToolTipSupport; | |
25 | import org.eclipse.jface.viewers.ISelection; | |
d132bcc7 | 26 | import org.eclipse.jface.viewers.StructuredSelection; |
eb1bab5b | 27 | import org.eclipse.jface.viewers.TreeViewer; |
b732adaa | 28 | import org.eclipse.remote.core.IRemoteConnection; |
eb1bab5b | 29 | import org.eclipse.swt.SWT; |
6e512b93 | 30 | import org.eclipse.swt.widgets.Composite; |
eb1bab5b | 31 | import org.eclipse.swt.widgets.Menu; |
9bc60be7 AM |
32 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent; |
33 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponentChangedListener; | |
b732adaa | 34 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent; |
9bc60be7 AM |
35 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceControlContentProvider; |
36 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceControlLabelProvider; | |
37 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceControlRoot; | |
b6b4e8b4 | 38 | import org.eclipse.tracecompass.tmf.remote.core.proxy.TmfRemoteConnectionFactory; |
b732adaa MS |
39 | import org.eclipse.ui.IMemento; |
40 | import org.eclipse.ui.IViewSite; | |
41 | import org.eclipse.ui.PartInitException; | |
6e512b93 | 42 | import org.eclipse.ui.part.ViewPart; |
b957fb8c | 43 | import org.eclipse.ui.progress.UIJob; |
6e512b93 ASL |
44 | |
45 | /** | |
6e512b93 | 46 | * <p> |
cfdb727a | 47 | * View implementation for Trace Control. |
eb1bab5b | 48 | * </p> |
cfdb727a | 49 | * |
dbd4432d | 50 | * @author Bernd Hufmann |
6e512b93 | 51 | */ |
eb1bab5b | 52 | public class ControlView extends ViewPart implements ITraceControlComponentChangedListener { |
6e512b93 | 53 | |
eb1bab5b BH |
54 | // ------------------------------------------------------------------------ |
55 | // Constants | |
56 | // ------------------------------------------------------------------------ | |
11252342 | 57 | |
eb1bab5b BH |
58 | /** |
59 | * View ID. | |
60 | */ | |
115b4a01 | 61 | public static final String ID = "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$ |
6e512b93 | 62 | |
b732adaa MS |
63 | private static final String KEY_REMOTE_CONNECTION_NAME = "rc_name_"; //$NON-NLS-1$ |
64 | private static final String KEY_REMOTE_PROVIDER = "rc_id_"; //$NON-NLS-1$ | |
65 | ||
eb1bab5b BH |
66 | // ------------------------------------------------------------------------ |
67 | // Attributes | |
68 | // ------------------------------------------------------------------------ | |
69 | ||
70 | /** | |
71 | * The tree viewer. | |
72 | */ | |
73 | private TreeViewer fTreeViewer = null; | |
cfdb727a | 74 | |
eb1bab5b | 75 | /** |
cfdb727a | 76 | * The trace control root node. This provides access to the whole model. |
eb1bab5b BH |
77 | */ |
78 | private ITraceControlComponent fRoot = null; | |
cfdb727a | 79 | |
b732adaa MS |
80 | private List<IRemoteConnection> fInitialConnections; |
81 | ||
eb1bab5b BH |
82 | // ------------------------------------------------------------------------ |
83 | // Accessors | |
84 | // ------------------------------------------------------------------------ | |
49ffadb7 | 85 | |
12c155f5 | 86 | /** |
49ffadb7 | 87 | * Returns the trace control tree node (model) |
cfdb727a | 88 | * |
49ffadb7 | 89 | * @return the trace control tree node (model). |
eb1bab5b BH |
90 | */ |
91 | public ITraceControlComponent getTraceControlRoot() { | |
92 | return fRoot; | |
12c155f5 FC |
93 | } |
94 | ||
eb1bab5b BH |
95 | // ------------------------------------------------------------------------ |
96 | // Operations | |
97 | // ------------------------------------------------------------------------ | |
98 | ||
12c155f5 FC |
99 | @Override |
100 | public void createPartControl(Composite parent) { | |
eb1bab5b | 101 | // Create tree viewer |
bbb3538a | 102 | fTreeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); |
eb1bab5b BH |
103 | ColumnViewerToolTipSupport.enableFor(fTreeViewer); |
104 | ||
105 | fTreeViewer.setContentProvider(new TraceControlContentProvider()); | |
106 | fTreeViewer.setLabelProvider(new TraceControlLabelProvider()); | |
107 | ||
108 | // Create model root | |
109 | fRoot = new TraceControlRoot(); | |
110 | fRoot.addComponentListener(this); | |
b732adaa MS |
111 | if (fInitialConnections != null) { |
112 | for (IRemoteConnection rc : fInitialConnections) { | |
113 | TargetNodeComponent node = new TargetNodeComponent(rc.getName(), fRoot, rc); | |
114 | fRoot.addChild(node); | |
115 | } | |
116 | fInitialConnections = null; | |
117 | } | |
eb1bab5b | 118 | fTreeViewer.setInput(fRoot); |
12c155f5 | 119 | |
eb1bab5b BH |
120 | // Create context menu for the tree viewer |
121 | createContextMenu(); | |
cfdb727a | 122 | |
eb1bab5b | 123 | getSite().setSelectionProvider(fTreeViewer); |
b732adaa MS |
124 | } |
125 | ||
126 | @Override | |
127 | public void saveState(IMemento memento) { | |
128 | int i = 0; | |
129 | for (ITraceControlComponent cmp : fRoot.getChildren()) { | |
130 | if (cmp instanceof TargetNodeComponent) { | |
d8a4fd60 | 131 | IRemoteConnection rc = ((TargetNodeComponent) cmp).getRemoteSystemProxy().getRemoteConnection(); |
533d0bc3 | 132 | memento.putString(KEY_REMOTE_PROVIDER + i, rc.getConnectionType().getId()); |
b732adaa MS |
133 | memento.putString(KEY_REMOTE_CONNECTION_NAME + i, rc.getName()); |
134 | i++; | |
135 | } | |
136 | } | |
137 | super.saveState(memento); | |
138 | } | |
cfdb727a | 139 | |
b732adaa MS |
140 | |
141 | @Override | |
142 | public void init(IViewSite site, IMemento memento) throws PartInitException { | |
143 | super.init(site, memento); | |
144 | if (memento != null) { | |
145 | fInitialConnections = new ArrayList<>(); | |
146 | for(int i = 0; ; i++) { | |
147 | String id = memento.getString(KEY_REMOTE_PROVIDER + i); | |
148 | String name = memento.getString(KEY_REMOTE_CONNECTION_NAME + i); | |
533d0bc3 | 149 | if ((id == null) || (name == null)) { |
b732adaa MS |
150 | break; |
151 | } | |
b6b4e8b4 | 152 | IRemoteConnection conn = TmfRemoteConnectionFactory.getRemoteConnection(id, name); |
533d0bc3 BH |
153 | if (conn != null) { |
154 | fInitialConnections.add(conn); | |
b732adaa MS |
155 | } |
156 | } | |
157 | } | |
12c155f5 FC |
158 | } |
159 | ||
12c155f5 FC |
160 | @Override |
161 | public void setFocus() { | |
eb1bab5b | 162 | fTreeViewer.getControl().setFocus(); |
eb1bab5b | 163 | } |
cfdb727a | 164 | |
eb1bab5b BH |
165 | @Override |
166 | public void componentAdded(ITraceControlComponent parent, ITraceControlComponent component) { | |
b957fb8c | 167 | componentChanged(parent); |
eb1bab5b | 168 | } |
12c155f5 | 169 | |
eb1bab5b BH |
170 | @Override |
171 | public void componentRemoved(ITraceControlComponent parent, ITraceControlComponent component) { | |
b957fb8c | 172 | componentChanged(parent); |
12c155f5 | 173 | } |
6e512b93 | 174 | |
eb1bab5b | 175 | @Override |
b957fb8c | 176 | public void componentChanged(final ITraceControlComponent component) { |
eb1bab5b BH |
177 | if (fTreeViewer.getTree().isDisposed()) { |
178 | return; | |
179 | } | |
180 | ||
b957fb8c | 181 | UIJob myJob = new UIJob("Refresh") { //$NON-NLS-1$ |
eb1bab5b | 182 | @Override |
b957fb8c | 183 | public IStatus runInUIThread(IProgressMonitor monitor) { |
eb1bab5b | 184 | if (fTreeViewer.getTree().isDisposed()) { |
b957fb8c | 185 | return Status.OK_STATUS; |
eb1bab5b | 186 | } |
5293eb3f | 187 | |
b957fb8c BH |
188 | fTreeViewer.refresh(component); |
189 | ||
cfdb727a | 190 | // Change selection needed |
eb1bab5b BH |
191 | final ISelection sel = fTreeViewer.getSelection(); |
192 | fTreeViewer.setSelection(null); | |
193 | fTreeViewer.setSelection(sel); | |
b957fb8c | 194 | |
5293eb3f BH |
195 | // Show component that was changed |
196 | fTreeViewer.reveal(component); | |
197 | ||
b957fb8c | 198 | return Status.OK_STATUS; |
eb1bab5b | 199 | } |
b957fb8c BH |
200 | }; |
201 | myJob.setUser(false); | |
6fd3c6e9 | 202 | myJob.setSystem(true); |
b957fb8c | 203 | myJob.schedule(); |
eb1bab5b | 204 | } |
cfdb727a | 205 | |
d132bcc7 BH |
206 | /** |
207 | * Sets the selected component in the tree | |
208 | * @param component - component to select | |
209 | */ | |
210 | public void setSelection(ITraceControlComponent component) { | |
b957fb8c BH |
211 | ITraceControlComponent[] components = new ITraceControlComponent[1]; |
212 | components[0] = component; | |
213 | setSelection(components); | |
d132bcc7 BH |
214 | } |
215 | ||
216 | /** | |
217 | * Sets the selected components in the tree | |
cfdb727a | 218 | * @param components - array of components to select |
d132bcc7 BH |
219 | */ |
220 | public void setSelection(ITraceControlComponent[] components) { | |
b957fb8c BH |
221 | final StructuredSelection selection = new StructuredSelection(components); |
222 | UIJob myJob = new UIJob("Select") { //$NON-NLS-1$ | |
223 | @Override | |
224 | public IStatus runInUIThread(IProgressMonitor monitor) { | |
225 | fTreeViewer.setSelection(selection); | |
226 | return Status.OK_STATUS; | |
227 | } | |
228 | }; | |
229 | myJob.setUser(false); | |
230 | myJob.schedule(); | |
d132bcc7 | 231 | } |
cfdb727a | 232 | |
eb1bab5b BH |
233 | // ------------------------------------------------------------------------ |
234 | // Helper methods | |
235 | // ------------------------------------------------------------------------ | |
c5f68877 BH |
236 | /** |
237 | * Creates the context sensitive menu. | |
238 | */ | |
eb1bab5b | 239 | private void createContextMenu() { |
eb1bab5b BH |
240 | // First we create a menu Manager |
241 | final MenuManager menuManager = new MenuManager(); | |
242 | final Menu menu = menuManager.createContextMenu(fTreeViewer.getTree()); | |
243 | // Set the MenuManager | |
244 | fTreeViewer.getTree().setMenu(menu); | |
245 | getSite().registerContextMenu(menuManager, fTreeViewer); | |
246 | } | |
6e512b93 | 247 | } |