Commit | Line | Data |
---|---|---|
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 | 13 | package org.eclipse.linuxtools.tmf.ui.viewers.statistics.model; |
79e08fd0 BH |
14 | |
15 | import java.util.Arrays; | |
16 | import java.util.HashSet; | |
9fa32496 | 17 | import java.util.List; |
79e08fd0 BH |
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; | |
cfd22ad0 | 24 | import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfBaseColumnData.ITmfColumnPercentageProvider; |
79e08fd0 BH |
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 | /** | |
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 | */ |
37 | public 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 | */ | |
66711dc8 | 77 | protected Set<String> fFolderLevels = new HashSet<String>(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. */ |
79e08fd0 | 84 | fColumnData = new Vector<TmfBaseColumnData>(); |
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) { | |
89 | return ((TmfStatisticsTreeNode) element).getKey(); | |
90 | } | |
91 | ||
92 | @Override | |
93 | public Image getImage(Object element) { | |
94 | TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element; | |
95 | if (fFolderLevels.contains(node.getKey())) { | |
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 | ||
106 | return n1.getKey().compareTo(n2.getKey()); | |
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; | |
115 | if (!fFolderLevels.contains(node.getKey())) { | |
116 | return Long.toString(node.getValue().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.getValue().getTotal() - n2.getValue().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.getValue().getTotal() == 0); | |
136 | ||
137 | if (parent == null) { | |
138 | return 0; | |
139 | } | |
140 | return (double) node.getValue().getTotal() / parent.getValue().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() { | |
79e08fd0 BH |
147 | @Override |
148 | public String getText(Object element) { | |
149 | TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element; | |
150 | if (!fFolderLevels.contains(node.getKey())) { | |
25a042b3 | 151 | return Long.toString(node.getValue().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 | ||
25a042b3 | 161 | return (int) (n1.getValue().getPartial() - n2.getValue().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(); | |
25a042b3 | 170 | } while (parent != null && parent.getValue().getPartial() == 0); |
79e08fd0 BH |
171 | |
172 | if (parent == null) { | |
173 | return 0; | |
79e08fd0 | 174 | } |
25a042b3 | 175 | return (double) node.getValue().getPartial() / parent.getValue().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 | } |