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
.StructuredSelection
;
20 import org
.eclipse
.jface
.viewers
.TreeViewer
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponent
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.ITraceControlComponentChangedListener
;
23 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.model
.impl
.TraceControlRoot
;
24 import org
.eclipse
.swt
.SWT
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Menu
;
27 import org
.eclipse
.ui
.part
.ViewPart
;
30 * <b><u>ControlView</u></b>
32 * View implementation for Trace Control.
35 public class ControlView
extends ViewPart
implements ITraceControlComponentChangedListener
{
37 // ------------------------------------------------------------------------
39 // ------------------------------------------------------------------------
43 public static final String ID
= "org.eclipse.linuxtools.lttng.ui.views.control"; //$NON-NLS-1$
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
52 private TreeViewer fTreeViewer
= null;
55 * The trace control root node. This provides access to the whole model.
57 private ITraceControlComponent fRoot
= null;
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
68 * @return returns the trace control tree node (model).
70 public ITraceControlComponent
getTraceControlRoot() {
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
81 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
84 public void createPartControl(Composite parent
) {
86 fTreeViewer
= new TreeViewer(parent
, SWT
.SINGLE
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
87 ColumnViewerToolTipSupport
.enableFor(fTreeViewer
);
89 fTreeViewer
.setContentProvider(new TraceControlContentProvider());
90 fTreeViewer
.setLabelProvider(new TraceControlLabelProvider());
93 fRoot
= new TraceControlRoot();
94 fRoot
.addComponentListener(this);
95 fTreeViewer
.setInput(fRoot
);
97 // Create context menu for the tree viewer
100 getSite().setSelectionProvider(fTreeViewer
);
106 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
109 public void setFocus() {
110 fTreeViewer
.getControl().setFocus();
111 final ISelection sel
= fTreeViewer
.getSelection();
113 fTreeViewer
.setSelection(new StructuredSelection(fRoot
));
114 fTreeViewer
.setSelection(null);
117 fTreeViewer
.setSelection(sel
);
122 * @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)
125 public void componentAdded(ITraceControlComponent parent
, ITraceControlComponent component
) {
126 componentChanged(component
);
131 * @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)
134 public void componentRemoved(ITraceControlComponent parent
, ITraceControlComponent component
) {
135 componentChanged(component
);
140 * @see org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponentChangedListener#componentChanged(org.eclipse.linuxtools.lttng.ui.views.control.model.ITraceControlComponent)
143 public void componentChanged(ITraceControlComponent component
) {
144 if (fTreeViewer
.getTree().isDisposed()) {
148 fTreeViewer
.getTree().getDisplay().asyncExec(new Runnable() {
151 if (fTreeViewer
.getTree().isDisposed()) {
154 fTreeViewer
.refresh();
155 // Change selection needed
156 final ISelection sel
= fTreeViewer
.getSelection();
157 fTreeViewer
.setSelection(null);
158 fTreeViewer
.setSelection(sel
);
163 // ------------------------------------------------------------------------
165 // ------------------------------------------------------------------------
166 private void createContextMenu() {
168 // First we create a menu Manager
169 final MenuManager menuManager
= new MenuManager();
170 final Menu menu
= menuManager
.createContextMenu(fTreeViewer
.getTree());
171 // Set the MenuManager
172 fTreeViewer
.getTree().setMenu(menu
);
173 getSite().registerContextMenu(menuManager
, fTreeViewer
);