1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 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 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Filled with content
12 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
;
17 import java
.util
.ArrayList
;
18 import java
.util
.List
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.jface
.action
.MenuManager
;
24 import org
.eclipse
.jface
.viewers
.ColumnViewerToolTipSupport
;
25 import org
.eclipse
.jface
.viewers
.ISelection
;
26 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
27 import org
.eclipse
.jface
.viewers
.TreeViewer
;
28 import org
.eclipse
.remote
.core
.IRemoteConnection
;
29 import org
.eclipse
.remote
.core
.IRemoteServices
;
30 import org
.eclipse
.remote
.core
.RemoteServices
;
31 import org
.eclipse
.swt
.SWT
;
32 import org
.eclipse
.swt
.widgets
.Composite
;
33 import org
.eclipse
.swt
.widgets
.Menu
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
35 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponentChangedListener
;
36 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
37 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceControlContentProvider
;
38 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceControlLabelProvider
;
39 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TraceControlRoot
;
40 import org
.eclipse
.ui
.IMemento
;
41 import org
.eclipse
.ui
.IViewSite
;
42 import org
.eclipse
.ui
.PartInitException
;
43 import org
.eclipse
.ui
.part
.ViewPart
;
44 import org
.eclipse
.ui
.progress
.UIJob
;
48 * View implementation for Trace Control.
51 * @author Bernd Hufmann
53 public class ControlView
extends ViewPart
implements ITraceControlComponentChangedListener
{
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
62 public static final String ID
= "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$
64 private static final String KEY_REMOTE_CONNECTION_NAME
= "rc_name_"; //$NON-NLS-1$
65 private static final String KEY_REMOTE_PROVIDER
= "rc_id_"; //$NON-NLS-1$
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
74 private TreeViewer fTreeViewer
= null;
77 * The trace control root node. This provides access to the whole model.
79 private ITraceControlComponent fRoot
= null;
81 private List
<IRemoteConnection
> fInitialConnections
;
83 // ------------------------------------------------------------------------
85 // ------------------------------------------------------------------------
88 * Returns the trace control tree node (model)
90 * @return the trace control tree node (model).
92 public ITraceControlComponent
getTraceControlRoot() {
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 public void createPartControl(Composite parent
) {
102 // Create tree viewer
103 fTreeViewer
= new TreeViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
104 ColumnViewerToolTipSupport
.enableFor(fTreeViewer
);
106 fTreeViewer
.setContentProvider(new TraceControlContentProvider());
107 fTreeViewer
.setLabelProvider(new TraceControlLabelProvider());
110 fRoot
= new TraceControlRoot();
111 fRoot
.addComponentListener(this);
112 if (fInitialConnections
!= null) {
113 for (IRemoteConnection rc
: fInitialConnections
) {
114 TargetNodeComponent node
= new TargetNodeComponent(rc
.getName(), fRoot
, rc
);
115 fRoot
.addChild(node
);
117 fInitialConnections
= null;
119 fTreeViewer
.setInput(fRoot
);
121 // Create context menu for the tree viewer
124 getSite().setSelectionProvider(fTreeViewer
);
128 public void saveState(IMemento memento
) {
130 for (ITraceControlComponent cmp
: fRoot
.getChildren()) {
131 if (cmp
instanceof TargetNodeComponent
) {
132 IRemoteConnection rc
= ((TargetNodeComponent
) cmp
).getRemoteConnection();
133 memento
.putString(KEY_REMOTE_PROVIDER
+ i
, rc
.getRemoteServices().getId());
134 memento
.putString(KEY_REMOTE_CONNECTION_NAME
+ i
, rc
.getName());
138 super.saveState(memento
);
143 public void init(IViewSite site
, IMemento memento
) throws PartInitException
{
144 super.init(site
, memento
);
145 if (memento
!= null) {
146 fInitialConnections
= new ArrayList
<>();
147 for(int i
= 0; ; i
++) {
148 String id
= memento
.getString(KEY_REMOTE_PROVIDER
+ i
);
149 String name
= memento
.getString(KEY_REMOTE_CONNECTION_NAME
+ i
);
150 if (id
== null || name
== null) {
153 if (!Workaround_Bug449362
.triggerRSEStartup(id
)) {
154 // Skip the connection in order to avoid an infinite loop
156 IRemoteServices rs
= RemoteServices
.getRemoteServices(id
);
158 IRemoteConnection rc
= rs
.getConnectionManager().getConnection(name
);
160 fInitialConnections
.add(rc
);
169 public void setFocus() {
170 fTreeViewer
.getControl().setFocus();
174 public void componentAdded(ITraceControlComponent parent
, ITraceControlComponent component
) {
175 componentChanged(parent
);
179 public void componentRemoved(ITraceControlComponent parent
, ITraceControlComponent component
) {
180 componentChanged(parent
);
184 public void componentChanged(final ITraceControlComponent component
) {
185 if (fTreeViewer
.getTree().isDisposed()) {
189 UIJob myJob
= new UIJob("Refresh") { //$NON-NLS-1$
191 public IStatus
runInUIThread(IProgressMonitor monitor
) {
192 if (fTreeViewer
.getTree().isDisposed()) {
193 return Status
.OK_STATUS
;
196 fTreeViewer
.refresh(component
);
198 // Change selection needed
199 final ISelection sel
= fTreeViewer
.getSelection();
200 fTreeViewer
.setSelection(null);
201 fTreeViewer
.setSelection(sel
);
203 // Show component that was changed
204 fTreeViewer
.reveal(component
);
206 return Status
.OK_STATUS
;
209 myJob
.setUser(false);
210 myJob
.setSystem(true);
215 * Sets the selected component in the tree
216 * @param component - component to select
218 public void setSelection(ITraceControlComponent component
) {
219 ITraceControlComponent
[] components
= new ITraceControlComponent
[1];
220 components
[0] = component
;
221 setSelection(components
);
225 * Sets the selected components in the tree
226 * @param components - array of components to select
228 public void setSelection(ITraceControlComponent
[] components
) {
229 final StructuredSelection selection
= new StructuredSelection(components
);
230 UIJob myJob
= new UIJob("Select") { //$NON-NLS-1$
232 public IStatus
runInUIThread(IProgressMonitor monitor
) {
233 fTreeViewer
.setSelection(selection
);
234 return Status
.OK_STATUS
;
237 myJob
.setUser(false);
241 // ------------------------------------------------------------------------
243 // ------------------------------------------------------------------------
245 * Creates the context sensitive menu.
247 private void createContextMenu() {
248 // First we create a menu Manager
249 final MenuManager menuManager
= new MenuManager();
250 final Menu menu
= menuManager
.createContextMenu(fTreeViewer
.getTree());
251 // Set the MenuManager
252 fTreeViewer
.getTree().setMenu(menu
);
253 getSite().registerContextMenu(menuManager
, fTreeViewer
);