|
1 /* |
|
2 * Copyright (c) 2007-2010 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 * Event view |
|
17 * |
|
18 */ |
|
19 package com.nokia.trace.eventview; |
|
20 |
|
21 import org.eclipse.jface.action.IMenuListener; |
|
22 import org.eclipse.jface.action.IMenuManager; |
|
23 import org.eclipse.jface.action.MenuManager; |
|
24 import org.eclipse.jface.action.Separator; |
|
25 import org.eclipse.jface.preference.IPreferenceStore; |
|
26 import org.eclipse.jface.viewers.IStructuredSelection; |
|
27 import org.eclipse.jface.viewers.ITableLabelProvider; |
|
28 import org.eclipse.jface.viewers.TableViewer; |
|
29 import org.eclipse.jface.viewers.Viewer; |
|
30 import org.eclipse.swt.SWT; |
|
31 import org.eclipse.swt.events.ControlEvent; |
|
32 import org.eclipse.swt.events.ControlListener; |
|
33 import org.eclipse.swt.widgets.Composite; |
|
34 import org.eclipse.swt.widgets.Menu; |
|
35 import org.eclipse.swt.widgets.Table; |
|
36 import org.eclipse.swt.widgets.TableColumn; |
|
37 import org.eclipse.ui.IWorkbenchActionConstants; |
|
38 import org.eclipse.ui.part.ViewPart; |
|
39 import org.eclipse.ui.progress.IWorkbenchSiteProgressService; |
|
40 |
|
41 /** |
|
42 * Event view. {@link #getEventList() getEventList} method is the access point |
|
43 * for view extensions. |
|
44 */ |
|
45 public class TraceEventView extends ViewPart implements ContentChangeListener { |
|
46 |
|
47 /** |
|
48 * Type column title |
|
49 */ |
|
50 private static final String TYPE_TITLE = Messages |
|
51 .getString("TraceEventView.TypeColumnTitle"); //$NON-NLS-1$ |
|
52 |
|
53 /** |
|
54 * Category column title |
|
55 */ |
|
56 private static final String CATEGORY_TITLE = Messages |
|
57 .getString("TraceEventView.CategoryColumnTitle"); //$NON-NLS-1$ |
|
58 |
|
59 /** |
|
60 * Source column title |
|
61 */ |
|
62 private static final String SOURCE_TITLE = Messages |
|
63 .getString("TraceEventView.SourceColumnTitle"); //$NON-NLS-1$ |
|
64 |
|
65 /** |
|
66 * Description column title |
|
67 */ |
|
68 private static final String DESCRIPTION_TITLE = Messages |
|
69 .getString("TraceEventView.DescriptionColumnTitle"); //$NON-NLS-1$ |
|
70 |
|
71 /** |
|
72 * Type width configuration entry |
|
73 */ |
|
74 private static final String TYPE_WIDTH_CONFIGURATION = "TraceEventView.TypeWidth"; //$NON-NLS-1$ |
|
75 |
|
76 /** |
|
77 * Category width configuration entry |
|
78 */ |
|
79 private static final String CATEGORY_WIDTH_CONFIGURATION = "TraceEventView.CategoryWidth"; //$NON-NLS-1$ |
|
80 |
|
81 /** |
|
82 * Source width configuration entry |
|
83 */ |
|
84 private static final String SOURCE_WIDTH_CONFIGURATION = "TraceEventView.SourceWidth"; //$NON-NLS-1$ |
|
85 |
|
86 /** |
|
87 * Description width configuration entry |
|
88 */ |
|
89 private static final String DESCRIPTION_WIDTH_CONFIGURATION = "TraceEventView.DescriptionsWidth"; //$NON-NLS-1$ |
|
90 |
|
91 /** |
|
92 * Default width for type column |
|
93 */ |
|
94 private static final int DEFAULT_TYPE_WIDTH = 75; |
|
95 |
|
96 /** |
|
97 * Default width for category column |
|
98 */ |
|
99 private static final int DEFAULT_CATEGORY_WIDTH = 150; |
|
100 |
|
101 /** |
|
102 * Default width for source column |
|
103 */ |
|
104 private static final int DEFAULT_SOURCE_WIDTH = 150; |
|
105 |
|
106 /** |
|
107 * Default width for description column |
|
108 */ |
|
109 private static final int DEFAULT_DESCRIPTION_WIDTH = 800; |
|
110 |
|
111 /** |
|
112 * Type column index |
|
113 */ |
|
114 static final int TYPE_COLUM_INDEX = 0; |
|
115 |
|
116 /** |
|
117 * Category column index |
|
118 */ |
|
119 static final int CATEGORY_COLUM_INDEX = 1; |
|
120 |
|
121 /** |
|
122 * Source column index |
|
123 */ |
|
124 static final int SOURCE_COLUM_INDEX = 2; |
|
125 |
|
126 /** |
|
127 * Description column index |
|
128 */ |
|
129 static final int DESCRIPTION_COLUM_INDEX = 3; |
|
130 |
|
131 /** |
|
132 * Message list |
|
133 */ |
|
134 private TableViewer table; |
|
135 |
|
136 /** |
|
137 * Remove event action |
|
138 */ |
|
139 private RemoveEventAction removeEventAction; |
|
140 |
|
141 /** |
|
142 * Remove event action |
|
143 */ |
|
144 private RemoveAllEventsAction removeAllEventsAction; |
|
145 |
|
146 /** |
|
147 * Descriptions column |
|
148 */ |
|
149 private TableColumn descriptionColumn; |
|
150 |
|
151 /** |
|
152 * Descriptions column |
|
153 */ |
|
154 private TableColumn categoryColumn; |
|
155 |
|
156 /** |
|
157 * Source column |
|
158 */ |
|
159 private TableColumn sourceColumn; |
|
160 |
|
161 /** |
|
162 * Type column |
|
163 */ |
|
164 private TableColumn typeColumn; |
|
165 |
|
166 /** |
|
167 * Content change listener |
|
168 */ |
|
169 public static ContentChangeListener contentChangeListener; |
|
170 |
|
171 /* |
|
172 * (non-Javadoc) |
|
173 * |
|
174 * @see |
|
175 * org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets |
|
176 * .Composite) |
|
177 */ |
|
178 @Override |
|
179 public void createPartControl(Composite parent) { |
|
180 table = new TableViewer(parent, SWT.SINGLE | SWT.H_SCROLL |
|
181 | SWT.V_SCROLL | SWT.FULL_SELECTION); |
|
182 EventListContentProvider contentProvider = (EventListContentProvider) getEventList(); |
|
183 EventListLabelProvider labelProvider = new EventListLabelProvider(); |
|
184 removeEventAction = new RemoveEventAction(contentProvider); |
|
185 removeAllEventsAction = new RemoveAllEventsAction(contentProvider); |
|
186 table.setContentProvider(contentProvider); |
|
187 table.setLabelProvider(labelProvider); |
|
188 |
|
189 // Content provider creates the viewer updater. The updater needs the |
|
190 // display reference in order to create asynchronous callbacks to the UI |
|
191 // thread. |
|
192 Table tableWidget = table.getTable(); |
|
193 createTypeColumn(tableWidget); |
|
194 createCategoryColumn(tableWidget); |
|
195 createSourceColumn(tableWidget); |
|
196 createDescriptionColumn(tableWidget); |
|
197 configureWidgets(); |
|
198 tableWidget.setHeaderVisible(true); |
|
199 tableWidget.setLinesVisible(true); |
|
200 hookContextMenu(); |
|
201 table.setInput(getViewSite().getShell().getDisplay()); |
|
202 setContentListener(this); |
|
203 } |
|
204 |
|
205 /** |
|
206 * Sets content listener |
|
207 * |
|
208 * @param listener |
|
209 * new content listener |
|
210 */ |
|
211 private void setContentListener(ContentChangeListener listener) { |
|
212 contentChangeListener = listener; |
|
213 } |
|
214 |
|
215 /** |
|
216 * Configures the widgets |
|
217 */ |
|
218 void configureWidgets() { |
|
219 |
|
220 // Get preference store from the plugin |
|
221 IPreferenceStore preferences = Activator.getDefault() |
|
222 .getPreferenceStore(); |
|
223 |
|
224 // Set description column width |
|
225 int value = preferences.getInt(DESCRIPTION_WIDTH_CONFIGURATION); |
|
226 if (value > 0) { |
|
227 descriptionColumn.setWidth(value); |
|
228 } else { |
|
229 descriptionColumn.setWidth(DEFAULT_DESCRIPTION_WIDTH); |
|
230 } |
|
231 |
|
232 // Set category column width |
|
233 value = preferences.getInt(CATEGORY_WIDTH_CONFIGURATION); |
|
234 if (value > 0) { |
|
235 categoryColumn.setWidth(value); |
|
236 } else { |
|
237 categoryColumn.setWidth(DEFAULT_CATEGORY_WIDTH); |
|
238 } |
|
239 |
|
240 // Set source column width |
|
241 value = preferences.getInt(SOURCE_WIDTH_CONFIGURATION); |
|
242 if (value > 0) { |
|
243 sourceColumn.setWidth(value); |
|
244 } else { |
|
245 sourceColumn.setWidth(DEFAULT_SOURCE_WIDTH); |
|
246 } |
|
247 |
|
248 // Set type column width |
|
249 value = preferences.getInt(TYPE_WIDTH_CONFIGURATION); |
|
250 if (value > 0) { |
|
251 typeColumn.setWidth(value); |
|
252 } else { |
|
253 typeColumn.setWidth(DEFAULT_TYPE_WIDTH); |
|
254 } |
|
255 } |
|
256 |
|
257 /** |
|
258 * Creates the descriptions column |
|
259 * |
|
260 * @param tableWidget |
|
261 * the table widget |
|
262 */ |
|
263 private void createDescriptionColumn(Table tableWidget) { |
|
264 descriptionColumn = new TableColumn(tableWidget, SWT.NONE); |
|
265 descriptionColumn.setText(DESCRIPTION_TITLE); |
|
266 descriptionColumn.addControlListener(new ControlListener() { |
|
267 |
|
268 public void controlMoved(ControlEvent e) { |
|
269 } |
|
270 |
|
271 public void controlResized(ControlEvent e) { |
|
272 Activator.getDefault().getPreferenceStore().setValue( |
|
273 DESCRIPTION_WIDTH_CONFIGURATION, |
|
274 descriptionColumn.getWidth()); |
|
275 } |
|
276 |
|
277 }); |
|
278 createColumnSorter(tableWidget, descriptionColumn, |
|
279 DESCRIPTION_COLUM_INDEX); |
|
280 } |
|
281 |
|
282 /** |
|
283 * Creates the category column |
|
284 * |
|
285 * @param tableWidget |
|
286 * the table widget |
|
287 */ |
|
288 private void createCategoryColumn(Table tableWidget) { |
|
289 categoryColumn = new TableColumn(tableWidget, SWT.NONE); |
|
290 categoryColumn.setText(CATEGORY_TITLE); |
|
291 categoryColumn.addControlListener(new ControlListener() { |
|
292 |
|
293 public void controlMoved(ControlEvent e) { |
|
294 } |
|
295 |
|
296 public void controlResized(ControlEvent e) { |
|
297 Activator.getDefault().getPreferenceStore() |
|
298 .setValue(CATEGORY_WIDTH_CONFIGURATION, |
|
299 categoryColumn.getWidth()); |
|
300 } |
|
301 |
|
302 }); |
|
303 createColumnSorter(tableWidget, categoryColumn, CATEGORY_COLUM_INDEX); |
|
304 } |
|
305 |
|
306 /** |
|
307 * Creates the sources column |
|
308 * |
|
309 * @param tableWidget |
|
310 * the table widget |
|
311 */ |
|
312 private void createSourceColumn(Table tableWidget) { |
|
313 sourceColumn = new TableColumn(tableWidget, SWT.NONE); |
|
314 sourceColumn.setText(SOURCE_TITLE); |
|
315 sourceColumn.addControlListener(new ControlListener() { |
|
316 |
|
317 public void controlMoved(ControlEvent e) { |
|
318 } |
|
319 |
|
320 public void controlResized(ControlEvent e) { |
|
321 Activator.getDefault().getPreferenceStore().setValue( |
|
322 SOURCE_WIDTH_CONFIGURATION, sourceColumn.getWidth()); |
|
323 } |
|
324 |
|
325 }); |
|
326 createColumnSorter(tableWidget, sourceColumn, SOURCE_COLUM_INDEX); |
|
327 } |
|
328 |
|
329 /** |
|
330 * Creates the type column |
|
331 * |
|
332 * @param tableWidget |
|
333 * the table widget |
|
334 */ |
|
335 private void createTypeColumn(final Table tableWidget) { |
|
336 typeColumn = new TableColumn(tableWidget, SWT.NONE); |
|
337 typeColumn.setText(TYPE_TITLE); |
|
338 typeColumn.addControlListener(new ControlListener() { |
|
339 |
|
340 public void controlMoved(ControlEvent e) { |
|
341 } |
|
342 |
|
343 public void controlResized(ControlEvent e) { |
|
344 Activator.getDefault().getPreferenceStore().setValue( |
|
345 TYPE_WIDTH_CONFIGURATION, typeColumn.getWidth()); |
|
346 } |
|
347 |
|
348 }); |
|
349 createColumnSorter(tableWidget, typeColumn, TYPE_COLUM_INDEX); |
|
350 } |
|
351 |
|
352 /** |
|
353 * Creates sort listener |
|
354 * |
|
355 * @param tableWidget |
|
356 * table widget |
|
357 * @param column |
|
358 * column to create sort listener for |
|
359 * @param index |
|
360 * column index |
|
361 */ |
|
362 private void createColumnSorter(final Table tableWidget, |
|
363 final TableColumn column, final int index) { |
|
364 |
|
365 TableColumnSorter cSorter = new TableColumnSorter(table, column) { |
|
366 |
|
367 @Override |
|
368 protected int doCompare(Viewer v, Object o1, Object o2) { |
|
369 ITableLabelProvider lp = ((ITableLabelProvider) table |
|
370 .getLabelProvider()); |
|
371 String t1 = lp.getColumnText(o1, index); |
|
372 String t2 = lp.getColumnText(o2, index); |
|
373 return t1.compareTo(t2); |
|
374 } |
|
375 }; |
|
376 |
|
377 // Set no sorter as initial state |
|
378 cSorter.setSorter(cSorter, TableColumnSorter.NONE); |
|
379 } |
|
380 |
|
381 /** |
|
382 * Adds menu listener to popup menu |
|
383 */ |
|
384 private void hookContextMenu() { |
|
385 |
|
386 // Create menumanager |
|
387 MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ |
|
388 menuMgr.setRemoveAllWhenShown(true); |
|
389 |
|
390 // Create the menu when event is received |
|
391 menuMgr.addMenuListener(new IMenuListener() { |
|
392 public void menuAboutToShow(IMenuManager manager) { |
|
393 IStructuredSelection selection = (IStructuredSelection) table |
|
394 .getSelection(); |
|
395 if (!selection.isEmpty()) { |
|
396 EventListEntry entry = (EventListEntry) selection |
|
397 .getFirstElement(); |
|
398 removeEventAction.setEntry(entry); |
|
399 manager.add(removeAllEventsAction); |
|
400 manager.add(removeEventAction); |
|
401 if (entry.hasSourceActions()) { |
|
402 manager.add(new Separator()); |
|
403 entry.addSourceActions(manager); |
|
404 } |
|
405 manager.add(new Separator( |
|
406 IWorkbenchActionConstants.MB_ADDITIONS)); |
|
407 } |
|
408 } |
|
409 }); |
|
410 |
|
411 // Set the menu in to the table |
|
412 Menu menu = menuMgr.createContextMenu(table.getControl()); |
|
413 table.getControl().setMenu(menu); |
|
414 getSite().registerContextMenu(menuMgr, table); |
|
415 } |
|
416 |
|
417 /* |
|
418 * (non-Javadoc) |
|
419 * |
|
420 * @see org.eclipse.ui.part.WorkbenchPart#setFocus() |
|
421 */ |
|
422 @Override |
|
423 public void setFocus() { |
|
424 table.getControl().setFocus(); |
|
425 } |
|
426 |
|
427 /** |
|
428 * Gets the event list interface |
|
429 * |
|
430 * @return the event list |
|
431 */ |
|
432 public static TraceEventList getEventList() { |
|
433 TraceEventList list = Activator.getDefault().eventList; |
|
434 if (list == null) { |
|
435 list = new EventListContentProvider(); |
|
436 Activator.getDefault().eventList = list; |
|
437 } |
|
438 return list; |
|
439 } |
|
440 |
|
441 /* |
|
442 * (non-Javadoc) |
|
443 * |
|
444 * @see com.nokia.trace.eventview.ContentChangeListener#contentChanged() |
|
445 */ |
|
446 public void contentChanged() { |
|
447 IWorkbenchSiteProgressService progressService = (IWorkbenchSiteProgressService) getSite() |
|
448 .getAdapter(IWorkbenchSiteProgressService.class); |
|
449 progressService.warnOfContentChange(); |
|
450 } |
|
451 } |