1 /*******************************************************************************
2 * Copyright (c) 2011, 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 * Mathieu Denis <mathieu.denis@polymtl.ca> - Implementation and Initial API
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.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
.viewers
.statistics
.model
.TmfBaseColumnData
.ITmfColumnPercentageProvider
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.graphics
.Image
;
27 import org
.eclipse
.ui
.ISharedImages
;
28 import org
.eclipse
.ui
.PlatformUI
;
31 * Create a basic list of columns with providers.
34 * @author Mathieu Denis
37 public class TmfBaseColumnDataProvider
implements ITmfColumnDataProvider
{
40 * Contains the list of the columns
42 protected List
<TmfBaseColumnData
> fColumnData
= null;
47 protected final static String LEVEL_COLUMN
= Messages
.TmfStatisticsView_LevelColumn
;
50 * Number of events column names
52 protected final static String EVENTS_COUNT_COLUMN
= Messages
.TmfStatisticsView_NbEventsColumn
;
55 * Number of events in time range column names
58 protected final static String PARTIAL_EVENTS_COUNT_COLUMN
= Messages
.TmfStatisticsView_NbEventsTimeRangeColumn
;
60 * Level column tooltips
62 protected final static String LEVEL_COLUMN_TIP
= Messages
.TmfStatisticsView_LevelColumnTip
;
65 * Number of events column tooltips
67 protected final static String EVENTS_COUNT_COLUMN_TIP
= Messages
.TmfStatisticsView_NbEventsTip
;
70 * Number of events in time range column tooltips
73 protected final static String PARTIAL_COUNT_COLUMN_TIP
= Messages
.TmfStatisticsView_NbEventsTimeRangeTip
;
75 * Level for which statistics should not be displayed.
77 protected Set
<String
> fFolderLevels
= new HashSet
<String
>(Arrays
.asList(new String
[] { "Event Types" })); //$NON-NLS-1$
80 * Create basic columns to represent the statistics data
82 public TmfBaseColumnDataProvider() {
83 /* List that will be used to create the table. */
84 fColumnData
= new Vector
<TmfBaseColumnData
>();
85 /* Column showing the name of the events and its level in the tree */
86 fColumnData
.add(new TmfBaseColumnData(LEVEL_COLUMN
, 200, SWT
.LEFT
, LEVEL_COLUMN_TIP
, new ColumnLabelProvider() {
88 public String
getText(Object element
) {
89 return ((TmfStatisticsTreeNode
) element
).getName();
93 public Image
getImage(Object element
) {
94 TmfStatisticsTreeNode node
= (TmfStatisticsTreeNode
) element
;
95 if (fFolderLevels
.contains(node
.getName())) {
96 return PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_FOLDER
);
98 return PlatformUI
.getWorkbench().getSharedImages().getImage(ISharedImages
.IMG_OBJ_ELEMENT
);
100 }, new ViewerComparator() {
102 public int compare(Viewer viewer
, Object e1
, Object e2
) {
103 TmfStatisticsTreeNode n1
= (TmfStatisticsTreeNode
) e1
;
104 TmfStatisticsTreeNode n2
= (TmfStatisticsTreeNode
) e2
;
106 return n1
.getName().compareTo(n2
.getName());
110 /* Column showing the total number of events */
111 fColumnData
.add(new TmfBaseColumnData(EVENTS_COUNT_COLUMN
, 140, SWT
.LEFT
, EVENTS_COUNT_COLUMN_TIP
, new ColumnLabelProvider() {
113 public String
getText(Object element
) {
114 TmfStatisticsTreeNode node
= (TmfStatisticsTreeNode
) element
;
115 if (!fFolderLevels
.contains(node
.getName())) {
116 return Long
.toString(node
.getValues().getTotal());
118 return ""; //$NON-NLS-1$
120 }, new ViewerComparator() {
122 public int compare(Viewer viewer
, Object e1
, Object e2
) {
123 TmfStatisticsTreeNode n1
= (TmfStatisticsTreeNode
) e1
;
124 TmfStatisticsTreeNode n2
= (TmfStatisticsTreeNode
) e2
;
126 return (int) (n1
.getValues().getTotal() - n2
.getValues().getTotal());
128 }, new ITmfColumnPercentageProvider() {
131 public double getPercentage(TmfStatisticsTreeNode node
) {
132 TmfStatisticsTreeNode parent
= node
;
134 parent
= parent
.getParent();
135 } while (parent
!= null && parent
.getValues().getTotal() == 0);
137 if (parent
== null) {
140 return (double) node
.getValues().getTotal() / parent
.getValues().getTotal();
144 /* Column showing the number of events within the selected time range */
145 fColumnData
.add(new TmfBaseColumnData(PARTIAL_EVENTS_COUNT_COLUMN
, 140, SWT
.LEFT
, PARTIAL_COUNT_COLUMN_TIP
,
146 new ColumnLabelProvider() {
148 public String
getText(Object element
) {
149 TmfStatisticsTreeNode node
= (TmfStatisticsTreeNode
) element
;
150 if (!fFolderLevels
.contains(node
.getName())) {
151 return Long
.toString(node
.getValues().getPartial());
153 return ""; //$NON-NLS-1$
155 }, new ViewerComparator() {
157 public int compare(Viewer viewer
, Object e1
, Object e2
) {
158 TmfStatisticsTreeNode n1
= (TmfStatisticsTreeNode
) e1
;
159 TmfStatisticsTreeNode n2
= (TmfStatisticsTreeNode
) e2
;
161 return (int) (n1
.getValues().getPartial() - n2
.getValues().getPartial());
163 }, new ITmfColumnPercentageProvider() {
166 public double getPercentage(TmfStatisticsTreeNode node
) {
167 TmfStatisticsTreeNode parent
= node
;
169 parent
= parent
.getParent();
170 } while (parent
!= null && parent
.getValues().getPartial() == 0);
172 if (parent
== null) {
175 return (double) node
.getValues().getPartial() / parent
.getValues().getPartial();
181 * Provide the columns to represent statistics data
184 public List
<TmfBaseColumnData
> getColumnData() {