tmf: Switch tmf.ui to Java 7 + fix warnings
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / viewers / statistics / model / TmfBaseColumnDataProvider.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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.viewers.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.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;
29
30 /**
31 * Create a basic list of columns with providers.
32 *
33 * @version 2.0
34 * @author Mathieu Denis
35 * @since 2.0
36 */
37 public class TmfBaseColumnDataProvider implements ITmfColumnDataProvider {
38
39 /**
40 * Contains the list of the columns
41 */
42 protected List<TmfBaseColumnData> fColumnData = null;
43
44 /**
45 * Level column names
46 */
47 protected final static String LEVEL_COLUMN = Messages.TmfStatisticsView_LevelColumn;
48
49 /**
50 * Number of events column names
51 */
52 protected final static String EVENTS_COUNT_COLUMN = Messages.TmfStatisticsView_NbEventsColumn;
53
54 /**
55 * Number of events in time range column names
56 * @since 2.0
57 */
58 protected final static String PARTIAL_EVENTS_COUNT_COLUMN = Messages.TmfStatisticsView_NbEventsTimeRangeColumn;
59 /**
60 * Level column tooltips
61 */
62 protected final static String LEVEL_COLUMN_TIP = Messages.TmfStatisticsView_LevelColumnTip;
63
64 /**
65 * Number of events column tooltips
66 */
67 protected final static String EVENTS_COUNT_COLUMN_TIP = Messages.TmfStatisticsView_NbEventsTip;
68
69 /**
70 * Number of events in time range column tooltips
71 * @since 2.0
72 */
73 protected final static String PARTIAL_COUNT_COLUMN_TIP = Messages.TmfStatisticsView_NbEventsTimeRangeTip;
74 /**
75 * Level for which statistics should not be displayed.
76 */
77 protected Set<String> fFolderLevels = new HashSet<>(Arrays.asList(new String[] { "Event Types" })); //$NON-NLS-1$
78
79 /**
80 * Create basic columns to represent the statistics data
81 */
82 public TmfBaseColumnDataProvider() {
83 /* List that will be used to create the table. */
84 fColumnData = new Vector<>();
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() {
87 @Override
88 public String getText(Object element) {
89 return ((TmfStatisticsTreeNode) element).getName();
90 }
91
92 @Override
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);
97 }
98 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
99 }
100 }, new ViewerComparator() {
101 @Override
102 public int compare(Viewer viewer, Object e1, Object e2) {
103 TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
104 TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
105
106 return n1.getName().compareTo(n2.getName());
107 }
108 }, null));
109
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() {
112 @Override
113 public String getText(Object element) {
114 TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
115 if (!fFolderLevels.contains(node.getName())) {
116 return Long.toString(node.getValues().getTotal());
117 }
118 return ""; //$NON-NLS-1$
119 }
120 }, new ViewerComparator() {
121 @Override
122 public int compare(Viewer viewer, Object e1, Object e2) {
123 TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
124 TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
125
126 return (int) (n1.getValues().getTotal() - n2.getValues().getTotal());
127 }
128 }, new ITmfColumnPercentageProvider() {
129
130 @Override
131 public double getPercentage(TmfStatisticsTreeNode node) {
132 TmfStatisticsTreeNode parent = node;
133 do {
134 parent = parent.getParent();
135 } while (parent != null && parent.getValues().getTotal() == 0);
136
137 if (parent == null) {
138 return 0;
139 }
140 return (double) node.getValues().getTotal() / parent.getValues().getTotal();
141 }
142 }));
143
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() {
147 @Override
148 public String getText(Object element) {
149 TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
150 if (!fFolderLevels.contains(node.getName())) {
151 return Long.toString(node.getValues().getPartial());
152 }
153 return ""; //$NON-NLS-1$
154 }
155 }, new ViewerComparator() {
156 @Override
157 public int compare(Viewer viewer, Object e1, Object e2) {
158 TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1;
159 TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2;
160
161 return (int) (n1.getValues().getPartial() - n2.getValues().getPartial());
162 }
163 }, new ITmfColumnPercentageProvider() {
164
165 @Override
166 public double getPercentage(TmfStatisticsTreeNode node) {
167 TmfStatisticsTreeNode parent = node;
168 do {
169 parent = parent.getParent();
170 } while (parent != null && parent.getValues().getPartial() == 0);
171
172 if (parent == null) {
173 return 0;
174 }
175 return (double) node.getValues().getPartial() / parent.getValues().getPartial();
176 }
177 }));
178 }
179
180 /**
181 * Provide the columns to represent statistics data
182 */
183 @Override
184 public List<TmfBaseColumnData> getColumnData() {
185 return fColumnData;
186 }
187
188 }
This page took 0.051496 seconds and 5 git commands to generate.