97869998cc9f848246d167a6a636beca060f9b07
[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.List;
18 import java.util.Set;
19 import java.util.Vector;
20
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;
30
31 /**
32 * Create a basic list of columns with providers
33 */
34 public class TmfBaseColumnDataProvider implements ITmfColumnDataProvider {
35
36 /**
37 * Contains the list of the columns
38 */
39 protected List<TmfBaseColumnData> fColumnData = null;
40
41 /**
42 * Level column names
43 */
44 protected final static String LEVEL_COLUMN = Messages.TmfStatisticsView_LevelColumn;
45 /**
46 * Number of events column names
47 */
48 protected final static String EVENTS_COUNT_COLUMN = Messages.TmfStatisticsView_NbEventsColumn;
49
50 /**
51 * Level column tooltips
52 */
53 protected final static String LEVEL_COLUMN_TIP = Messages.TmfStatisticsView_LevelColumnTip;
54 /**
55 * Number of events column tooltips
56 */
57 protected final static String EVENTS_COUNT_COLUMN_TIP = Messages.TmfStatisticsView_NbEventsTip;
58
59 /**
60 * Level for which statistics should not be displayed.
61 */
62 protected Set<String> fFolderLevels = new HashSet<String>(Arrays.asList(new String[] { "Event Types" })); //$NON-NLS-1$
63
64 /**
65 * Create basic columns to represent the statistics data
66 */
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() {
71 @Override
72 public String getText(Object element) {
73 return ((TmfStatisticsTreeNode) element).getKey();
74 }
75
76 @Override
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);
81 } else {
82 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
83 }
84 }
85 }, new ViewerComparator() {
86 @Override
87 public int compare(Viewer viewer, Object e1, Object e2) {
88 TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
89 TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
90
91 return n1.getKey().compareTo(n2.getKey());
92 }
93 }, null));
94
95 fColumnData.add(new TmfBaseColumnData(EVENTS_COUNT_COLUMN, 125, SWT.LEFT, EVENTS_COUNT_COLUMN_TIP, new ColumnLabelProvider() {
96 @Override
97 public String getText(Object element) {
98 TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
99 if (!fFolderLevels.contains(node.getKey())) {
100 return Long.toString(node.getValue().nbEvents);
101 } else {
102 return ""; //$NON-NLS-1$
103 }
104 }
105 }, new ViewerComparator() {
106 @Override
107 public int compare(Viewer viewer, Object e1, Object e2) {
108 TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
109 TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
110
111 return (int) (n1.getValue().nbEvents - n2.getValue().nbEvents);
112 }
113 }, new ITmfColumnPercentageProvider() {
114
115 @Override
116 public double getPercentage(TmfStatisticsTreeNode node) {
117 TmfStatisticsTreeNode parent = node;
118 do {
119 parent = parent.getParent();
120 } while (parent != null && parent.getValue().nbEvents == 0);
121
122 if (parent == null) {
123 return 0;
124 } else {
125 return (double) node.getValue().nbEvents / parent.getValue().nbEvents;
126 }
127 }
128 }));
129 }
130
131 /**
132 * Provide the columns to represent statistics data
133 */
134 @Override
135 public List<TmfBaseColumnData> getColumnData() {
136 return fColumnData;
137 }
138
139 }
This page took 0.033133 seconds and 4 git commands to generate.