Fix Findbug, compiler warnings + improved Control View refresh (LTTng)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / ControlView.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2012 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 * Bernd Hufmann - Filled with content
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.internal.lttng2.ui.views.control;
15
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;
33
34 /**
35 * <b><u>ControlView</u></b>
36 * <p>
37 * View implementation for Trace Control.
38 * </p>
39 */
40 public class ControlView extends ViewPart implements ITraceControlComponentChangedListener {
41
42 // ------------------------------------------------------------------------
43 // Constants
44 // ------------------------------------------------------------------------
45 /**
46 * View ID.
47 */
48 public static final String ID = "org.eclipse.linuxtools.internal.lttng2.ui.views.control"; //$NON-NLS-1$
49
50 // ------------------------------------------------------------------------
51 // Attributes
52 // ------------------------------------------------------------------------
53
54 /**
55 * The tree viewer.
56 */
57 private TreeViewer fTreeViewer = null;
58
59 /**
60 * The trace control root node. This provides access to the whole model.
61 */
62 private ITraceControlComponent fRoot = null;
63
64 // ------------------------------------------------------------------------
65 // Constructors
66 // ------------------------------------------------------------------------
67
68 // ------------------------------------------------------------------------
69 // Accessors
70 // ------------------------------------------------------------------------
71
72 /**
73 * @return returns the trace control tree node (model).
74 */
75 public ITraceControlComponent getTraceControlRoot() {
76 return fRoot;
77 }
78
79 // ------------------------------------------------------------------------
80 // Operations
81 // ------------------------------------------------------------------------
82
83 /*
84 * (non-Javadoc)
85 *
86 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
87 */
88 @Override
89 public void createPartControl(Composite parent) {
90 // Create tree viewer
91 fTreeViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
92 ColumnViewerToolTipSupport.enableFor(fTreeViewer);
93
94 fTreeViewer.setContentProvider(new TraceControlContentProvider());
95 fTreeViewer.setLabelProvider(new TraceControlLabelProvider());
96
97 // Create model root
98 fRoot = new TraceControlRoot();
99 fRoot.addComponentListener(this);
100 fTreeViewer.setInput(fRoot);
101
102 // Create context menu for the tree viewer
103 createContextMenu();
104
105 getSite().setSelectionProvider(fTreeViewer);
106
107 RSECorePlugin.getTheSystemRegistry(); // to load RSE
108 }
109
110 /*
111 * (non-Javadoc)
112 *
113 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
114 */
115 @Override
116 public void setFocus() {
117 fTreeViewer.getControl().setFocus();
118 }
119
120 /*
121 * (non-Javadoc)
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)
123 */
124 @Override
125 public void componentAdded(ITraceControlComponent parent, ITraceControlComponent component) {
126 componentChanged(parent);
127 }
128
129 /*
130 * (non-Javadoc)
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)
132 */
133 @Override
134 public void componentRemoved(ITraceControlComponent parent, ITraceControlComponent component) {
135 componentChanged(parent);
136 }
137
138 /*
139 * (non-Javadoc)
140 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponentChangedListener#componentChanged(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent)
141 */
142 @Override
143 public void componentChanged(final ITraceControlComponent component) {
144 if (fTreeViewer.getTree().isDisposed()) {
145 return;
146 }
147
148 UIJob myJob = new UIJob("Refresh") { //$NON-NLS-1$
149 @Override
150 public IStatus runInUIThread(IProgressMonitor monitor) {
151 if (fTreeViewer.getTree().isDisposed()) {
152 return Status.OK_STATUS;
153 }
154
155 fTreeViewer.refresh(component);
156
157 // Change selection needed
158 final ISelection sel = fTreeViewer.getSelection();
159 fTreeViewer.setSelection(null);
160 fTreeViewer.setSelection(sel);
161
162 // Show component that was changed
163 fTreeViewer.reveal(component);
164
165 return Status.OK_STATUS;
166 }
167 };
168 myJob.setUser(false);
169 myJob.schedule();
170 }
171
172 /**
173 * Sets the selected component in the tree
174 * @param component - component to select
175 */
176 public void setSelection(ITraceControlComponent component) {
177 ITraceControlComponent[] components = new ITraceControlComponent[1];
178 components[0] = component;
179 setSelection(components);
180 }
181
182 /**
183 * Sets the selected components in the tree
184 * @param component - array of components to select
185 */
186 public void setSelection(ITraceControlComponent[] components) {
187 final StructuredSelection selection = new StructuredSelection(components);
188 UIJob myJob = new UIJob("Select") { //$NON-NLS-1$
189 @Override
190 public IStatus runInUIThread(IProgressMonitor monitor) {
191 fTreeViewer.setSelection(selection);
192 return Status.OK_STATUS;
193 }
194 };
195 myJob.setUser(false);
196 myJob.schedule();
197 }
198
199 // public ITraceControlComponent getSelection() {
200 // ISelection selection = fTreeViewer.getSelection();
201 //
202 // }
203
204 // ------------------------------------------------------------------------
205 // Helper methods
206 // ------------------------------------------------------------------------
207 private void createContextMenu() {
208 // First we create a menu Manager
209 final MenuManager menuManager = new MenuManager();
210 final Menu menu = menuManager.createContextMenu(fTreeViewer.getTree());
211 // Set the MenuManager
212 fTreeViewer.getTree().setMenu(menu);
213 getSite().registerContextMenu(menuManager, fTreeViewer);
214 }
215 }
This page took 0.035646 seconds and 6 git commands to generate.