|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Trace Builder view implementation |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.view; |
|
20 |
|
21 import org.eclipse.jface.action.IMenuListener; |
|
22 import org.eclipse.jface.action.IMenuManager; |
|
23 import org.eclipse.jface.action.IToolBarManager; |
|
24 import org.eclipse.jface.action.MenuManager; |
|
25 import org.eclipse.jface.action.Separator; |
|
26 import org.eclipse.jface.viewers.TreeViewer; |
|
27 import org.eclipse.swt.SWT; |
|
28 import org.eclipse.swt.widgets.Composite; |
|
29 import org.eclipse.swt.widgets.Menu; |
|
30 import org.eclipse.swt.widgets.Shell; |
|
31 import org.eclipse.swt.widgets.TreeItem; |
|
32 import org.eclipse.ui.IActionBars; |
|
33 import org.eclipse.ui.IWorkbenchActionConstants; |
|
34 import org.eclipse.ui.part.ViewPart; |
|
35 |
|
36 import com.nokia.carbide.cpp.internal.featureTracker.FeatureUseTrackerConsts; |
|
37 import com.nokia.carbide.cpp.internal.featureTracker.FeatureUseTrackerPlugin; |
|
38 import com.nokia.tracebuilder.action.ActionFactory; |
|
39 import com.nokia.tracebuilder.action.TraceViewActions; |
|
40 import com.nokia.tracebuilder.engine.TraceBuilderActions; |
|
41 import com.nokia.tracebuilder.engine.TraceBuilderConfiguration; |
|
42 import com.nokia.tracebuilder.engine.TraceBuilderDialogs; |
|
43 import com.nokia.tracebuilder.engine.TraceBuilderGlobals; |
|
44 import com.nokia.tracebuilder.engine.TraceBuilderView; |
|
45 import com.nokia.tracebuilder.engine.TraceLocation; |
|
46 import com.nokia.tracebuilder.engine.TraceObjectPropertyDialog; |
|
47 import com.nokia.tracebuilder.model.TraceObject; |
|
48 import com.nokia.tracebuilder.preferences.ConfigurationImpl; |
|
49 |
|
50 /** |
|
51 * Trace Builder view implementation |
|
52 * |
|
53 */ |
|
54 public final class TraceView extends ViewPart implements TraceBuilderView { |
|
55 |
|
56 /** |
|
57 * Trace Groups branch text |
|
58 */ |
|
59 private static final String TRACE_GROUPS_BRANCH_TEXT = "Trace Groups"; //$NON-NLS-1$ |
|
60 |
|
61 /** |
|
62 * Tree viewer widget |
|
63 */ |
|
64 private TreeViewer viewer; |
|
65 |
|
66 /** |
|
67 * Tree view selection listener |
|
68 */ |
|
69 private TraceViewSelectionListener selectionListener; |
|
70 |
|
71 /** |
|
72 * Tree view expansion listener |
|
73 */ |
|
74 private TraceViewTreeListener treeListener; |
|
75 |
|
76 /** |
|
77 * Dialog interface implementation |
|
78 */ |
|
79 private TraceViewDialogs dialogs; |
|
80 |
|
81 /** |
|
82 * Action factory |
|
83 */ |
|
84 private TraceViewActions actions; |
|
85 |
|
86 /** |
|
87 * Configuration |
|
88 */ |
|
89 private TraceBuilderConfiguration configuration; |
|
90 |
|
91 /** |
|
92 * Help listener |
|
93 */ |
|
94 private TraceViewHelpListener helpListener; |
|
95 |
|
96 /** |
|
97 * Property dialog properties |
|
98 */ |
|
99 private PropertyDialogProperties propertyDialog; |
|
100 |
|
101 /* |
|
102 * (non-Javadoc) |
|
103 * |
|
104 * @see |
|
105 * org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets |
|
106 * .Composite) |
|
107 */ |
|
108 @Override |
|
109 public void createPartControl(Composite parent) { |
|
110 actions = new ActionFactory(); |
|
111 configuration = new ConfigurationImpl(); |
|
112 selectionListener = new TraceViewSelectionListener(actions); |
|
113 // Creates the tree viewer |
|
114 viewer = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL |
|
115 | SWT.V_SCROLL); |
|
116 TraceContentProvider contentProvider = new TraceContentProvider(); |
|
117 TraceLabelProvider labelProvider = new TraceLabelProvider(); |
|
118 TraceNameSorter nameSorter = new TraceNameSorter(); |
|
119 viewer.setContentProvider(contentProvider); |
|
120 viewer.setLabelProvider(labelProvider); |
|
121 viewer.setSorter(nameSorter); |
|
122 // Content provider creates the viewer updater. The updater needs the |
|
123 // display reference in order to create asynchronous callbacks to the UI |
|
124 // thread. |
|
125 viewer.setInput(getViewSite().getShell().getDisplay()); |
|
126 treeListener = new TraceViewTreeListener(viewer); |
|
127 helpListener = new TraceViewHelpListener(); |
|
128 viewer.addSelectionChangedListener(selectionListener); |
|
129 viewer.addDoubleClickListener(selectionListener); |
|
130 viewer.addHelpListener(helpListener); |
|
131 viewer.addTreeListener(treeListener); |
|
132 |
|
133 // Hooks actions to menus |
|
134 hookContextMenu(); |
|
135 fillMenuAndToolBar(); |
|
136 |
|
137 // Start using feature |
|
138 FeatureUseTrackerPlugin.getFeatureUseProxy().startUsingFeature( |
|
139 FeatureUseTrackerConsts.CARBIDE_OST_TRACE); |
|
140 |
|
141 // Sets the view reference to trace builder engine |
|
142 TraceBuilderGlobals.setView(this); |
|
143 } |
|
144 |
|
145 /* |
|
146 * (non-Javadoc) |
|
147 * |
|
148 * @see org.eclipse.ui.part.WorkbenchPart#dispose() |
|
149 */ |
|
150 @Override |
|
151 public void dispose() { |
|
152 TraceBuilderGlobals.setView(null); |
|
153 viewer.removeTreeListener(treeListener); |
|
154 viewer.removeSelectionChangedListener(selectionListener); |
|
155 viewer.removeHelpListener(helpListener); |
|
156 |
|
157 // Stop using feature |
|
158 FeatureUseTrackerPlugin.getFeatureUseProxy().stopUsingFeature( |
|
159 FeatureUseTrackerConsts.CARBIDE_OST_TRACE); |
|
160 |
|
161 super.dispose(); |
|
162 } |
|
163 |
|
164 /* |
|
165 * (non-Javadoc) |
|
166 * |
|
167 * @see org.eclipse.ui.IWorkbenchPart#setFocus() |
|
168 */ |
|
169 @Override |
|
170 public void setFocus() { |
|
171 viewer.getControl().setFocus(); |
|
172 } |
|
173 |
|
174 /* |
|
175 * (non-Javadoc) |
|
176 * |
|
177 * @see com.nokia.tracebuilder.engine.TraceBuilderView#hasFocus() |
|
178 */ |
|
179 public boolean hasFocus() { |
|
180 return viewer.getControl().isFocusControl(); |
|
181 } |
|
182 |
|
183 /* |
|
184 * (non-Javadoc) |
|
185 * |
|
186 * @see com.nokia.tracebuilder.engine.TraceBuilderView# |
|
187 * selectObject(com.nokia.tracebuilder.model.TraceObject) |
|
188 */ |
|
189 public void selectObject(TraceObject object) { |
|
190 TraceObjectWrapper wrapper = object |
|
191 .getExtension(TraceObjectWrapper.class); |
|
192 // Wrapper is null if user makes a selection before view is updated |
|
193 if (wrapper != null) { |
|
194 revealSelectedObject(wrapper); |
|
195 actions.enableActions(object); |
|
196 } |
|
197 } |
|
198 |
|
199 /* |
|
200 * (non-Javadoc) |
|
201 * |
|
202 * @see com.nokia.tracebuilder.engine.TraceBuilderView# |
|
203 * selectLocation(com.nokia.tracebuilder.engine.TraceLocation) |
|
204 */ |
|
205 public void selectLocation(TraceLocation location) { |
|
206 TraceLocationWrapper wrapper = (TraceLocationWrapper) location |
|
207 .getProperties().getViewReference(); |
|
208 // Wrapper is null if user makes a selection before view is updated |
|
209 if (wrapper != null) { |
|
210 revealSelectedObject(wrapper); |
|
211 actions.enableActions(location); |
|
212 } |
|
213 } |
|
214 |
|
215 /** |
|
216 * Reveals the given wrapper |
|
217 * |
|
218 * @param wrapper |
|
219 * the wrapper to be revealed |
|
220 */ |
|
221 private void revealSelectedObject(WrapperBase wrapper) { |
|
222 ListWrapper parent = (ListWrapper) wrapper.getParent(); |
|
223 WrapperBase updated = parent.moveChildToView(wrapper); |
|
224 if (updated != null) { |
|
225 viewer.removeSelectionChangedListener(selectionListener); |
|
226 updated.getUpdater().update(updated); |
|
227 viewer.addSelectionChangedListener(selectionListener); |
|
228 } |
|
229 wrapper.getUpdater().queueSelection(wrapper); |
|
230 } |
|
231 |
|
232 /** |
|
233 * Gets the view shell |
|
234 * |
|
235 * @return the shell of the tree viewer |
|
236 */ |
|
237 Shell getShell() { |
|
238 Shell retval = null; |
|
239 if (viewer != null) { |
|
240 retval = viewer.getControl().getShell(); |
|
241 if (retval != null && retval.isDisposed()) { |
|
242 retval = null; |
|
243 } |
|
244 } |
|
245 return retval; |
|
246 } |
|
247 |
|
248 /** |
|
249 * Adds menu listener to popup menu |
|
250 */ |
|
251 private void hookContextMenu() { |
|
252 MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ |
|
253 menuMgr.setRemoveAllWhenShown(true); |
|
254 menuMgr.addMenuListener(new IMenuListener() { |
|
255 public void menuAboutToShow(IMenuManager manager) { |
|
256 fillContextMenu(manager); |
|
257 } |
|
258 }); |
|
259 Menu menu = menuMgr.createContextMenu(viewer.getControl()); |
|
260 viewer.getControl().setMenu(menu); |
|
261 getSite().registerContextMenu(menuMgr, viewer); |
|
262 } |
|
263 |
|
264 /** |
|
265 * Adds action items to menu and toolbar |
|
266 */ |
|
267 private void fillMenuAndToolBar() { |
|
268 IActionBars bars = getViewSite().getActionBars(); |
|
269 fillMenu(bars.getMenuManager()); |
|
270 fillToolBar(bars.getToolBarManager()); |
|
271 } |
|
272 |
|
273 /** |
|
274 * Adds menu items to view pull-down menu |
|
275 * |
|
276 * @param manager |
|
277 * the menu to be filled |
|
278 */ |
|
279 private void fillMenu(IMenuManager manager) { |
|
280 actions.fillMenu(manager); |
|
281 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
282 } |
|
283 |
|
284 /** |
|
285 * Adds actions to tool bar |
|
286 * |
|
287 * @param manager |
|
288 * the tool bar |
|
289 */ |
|
290 private void fillToolBar(IToolBarManager manager) { |
|
291 actions.fillToolBar(manager); |
|
292 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
293 } |
|
294 |
|
295 /** |
|
296 * Called prior to showing the context menu |
|
297 * |
|
298 * @param manager |
|
299 * the menu to be filled |
|
300 */ |
|
301 private void fillContextMenu(IMenuManager manager) { |
|
302 actions.fillContextMenu(manager); |
|
303 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
304 } |
|
305 |
|
306 /* |
|
307 * (non-Javadoc) |
|
308 * |
|
309 * @see com.nokia.tracebuilder.engine.TraceBuilderView#getDialogs() |
|
310 */ |
|
311 public TraceBuilderDialogs getDialogs() { |
|
312 if (dialogs == null) { |
|
313 dialogs = new TraceViewDialogs(this); |
|
314 } |
|
315 return dialogs; |
|
316 } |
|
317 |
|
318 /* |
|
319 * (non-Javadoc) |
|
320 * |
|
321 * @see com.nokia.tracebuilder.engine.TraceBuilderView#getPropertyDialog() |
|
322 */ |
|
323 public TraceObjectPropertyDialog getPropertyDialog() { |
|
324 if (propertyDialog == null) { |
|
325 propertyDialog = new PropertyDialogProperties(this); |
|
326 } |
|
327 return propertyDialog; |
|
328 } |
|
329 |
|
330 /* |
|
331 * (non-Javadoc) |
|
332 * |
|
333 * @see com.nokia.tracebuilder.engine.TraceBuilderView#getActions() |
|
334 */ |
|
335 public TraceBuilderActions getActions() { |
|
336 return actions; |
|
337 } |
|
338 |
|
339 /* |
|
340 * (non-Javadoc) |
|
341 * |
|
342 * @see com.nokia.tracebuilder.engine.TraceBuilderView#getConfiguration() |
|
343 */ |
|
344 public TraceBuilderConfiguration getConfiguration() { |
|
345 return configuration; |
|
346 } |
|
347 |
|
348 /* |
|
349 * (non-Javadoc) |
|
350 * |
|
351 * @see com.nokia.tracebuilder.engine.TraceBuilderView# |
|
352 * runAsyncOperation(java.lang.Runnable) |
|
353 */ |
|
354 public void runAsyncOperation(Runnable runnable) { |
|
355 Shell shell = getShell(); |
|
356 if (shell != null) { |
|
357 shell.getDisplay().asyncExec(runnable); |
|
358 } |
|
359 } |
|
360 |
|
361 /* |
|
362 * (non-Javadoc) |
|
363 * |
|
364 * @see com.nokia.tracebuilder.engine.TraceBuilderView# refresh() |
|
365 */ |
|
366 public void refresh() { |
|
367 viewer.refresh(); |
|
368 } |
|
369 |
|
370 /* |
|
371 * (non-Javadoc) |
|
372 * |
|
373 * @see |
|
374 * com.nokia.tracebuilder.engine.TraceBuilderView#expandTraceGroupsBranch() |
|
375 */ |
|
376 public void expandTraceGroupsBranch() { |
|
377 TreeItem[] items = viewer.getTree().getItems(); |
|
378 if (items != null) { |
|
379 for (TreeItem item : items) { |
|
380 if (item.getText().equals(TRACE_GROUPS_BRANCH_TEXT)) { |
|
381 item.setExpanded(true); |
|
382 break; |
|
383 } |
|
384 } |
|
385 } |
|
386 } |
|
387 } |