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
CommitLineData
79e08fd0 1/*******************************************************************************
09667aa4 2 * Copyright (c) 2011, 2012 Ericsson
20ff3b75 3 *
79e08fd0
BH
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
20ff3b75 8 *
79e08fd0 9 * Contributors:
09667aa4 10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Implementation and Initial API
79e08fd0
BH
11 *******************************************************************************/
12
cfd22ad0 13package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model;
79e08fd0
BH
14
15import java.util.Arrays;
16import java.util.HashSet;
9fa32496 17import java.util.List;
79e08fd0
BH
18import java.util.Set;
19import java.util.Vector;
20
21import org.eclipse.jface.viewers.ColumnLabelProvider;
22import org.eclipse.jface.viewers.Viewer;
23import org.eclipse.jface.viewers.ViewerComparator;
cfd22ad0 24import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData.ITmfColumnPercentageProvider;
79e08fd0
BH
25import org.eclipse.swt.SWT;
26import org.eclipse.swt.graphics.Image;
27import org.eclipse.ui.ISharedImages;
28import org.eclipse.ui.PlatformUI;
29
30/**
b544077e 31 * Create a basic list of columns with providers.
20ff3b75 32 *
25a042b3 33 * @version 2.0
b544077e 34 * @author Mathieu Denis
cfd22ad0 35 * @since 2.0
79e08fd0
BH
36 */
37public class TmfBaseColumnDataProvider implements ITmfColumnDataProvider {
38
39 /**
40 * Contains the list of the columns
41 */
9fa32496 42 protected List<TmfBaseColumnData> fColumnData = null;
09667aa4 43
79e08fd0
BH
44 /**
45 * Level column names
46 */
66711dc8 47 protected final static String LEVEL_COLUMN = Messages.TmfStatisticsView_LevelColumn;
09667aa4 48
79e08fd0
BH
49 /**
50 * Number of events column names
51 */
66711dc8 52 protected final static String EVENTS_COUNT_COLUMN = Messages.TmfStatisticsView_NbEventsColumn;
09667aa4 53
25a042b3
MD
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;
79e08fd0
BH
59 /**
60 * Level column tooltips
61 */
66711dc8 62 protected final static String LEVEL_COLUMN_TIP = Messages.TmfStatisticsView_LevelColumnTip;
09667aa4 63
79e08fd0
BH
64 /**
65 * Number of events column tooltips
66 */
66711dc8 67 protected final static String EVENTS_COUNT_COLUMN_TIP = Messages.TmfStatisticsView_NbEventsTip;
09667aa4 68
25a042b3
MD
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;
79e08fd0
BH
74 /**
75 * Level for which statistics should not be displayed.
76 */
507b1336 77 protected Set<String> fFolderLevels = new HashSet<>(Arrays.asList(new String[] { "Event Types" })); //$NON-NLS-1$
09667aa4 78
79e08fd0
BH
79 /**
80 * Create basic columns to represent the statistics data
81 */
82 public TmfBaseColumnDataProvider() {
09667aa4 83 /* List that will be used to create the table. */
507b1336 84 fColumnData = new Vector<>();
25a042b3 85 /* Column showing the name of the events and its level in the tree */
79e08fd0
BH
86 fColumnData.add(new TmfBaseColumnData(LEVEL_COLUMN, 200, SWT.LEFT, LEVEL_COLUMN_TIP, new ColumnLabelProvider() {
87 @Override
88 public String getText(Object element) {
7588c810 89 return ((TmfStatisticsTreeNode) element).getName();
79e08fd0
BH
90 }
91
92 @Override
93 public Image getImage(Object element) {
94 TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
7588c810 95 if (fFolderLevels.contains(node.getName())) {
79e08fd0 96 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
79e08fd0 97 }
abbdd66a 98 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
79e08fd0
BH
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
7588c810 106 return n1.getName().compareTo(n2.getName());
79e08fd0
BH
107 }
108 }, null));
109
25a042b3
MD
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;
7588c810 115 if (!fFolderLevels.contains(node.getName())) {
89c06060 116 return Long.toString(node.getValues().getTotal());
25a042b3
MD
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
89c06060 126 return (int) (n1.getValues().getTotal() - n2.getValues().getTotal());
25a042b3
MD
127 }
128 }, new ITmfColumnPercentageProvider() {
129
130 @Override
131 public double getPercentage(TmfStatisticsTreeNode node) {
132 TmfStatisticsTreeNode parent = node;
133 do {
134 parent = parent.getParent();
89c06060 135 } while (parent != null && parent.getValues().getTotal() == 0);
25a042b3
MD
136
137 if (parent == null) {
138 return 0;
139 }
89c06060 140 return (double) node.getValues().getTotal() / parent.getValues().getTotal();
25a042b3
MD
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() {
79e08fd0
BH
147 @Override
148 public String getText(Object element) {
149 TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element;
7588c810 150 if (!fFolderLevels.contains(node.getName())) {
89c06060 151 return Long.toString(node.getValues().getPartial());
79e08fd0 152 }
abbdd66a 153 return ""; //$NON-NLS-1$
79e08fd0
BH
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
89c06060 161 return (int) (n1.getValues().getPartial() - n2.getValues().getPartial());
79e08fd0
BH
162 }
163 }, new ITmfColumnPercentageProvider() {
164
165 @Override
166 public double getPercentage(TmfStatisticsTreeNode node) {
167 TmfStatisticsTreeNode parent = node;
168 do {
169 parent = parent.getParent();
89c06060 170 } while (parent != null && parent.getValues().getPartial() == 0);
79e08fd0
BH
171
172 if (parent == null) {
173 return 0;
79e08fd0 174 }
89c06060 175 return (double) node.getValues().getPartial() / parent.getValues().getPartial();
79e08fd0
BH
176 }
177 }));
178 }
179
180 /**
181 * Provide the columns to represent statistics data
182 */
183 @Override
9fa32496 184 public List<TmfBaseColumnData> getColumnData() {
79e08fd0
BH
185 return fColumnData;
186 }
187
188}
This page took 0.061745 seconds and 5 git commands to generate.