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 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.statistics.model; | |
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; | |
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 | /** | |
b544077e | 32 | * Create a basic list of columns with providers. |
20ff3b75 | 33 | * |
b544077e BH |
34 | * @version 1.0 |
35 | * @author Mathieu Denis | |
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 | |
79e08fd0 BH |
54 | /** |
55 | * Level column tooltips | |
56 | */ | |
66711dc8 | 57 | protected final static String LEVEL_COLUMN_TIP = Messages.TmfStatisticsView_LevelColumnTip; |
09667aa4 | 58 | |
79e08fd0 BH |
59 | /** |
60 | * Number of events column tooltips | |
61 | */ | |
66711dc8 | 62 | protected final static String EVENTS_COUNT_COLUMN_TIP = Messages.TmfStatisticsView_NbEventsTip; |
09667aa4 | 63 | |
79e08fd0 BH |
64 | /** |
65 | * Level for which statistics should not be displayed. | |
66 | */ | |
66711dc8 | 67 | protected Set<String> fFolderLevels = new HashSet<String>(Arrays.asList(new String[] { "Event Types" })); //$NON-NLS-1$ |
09667aa4 | 68 | |
79e08fd0 BH |
69 | /** |
70 | * Create basic columns to represent the statistics data | |
71 | */ | |
72 | public TmfBaseColumnDataProvider() { | |
09667aa4 | 73 | /* List that will be used to create the table. */ |
79e08fd0 BH |
74 | fColumnData = new Vector<TmfBaseColumnData>(); |
75 | fColumnData.add(new TmfBaseColumnData(LEVEL_COLUMN, 200, SWT.LEFT, LEVEL_COLUMN_TIP, new ColumnLabelProvider() { | |
76 | @Override | |
77 | public String getText(Object element) { | |
78 | return ((TmfStatisticsTreeNode) element).getKey(); | |
79 | } | |
80 | ||
81 | @Override | |
82 | public Image getImage(Object element) { | |
83 | TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element; | |
84 | if (fFolderLevels.contains(node.getKey())) { | |
85 | return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); | |
79e08fd0 | 86 | } |
abbdd66a | 87 | return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); |
79e08fd0 BH |
88 | } |
89 | }, new ViewerComparator() { | |
90 | @Override | |
91 | public int compare(Viewer viewer, Object e1, Object e2) { | |
92 | TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1; | |
93 | TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2; | |
94 | ||
95 | return n1.getKey().compareTo(n2.getKey()); | |
96 | } | |
97 | }, null)); | |
98 | ||
99 | fColumnData.add(new TmfBaseColumnData(EVENTS_COUNT_COLUMN, 125, SWT.LEFT, EVENTS_COUNT_COLUMN_TIP, new ColumnLabelProvider() { | |
100 | @Override | |
101 | public String getText(Object element) { | |
102 | TmfStatisticsTreeNode node = (TmfStatisticsTreeNode) element; | |
103 | if (!fFolderLevels.contains(node.getKey())) { | |
104 | return Long.toString(node.getValue().nbEvents); | |
79e08fd0 | 105 | } |
abbdd66a | 106 | return ""; //$NON-NLS-1$ |
79e08fd0 BH |
107 | } |
108 | }, new ViewerComparator() { | |
109 | @Override | |
110 | public int compare(Viewer viewer, Object e1, Object e2) { | |
111 | TmfStatisticsTreeNode n1 = (TmfStatisticsTreeNode) e1; | |
112 | TmfStatisticsTreeNode n2 = (TmfStatisticsTreeNode) e2; | |
113 | ||
114 | return (int) (n1.getValue().nbEvents - n2.getValue().nbEvents); | |
115 | } | |
116 | }, new ITmfColumnPercentageProvider() { | |
117 | ||
118 | @Override | |
119 | public double getPercentage(TmfStatisticsTreeNode node) { | |
120 | TmfStatisticsTreeNode parent = node; | |
121 | do { | |
122 | parent = parent.getParent(); | |
123 | } while (parent != null && parent.getValue().nbEvents == 0); | |
124 | ||
125 | if (parent == null) { | |
126 | return 0; | |
79e08fd0 | 127 | } |
abbdd66a | 128 | return (double) node.getValue().nbEvents / parent.getValue().nbEvents; |
79e08fd0 BH |
129 | } |
130 | })); | |
131 | } | |
132 | ||
133 | /** | |
134 | * Provide the columns to represent statistics data | |
135 | */ | |
136 | @Override | |
9fa32496 | 137 | public List<TmfBaseColumnData> getColumnData() { |
79e08fd0 BH |
138 | return fColumnData; |
139 | } | |
140 | ||
141 | } |