Added TMF statistics feature (Bug 360572)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / statistics / model / TmfBaseColumnDataProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2011 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 * Mathieu Denis (mathieu.denis@polymtl.ca) - Implementation and Initial API
11 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.statistics.model;
14
15 import java.util.Arrays;
16 import java.util.HashSet;
17 import java.util.Set;
18 import java.util.Vector;
19
20 import org.eclipse.jface.viewers.ColumnLabelProvider;
21 import org.eclipse.jface.viewers.Viewer;
22 import org.eclipse.jface.viewers.ViewerComparator;
23 import org.eclipse.linuxtools.tmf.ui.views.statistics.Messages;
24 import org.eclipse.linuxtools.tmf.ui.views.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;
29
30 /**
31 * Create a basic list of columns with providers
32 */
33 public class TmfBaseColumnDataProvider implements ITmfColumnDataProvider {
34
35 /**
36 * Contains the list of the columns
37 */
38 private static Vector<TmfBaseColumnData> fColumnData = null;
39
40 /**
41 * Level column names
42 */
43 private final static String LEVEL_COLUMN = Messages.TmfStatisticsView_LevelColumn;
44 /**
45 * Number of events column names
46 */
47 private final static String EVENTS_COUNT_COLUMN = Messages.TmfStatisticsView_NbEventsColumn;
48
49 /**
50 * Level column tooltips
51 */
52 private final static String LEVEL_COLUMN_TIP = Messages.TmfStatisticsView_LevelColumnTip;
53 /**
54 * Number of events column tooltips
55 */
56 private final static String EVENTS_COUNT_COLUMN_TIP = Messages.TmfStatisticsView_NbEventsTip;
57
58 /**
59 * Level for which statistics should not be displayed.
60 */
61 private static Set<String> fFolderLevels = new HashSet<String>(Arrays.asList(new String[] { "Event Types" })); //$NON-NLS-1$
62
63 /**
64 * Create basic columns to represent the statistics data
65 */
66 public TmfBaseColumnDataProvider() {
67 // List that will be used to create the table.
68 fColumnData = new Vector<TmfBaseColumnData>();
69 fColumnData.add(new TmfBaseColumnData(LEVEL_COLUMN, 200, SWT.LEFT, LEVEL_COLUMN_TIP, new ColumnLabelProvider() {
70 @Override
71 public String getText(Object element) {
72 return ((TmfStatisticsTreeNode) element).getKey();
73 }
74
75 @Override
76 public Image getImage(Object element) {
77 TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
78 if (fFolderLevels.contains(node.getKey())) {
79 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
80 } else {
81 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
82 }
83 }
84 }, new ViewerComparator() {
85 @Override
86 public int compare(Viewer viewer, Object e1, Object e2) {
87 TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
88 TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
89
90 return n1.getKey().compareTo(n2.getKey());
91 }
92 }, null));
93
94 fColumnData.add(new TmfBaseColumnData(EVENTS_COUNT_COLUMN, 125, SWT.LEFT, EVENTS_COUNT_COLUMN_TIP, new ColumnLabelProvider() {
95 @Override
96 public String getText(Object element) {
97 TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
98 if (!fFolderLevels.contains(node.getKey())) {
99 return Long.toString(node.getValue().nbEvents);
100 } else {
101 return ""; //$NON-NLS-1$
102 }
103 }
104 }, new ViewerComparator() {
105 @Override
106 public int compare(Viewer viewer, Object e1, Object e2) {
107 TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
108 TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
109
110 return (int) (n1.getValue().nbEvents - n2.getValue().nbEvents);
111 }
112 }, new ITmfColumnPercentageProvider() {
113
114 @Override
115 public double getPercentage(TmfStatisticsTreeNode node) {
116 TmfStatisticsTreeNode parent = node;
117 do {
118 parent = parent.getParent();
119 } while (parent != null && parent.getValue().nbEvents == 0);
120
121 if (parent == null) {
122 return 0;
123 } else {
124 return (double) node.getValue().nbEvents / parent.getValue().nbEvents;
125 }
126 }
127 }));
128 }
129
130 /**
131 * Provide the columns to represent statistics data
132 */
133 @Override
134 public Vector<TmfBaseColumnData> getColumnData() {
135 return fColumnData;
136 }
137
138 }
This page took 0.034325 seconds and 5 git commands to generate.