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
.swt
.SWT
;
28 import org
.eclipse
.swt
.widgets
.Composite
;
29 import org
.eclipse
.swt
.widgets
.Menu
;
30 import org
.eclipse
.ui
.part
.ViewPart
;
31 import org
.eclipse
.ui
.progress
.UIJob
;
34 * <b><u>ControlView</u></b>
36 * View implementation for Trace Control.
39 public class ControlView
extends ViewPart
implements ITraceControlComponentChangedListener
{
41 // ------------------------------------------------------------------------
43 // ------------------------------------------------------------------------
47 public static final String ID
= "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
56 private TreeViewer fTreeViewer
= null;
59 * The trace control root node. This provides access to the whole model.
61 private ITraceControlComponent fRoot
= null;
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
69 // ------------------------------------------------------------------------
72 * @return returns the trace control tree node (model).
74 public ITraceControlComponent
getTraceControlRoot() {
78 // ------------------------------------------------------------------------
80 // ------------------------------------------------------------------------
85 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
88 public void createPartControl(Composite parent
) {
90 fTreeViewer
= new TreeViewer(parent
, SWT
.MULTI
| SWT
.H_SCROLL
| SWT
.V_SCROLL
);
91 ColumnViewerToolTipSupport
.enableFor(fTreeViewer
);
93 fTreeViewer
.setContentProvider(new TraceControlContentProvider());
94 fTreeViewer
.setLabelProvider(new TraceControlLabelProvider());
97 fRoot
= new TraceControlRoot();
98 fRoot
.addComponentListener(this);
99 fTreeViewer
.setInput(fRoot
);
101 // Create context menu for the tree viewer
104 getSite().setSelectionProvider(fTreeViewer
);
110 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
113 public void setFocus() {
114 fTreeViewer
.getControl().setFocus();
119 * @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)
122 public void componentAdded(ITraceControlComponent parent
, ITraceControlComponent component
) {
123 componentChanged(parent
);
128 * @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)
131 public void componentRemoved(ITraceControlComponent parent
, ITraceControlComponent component
) {
132 componentChanged(parent
);
137 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener#componentChanged(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent)
140 public void componentChanged(final ITraceControlComponent component
) {
141 if (fTreeViewer
.getTree().isDisposed()) {
145 UIJob myJob
= new UIJob("Refresh") { //$NON-NLS-1$
147 public IStatus
runInUIThread(IProgressMonitor monitor
) {
148 if (fTreeViewer
.getTree().isDisposed()) {
149 return Status
.OK_STATUS
;
152 fTreeViewer
.refresh(component
);
154 // Change selection needed
155 final ISelection sel
= fTreeViewer
.getSelection();
156 fTreeViewer
.setSelection(null);
157 fTreeViewer
.setSelection(sel
);
159 return Status
.OK_STATUS
;
162 myJob
.setUser(false);
167 * Sets the selected component in the tree
168 * @param component - component to select
170 public void setSelection(ITraceControlComponent component
) {
171 ITraceControlComponent
[] components
= new ITraceControlComponent
[1];
172 components
[0] = component
;
173 setSelection(components
);
177 * Sets the selected components in the tree
178 * @param component - array of components to select
180 public void setSelection(ITraceControlComponent
[] components
) {
181 final StructuredSelection selection
= new StructuredSelection(components
);
182 UIJob myJob
= new UIJob("Select") { //$NON-NLS-1$
184 public IStatus
runInUIThread(IProgressMonitor monitor
) {
185 fTreeViewer
.setSelection(selection
);
186 return Status
.OK_STATUS
;
189 myJob
.setUser(false);
193 // public ITraceControlComponent getSelection() {
194 // ISelection selection = fTreeViewer.getSelection();
198 // ------------------------------------------------------------------------
200 // ------------------------------------------------------------------------
201 private void createContextMenu() {
202 // First we create a menu Manager
203 final MenuManager menuManager
= new MenuManager();
204 final Menu menu
= menuManager
.createContextMenu(fTreeViewer
.getTree());
205 // Set the MenuManager
206 fTreeViewer
.getTree().setMenu(menu
);
207 getSite().registerContextMenu(menuManager
, fTreeViewer
);