1 /*******************************************************************************
2 * Copyright (c) 2009, 2013 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 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
;
16 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
17 import org
.eclipse
.core
.runtime
.IStatus
;
18 import org
.eclipse
.core
.runtime
.Status
;
19 import org
.eclipse
.jface
.action
.MenuManager
;
20 import org
.eclipse
.jface
.viewers
.ColumnViewerToolTipSupport
;
21 import org
.eclipse
.jface
.viewers
.ISelection
;
22 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
23 import org
.eclipse
.jface
.viewers
.TreeViewer
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponentChangedListener
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceControlContentProvider
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceControlLabelProvider
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceControlRoot
;
29 import org
.eclipse
.rse
.core
.RSECorePlugin
;
30 import org
.eclipse
.swt
.SWT
;
31 import org
.eclipse
.swt
.widgets
.Composite
;
32 import org
.eclipse
.swt
.widgets
.Menu
;
33 import org
.eclipse
.ui
.part
.ViewPart
;
34 import org
.eclipse
.ui
.progress
.UIJob
;
38 * View implementation for Trace Control.
41 * @author Bernd Hufmann
43 public class ControlView
extends ViewPart
implements ITraceControlComponentChangedListener
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
52 public static final String ID
= "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
61 private TreeViewer fTreeViewer
= null;
64 * The trace control root node. This provides access to the whole model.
66 private ITraceControlComponent fRoot
= null;
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * Returns the trace control tree node (model)
75 * @return the trace control tree node (model).
77 public ITraceControlComponent
getTraceControlRoot() {
81 // ------------------------------------------------------------------------
83 // ------------------------------------------------------------------------
86 public void createPartControl(Composite parent
) {
88 fTreeViewer
= new TreeViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
89 ColumnViewerToolTipSupport
.enableFor(fTreeViewer
);
91 fTreeViewer
.setContentProvider(new TraceControlContentProvider());
92 fTreeViewer
.setLabelProvider(new TraceControlLabelProvider());
95 fRoot
= new TraceControlRoot();
96 fRoot
.addComponentListener(this);
97 fTreeViewer
.setInput(fRoot
);
99 // Create context menu for the tree viewer
102 getSite().setSelectionProvider(fTreeViewer
);
104 RSECorePlugin
.getTheSystemRegistry(); // to load RSE
108 public void setFocus() {
109 fTreeViewer
.getControl().setFocus();
113 public void componentAdded(ITraceControlComponent parent
, ITraceControlComponent component
) {
114 componentChanged(parent
);
118 public void componentRemoved(ITraceControlComponent parent
, ITraceControlComponent component
) {
119 componentChanged(parent
);
123 public void componentChanged(final ITraceControlComponent component
) {
124 if (fTreeViewer
.getTree().isDisposed()) {
128 UIJob myJob
= new UIJob("Refresh") { //$NON-NLS-1$
130 public IStatus
runInUIThread(IProgressMonitor monitor
) {
131 if (fTreeViewer
.getTree().isDisposed()) {
132 return Status
.OK_STATUS
;
135 fTreeViewer
.refresh(component
);
137 // Change selection needed
138 final ISelection sel
= fTreeViewer
.getSelection();
139 fTreeViewer
.setSelection(null);
140 fTreeViewer
.setSelection(sel
);
142 // Show component that was changed
143 fTreeViewer
.reveal(component
);
145 return Status
.OK_STATUS
;
148 myJob
.setUser(false);
153 * Sets the selected component in the tree
154 * @param component - component to select
156 public void setSelection(ITraceControlComponent component
) {
157 ITraceControlComponent
[] components
= new ITraceControlComponent
[1];
158 components
[0] = component
;
159 setSelection(components
);
163 * Sets the selected components in the tree
164 * @param components - array of components to select
166 public void setSelection(ITraceControlComponent
[] components
) {
167 final StructuredSelection selection
= new StructuredSelection(components
);
168 UIJob myJob
= new UIJob("Select") { //$NON-NLS-1$
170 public IStatus
runInUIThread(IProgressMonitor monitor
) {
171 fTreeViewer
.setSelection(selection
);
172 return Status
.OK_STATUS
;
175 myJob
.setUser(false);
179 // ------------------------------------------------------------------------
181 // ------------------------------------------------------------------------
183 * Creates the context sensitive menu.
185 private void createContextMenu() {
186 // First we create a menu Manager
187 final MenuManager menuManager
= new MenuManager();
188 final Menu menu
= menuManager
.createContextMenu(fTreeViewer
.getTree());
189 // Set the MenuManager
190 fTreeViewer
.getTree().setMenu(menu
);
191 getSite().registerContextMenu(menuManager
, fTreeViewer
);