1 /*******************************************************************************
2 * Copyright (c) 2011 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 * Mathieu Denis (mathieu.denis@polymtl.ca) - Implementation and Initial API
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
;
15 import java
.util
.Arrays
;
16 import java
.util
.HashSet
;
17 import java
.util
.List
;
19 import java
.util
.Vector
;
21 import org
.eclipse
.jface
.viewers
.ColumnLabelProvider
;
22 import org
.eclipse
.jface
.viewers
.Viewer
;
23 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.Messages
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.model
.TmfBaseColumnData
.ITmfColumnPercentageProvider
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.graphics
.Image
;
28 import org
.eclipse
.ui
.ISharedImages
;
29 import org
.eclipse
.ui
.PlatformUI
;
32 * Create a basic list of columns with providers
34 public class TmfBaseColumnDataProvider
implements ITmfColumnDataProvider
{
37 * Contains the list of the columns
39 protected List
<TmfBaseColumnData
> fColumnData
= null;
44 protected final static String LEVEL_COLUMN
= Messages
.TmfStatisticsView_LevelColumn
;
46 * Number of events column names
48 protected final static String EVENTS_COUNT_COLUMN
= Messages
.TmfStatisticsView_NbEventsColumn
;
51 * Level column tooltips
53 protected final static String LEVEL_COLUMN_TIP
= Messages
.TmfStatisticsView_LevelColumnTip
;
55 * Number of events column tooltips
57 protected final static String EVENTS_COUNT_COLUMN_TIP
= Messages
.TmfStatisticsView_NbEventsTip
;
60 * Level for which statistics should not be displayed.
62 protected Set
<String
> fFolderLevels
= new HashSet
<String
>(Arrays
.asList(new String
[] { "Event Types" })); //$NON-NLS-1$
65 * Create basic columns to represent the statistics data
67 public TmfBaseColumnDataProvider() {
68 // List that will be used to create the table.
69 fColumnData
= new Vector
<TmfBaseColumnData
>();
70 fColumnData
.add(new TmfBaseColumnData(LEVEL_COLUMN
, 200, SWT
.LEFT
, LEVEL_COLUMN_TIP
, new ColumnLabelProvider() {
72 public String
getText(Object element
) {
73 return ((TmfStatisticsTreeNode
) element
).getKey();
77 public Image
getImage(Object element
) {
78 TmfStatisticsTreeNode node
= (TmfStatisticsTreeNode
) element
;
79 if (fFolderLevels
.contains(node
.getKey())) {
80 return PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_FOLDER
);
82 return PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_ELEMENT
);
85 }, new ViewerComparator() {
87 public int compare(Viewer viewer
, Object e1
, Object e2
) {
88 TmfStatisticsTreeNode n1
= (TmfStatisticsTreeNode
) e1
;
89 TmfStatisticsTreeNode n2
= (TmfStatisticsTreeNode
) e2
;
91 return n1
.getKey().compareTo(n2
.getKey());
95 fColumnData
.add(new TmfBaseColumnData(EVENTS_COUNT_COLUMN
, 125, SWT
.LEFT
, EVENTS_COUNT_COLUMN_TIP
, new ColumnLabelProvider() {
97 public String
getText(Object element
) {
98 TmfStatisticsTreeNode node
= (TmfStatisticsTreeNode
) element
;
99 if (!fFolderLevels
.contains(node
.getKey())) {
100 return Long
.toString(node
.getValue().nbEvents
);
102 return ""; //$NON-NLS-1$
105 }, new ViewerComparator() {
107 public int compare(Viewer viewer
, Object e1
, Object e2
) {
108 TmfStatisticsTreeNode n1
= (TmfStatisticsTreeNode
) e1
;
109 TmfStatisticsTreeNode n2
= (TmfStatisticsTreeNode
) e2
;
111 return (int) (n1
.getValue().nbEvents
- n2
.getValue().nbEvents
);
113 }, new ITmfColumnPercentageProvider() {
116 public double getPercentage(TmfStatisticsTreeNode node
) {
117 TmfStatisticsTreeNode parent
= node
;
119 parent
= parent
.getParent();
120 } while (parent
!= null && parent
.getValue().nbEvents
== 0);
122 if (parent
== null) {
125 return (double) node
.getValue().nbEvents
/ parent
.getValue().nbEvents
;
132 * Provide the columns to represent statistics data
135 public List
<TmfBaseColumnData
> getColumnData() {