1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 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 // ------------------------------------------------------------------------
51 public static final String ID
= "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
60 private TreeViewer fTreeViewer
= null;
63 * The trace control root node. This provides access to the whole model.
65 private ITraceControlComponent fRoot
= null;
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
76 * Returns the trace control tree node (model)
78 * @return the trace control tree node (model).
80 public ITraceControlComponent
getTraceControlRoot() {
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
91 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
94 public void createPartControl(Composite parent
) {
96 fTreeViewer
= new TreeViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
97 ColumnViewerToolTipSupport
.enableFor(fTreeViewer
);
99 fTreeViewer
.setContentProvider(new TraceControlContentProvider());
100 fTreeViewer
.setLabelProvider(new TraceControlLabelProvider());
103 fRoot
= new TraceControlRoot();
104 fRoot
.addComponentListener(this);
105 fTreeViewer
.setInput(fRoot
);
107 // Create context menu for the tree viewer
110 getSite().setSelectionProvider(fTreeViewer
);
112 RSECorePlugin
.getTheSystemRegistry(); // to load RSE
118 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
121 public void setFocus() {
122 fTreeViewer
.getControl().setFocus();
127 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener#componentAdded(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent)
130 public void componentAdded(ITraceControlComponent parent
, ITraceControlComponent component
) {
131 componentChanged(parent
);
136 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener#componentRemoved(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent)
139 public void componentRemoved(ITraceControlComponent parent
, ITraceControlComponent component
) {
140 componentChanged(parent
);
145 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener#componentChanged(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent)
148 public void componentChanged(final ITraceControlComponent component
) {
149 if (fTreeViewer
.getTree().isDisposed()) {
153 UIJob myJob
= new UIJob("Refresh") { //$NON-NLS-1$
155 public IStatus
runInUIThread(IProgressMonitor monitor
) {
156 if (fTreeViewer
.getTree().isDisposed()) {
157 return Status
.OK_STATUS
;
160 fTreeViewer
.refresh(component
);
162 // Change selection needed
163 final ISelection sel
= fTreeViewer
.getSelection();
164 fTreeViewer
.setSelection(null);
165 fTreeViewer
.setSelection(sel
);
167 // Show component that was changed
168 fTreeViewer
.reveal(component
);
170 return Status
.OK_STATUS
;
173 myJob
.setUser(false);
178 * Sets the selected component in the tree
179 * @param component - component to select
181 public void setSelection(ITraceControlComponent component
) {
182 ITraceControlComponent
[] components
= new ITraceControlComponent
[1];
183 components
[0] = component
;
184 setSelection(components
);
188 * Sets the selected components in the tree
189 * @param components - array of components to select
191 public void setSelection(ITraceControlComponent
[] components
) {
192 final StructuredSelection selection
= new StructuredSelection(components
);
193 UIJob myJob
= new UIJob("Select") { //$NON-NLS-1$
195 public IStatus
runInUIThread(IProgressMonitor monitor
) {
196 fTreeViewer
.setSelection(selection
);
197 return Status
.OK_STATUS
;
200 myJob
.setUser(false);
204 // ------------------------------------------------------------------------
206 // ------------------------------------------------------------------------
208 * Creates the context sensitive menu.
210 private void createContextMenu() {
211 // First we create a menu Manager
212 final MenuManager menuManager
= new MenuManager();
213 final Menu menu
= menuManager
.createContextMenu(fTreeViewer
.getTree());
214 // Set the MenuManager
215 fTreeViewer
.getTree().setMenu(menu
);
216 getSite().registerContextMenu(menuManager
, fTreeViewer
);