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
.lttng
.ui
.views
.control
;
16 import org
.eclipse
.jface
.action
.MenuManager
;
17 import org
.eclipse
.jface
.viewers
.ColumnViewerToolTipSupport
;
18 import org
.eclipse
.jface
.viewers
.ISelection
;
19 import org
.eclipse
.jface
.viewers
.TreeViewer
;
20 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponentChangedListener
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceControlRoot
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.swt
.widgets
.Menu
;
26 import org
.eclipse
.ui
.part
.ViewPart
;
29 * <b><u>ControlView</u></b>
31 * View implementation for Trace Control.
34 public class ControlView
extends ViewPart
implements ITraceControlComponentChangedListener
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
42 public static final String ID
= "org.eclipse.linuxtools.lttng.ui.views.control"; //$NON-NLS-1$
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
51 private TreeViewer fTreeViewer
= null;
54 * The trace control root node. This provides access to the whole model.
56 private ITraceControlComponent fRoot
= null;
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
67 * @return returns the trace control tree node (model).
69 public ITraceControlComponent
getTraceControlRoot() {
73 // ------------------------------------------------------------------------
75 // ------------------------------------------------------------------------
80 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
83 public void createPartControl(Composite parent
) {
85 fTreeViewer
= new TreeViewer(parent
, SWT
.SINGLE
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
86 ColumnViewerToolTipSupport
.enableFor(fTreeViewer
);
88 fTreeViewer
.setContentProvider(new TraceControlContentProvider());
89 fTreeViewer
.setLabelProvider(new TraceControlLabelProvider());
92 fRoot
= new TraceControlRoot();
93 fRoot
.addComponentListener(this);
94 fTreeViewer
.setInput(fRoot
);
96 // Create context menu for the tree viewer
99 getSite().setSelectionProvider(fTreeViewer
);
105 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
108 public void setFocus() {
109 fTreeViewer
.getControl().setFocus();
114 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener#componentAdded(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent)
117 public void componentAdded(ITraceControlComponent parent
, ITraceControlComponent component
) {
118 componentChanged(component
);
123 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener#componentRemoved(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent, org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent)
126 public void componentRemoved(ITraceControlComponent parent
, ITraceControlComponent component
) {
127 componentChanged(component
);
132 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener#componentChanged(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent)
135 public void componentChanged(ITraceControlComponent component
) {
136 if (fTreeViewer
.getTree().isDisposed()) {
140 fTreeViewer
.getTree().getDisplay().asyncExec(new Runnable() {
143 if (fTreeViewer
.getTree().isDisposed()) {
146 fTreeViewer
.refresh();
147 // Change selection needed
148 final ISelection sel
= fTreeViewer
.getSelection();
149 fTreeViewer
.setSelection(null);
150 fTreeViewer
.setSelection(sel
);
155 // ------------------------------------------------------------------------
157 // ------------------------------------------------------------------------
158 private void createContextMenu() {
159 // First we create a menu Manager
160 final MenuManager menuManager
= new MenuManager();
161 final Menu menu
= menuManager
.createContextMenu(fTreeViewer
.getTree());
162 // Set the MenuManager
163 fTreeViewer
.getTree().setMenu(menu
);
164 getSite().registerContextMenu(menuManager
, fTreeViewer
);