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
.TraceControlRoot
;
27 import org
.eclipse
.rse
.core
.RSECorePlugin
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Menu
;
31 import org
.eclipse
.ui
.part
.ViewPart
;
32 import org
.eclipse
.ui
.progress
.UIJob
;
35 * <b><u>ControlView</u></b>
37 * View implementation for Trace Control.
40 public class ControlView
extends ViewPart
implements ITraceControlComponentChangedListener
{
42 // ------------------------------------------------------------------------
44 // ------------------------------------------------------------------------
48 public static final String ID
= "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
57 private TreeViewer fTreeViewer
= null;
60 * The trace control root node. This provides access to the whole model.
62 private ITraceControlComponent fRoot
= null;
64 // ------------------------------------------------------------------------
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * @return returns the trace control tree node (model).
75 public ITraceControlComponent
getTraceControlRoot() {
79 // ------------------------------------------------------------------------
81 // ------------------------------------------------------------------------
86 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
89 public void createPartControl(Composite parent
) {
91 fTreeViewer
= new TreeViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
92 ColumnViewerToolTipSupport
.enableFor(fTreeViewer
);
94 fTreeViewer
.setContentProvider(new TraceControlContentProvider());
95 fTreeViewer
.setLabelProvider(new TraceControlLabelProvider());
98 fRoot
= new TraceControlRoot();
99 fRoot
.addComponentListener(this);
100 fTreeViewer
.setInput(fRoot
);
102 // Create context menu for the tree viewer
105 getSite().setSelectionProvider(fTreeViewer
);
107 RSECorePlugin
.getTheSystemRegistry(); // to load RSE
113 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
116 public void setFocus() {
117 fTreeViewer
.getControl().setFocus();
122 * @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)
125 public void componentAdded(ITraceControlComponent parent
, ITraceControlComponent component
) {
126 componentChanged(parent
);
131 * @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)
134 public void componentRemoved(ITraceControlComponent parent
, ITraceControlComponent component
) {
135 componentChanged(parent
);
140 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener#componentChanged(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent)
143 public void componentChanged(final ITraceControlComponent component
) {
144 if (fTreeViewer
.getTree().isDisposed()) {
148 UIJob myJob
= new UIJob("Refresh") { //$NON-NLS-1$
150 public IStatus
runInUIThread(IProgressMonitor monitor
) {
151 if (fTreeViewer
.getTree().isDisposed()) {
152 return Status
.OK_STATUS
;
155 fTreeViewer
.refresh(component
);
157 // Change selection needed
158 final ISelection sel
= fTreeViewer
.getSelection();
159 fTreeViewer
.setSelection(null);
160 fTreeViewer
.setSelection(sel
);
162 return Status
.OK_STATUS
;
165 myJob
.setUser(false);
170 * Sets the selected component in the tree
171 * @param component - component to select
173 public void setSelection(ITraceControlComponent component
) {
174 ITraceControlComponent
[] components
= new ITraceControlComponent
[1];
175 components
[0] = component
;
176 setSelection(components
);
180 * Sets the selected components in the tree
181 * @param component - array of components to select
183 public void setSelection(ITraceControlComponent
[] components
) {
184 final StructuredSelection selection
= new StructuredSelection(components
);
185 UIJob myJob
= new UIJob("Select") { //$NON-NLS-1$
187 public IStatus
runInUIThread(IProgressMonitor monitor
) {
188 fTreeViewer
.setSelection(selection
);
189 return Status
.OK_STATUS
;
192 myJob
.setUser(false);
196 // public ITraceControlComponent getSelection() {
197 // ISelection selection = fTreeViewer.getSelection();
201 // ------------------------------------------------------------------------
203 // ------------------------------------------------------------------------
204 private void createContextMenu() {
205 // First we create a menu Manager
206 final MenuManager menuManager
= new MenuManager();
207 final Menu menu
= menuManager
.createContextMenu(fTreeViewer
.getTree());
208 // Set the MenuManager
209 fTreeViewer
.getTree().setMenu(menu
);
210 getSite().registerContextMenu(menuManager
, fTreeViewer
);