1 /*******************************************************************************
2 * Copyright (c) 2009, 2015 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
.swt
.SWT
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Menu
;
32 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
33 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponentChangedListener
;
34 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
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
;
38 import org
.eclipse
.tracecompass
.tmf
.remote
.core
.proxy
.TmfRemoteConnectionFactory
;
39 import org
.eclipse
.ui
.IMemento
;
40 import org
.eclipse
.ui
.IViewSite
;
41 import org
.eclipse
.ui
.PartInitException
;
42 import org
.eclipse
.ui
.part
.ViewPart
;
43 import org
.eclipse
.ui
.progress
.UIJob
;
47 * View implementation for Trace Control.
50 * @author Bernd Hufmann
52 public class ControlView
extends ViewPart
implements ITraceControlComponentChangedListener
{
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
61 public static final String ID
= "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$
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$
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
73 private TreeViewer fTreeViewer
= null;
76 * The trace control root node. This provides access to the whole model.
78 private ITraceControlComponent fRoot
= null;
80 private List
<IRemoteConnection
> fInitialConnections
;
82 // ------------------------------------------------------------------------
84 // ------------------------------------------------------------------------
87 * Returns the trace control tree node (model)
89 * @return the trace control tree node (model).
91 public ITraceControlComponent
getTraceControlRoot() {
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
100 public void createPartControl(Composite parent
) {
101 // Create tree viewer
102 fTreeViewer
= new TreeViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
103 ColumnViewerToolTipSupport
.enableFor(fTreeViewer
);
105 fTreeViewer
.setContentProvider(new TraceControlContentProvider());
106 fTreeViewer
.setLabelProvider(new TraceControlLabelProvider());
109 fRoot
= new TraceControlRoot();
110 fRoot
.addComponentListener(this);
111 if (fInitialConnections
!= null) {
112 for (IRemoteConnection rc
: fInitialConnections
) {
113 TargetNodeComponent node
= new TargetNodeComponent(rc
.getName(), fRoot
, rc
);
114 fRoot
.addChild(node
);
116 fInitialConnections
= null;
118 fTreeViewer
.setInput(fRoot
);
120 // Create context menu for the tree viewer
123 getSite().setSelectionProvider(fTreeViewer
);
127 public void saveState(IMemento memento
) {
129 for (ITraceControlComponent cmp
: fRoot
.getChildren()) {
130 if (cmp
instanceof TargetNodeComponent
) {
131 IRemoteConnection rc
= ((TargetNodeComponent
) cmp
).getRemoteSystemProxy().getRemoteConnection();
132 memento
.putString(KEY_REMOTE_PROVIDER
+ i
, rc
.getConnectionType().getId());
133 memento
.putString(KEY_REMOTE_CONNECTION_NAME
+ i
, rc
.getName());
137 super.saveState(memento
);
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
);
149 if ((id
== null) || (name
== null)) {
152 IRemoteConnection conn
= TmfRemoteConnectionFactory
.getRemoteConnection(id
, name
);
154 fInitialConnections
.add(conn
);
161 public void setFocus() {
162 fTreeViewer
.getControl().setFocus();
166 public void componentAdded(ITraceControlComponent parent
, ITraceControlComponent component
) {
167 componentChanged(parent
);
171 public void componentRemoved(ITraceControlComponent parent
, ITraceControlComponent component
) {
172 componentChanged(parent
);
176 public void componentChanged(final ITraceControlComponent component
) {
177 if (fTreeViewer
.getTree().isDisposed()) {
181 UIJob myJob
= new UIJob("Refresh") { //$NON-NLS-1$
183 public IStatus
runInUIThread(IProgressMonitor monitor
) {
184 if (fTreeViewer
.getTree().isDisposed()) {
185 return Status
.OK_STATUS
;
188 fTreeViewer
.refresh(component
);
190 // Change selection needed
191 final ISelection sel
= fTreeViewer
.getSelection();
192 fTreeViewer
.setSelection(null);
193 fTreeViewer
.setSelection(sel
);
195 // Show component that was changed
196 fTreeViewer
.reveal(component
);
198 return Status
.OK_STATUS
;
201 myJob
.setUser(false);
202 myJob
.setSystem(true);
207 * Sets the selected component in the tree
208 * @param component - component to select
210 public void setSelection(ITraceControlComponent component
) {
211 ITraceControlComponent
[] components
= new ITraceControlComponent
[1];
212 components
[0] = component
;
213 setSelection(components
);
217 * Sets the selected components in the tree
218 * @param components - array of components to select
220 public void setSelection(ITraceControlComponent
[] components
) {
221 final StructuredSelection selection
= new StructuredSelection(components
);
222 UIJob myJob
= new UIJob("Select") { //$NON-NLS-1$
224 public IStatus
runInUIThread(IProgressMonitor monitor
) {
225 fTreeViewer
.setSelection(selection
);
226 return Status
.OK_STATUS
;
229 myJob
.setUser(false);
233 // ------------------------------------------------------------------------
235 // ------------------------------------------------------------------------
237 * Creates the context sensitive menu.
239 private void createContextMenu() {
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
);