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