Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 371285 | Differences between
and this patch

Collapse All | Expand All

(-)a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfDiffLabelProvider.java (+115 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 Red Hat, Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Camilo Bernal <cabernal@redhat.com> - Initial Implementation.
10
 *******************************************************************************/
11
package org.eclipse.linuxtools.internal.perf.ui;
12
13
import org.eclipse.jface.resource.StringConverter;
14
import org.eclipse.jface.viewers.ILabelProviderListener;
15
import org.eclipse.jface.viewers.ITableColorProvider;
16
import org.eclipse.jface.viewers.ITableLabelProvider;
17
import org.eclipse.linuxtools.internal.perf.model.PMSymbol;
18
import org.eclipse.linuxtools.internal.perf.model.PMSymbolMatch;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.graphics.Color;
21
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.widgets.Display;
23
24
class PerfDiffLabelProvider implements ITableLabelProvider, ITableColorProvider {
25
26
	public static final String COLOR_RED = "75, 200, 75";
27
	public static final String COLOR_GREEN = "200, 75, 75";
28
29
	@Override
30
	public Color getBackground(Object element, int columnIndex) {
31
		String result = ((PMSymbolMatch) element).getResult();
32
		switch (columnIndex) {
33
34
		case 3:
35
			try {
36
				float resFloat = Float.parseFloat(result);
37
				if (resFloat < 0) {
38
					return new Color(Display.getCurrent(),
39
							StringConverter.asRGB(COLOR_RED));
40
				} else if (resFloat == 0) {
41
					return Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
42
				} else {
43
					return new Color(Display.getCurrent(),
44
							StringConverter.asRGB(COLOR_GREEN));
45
				}
46
			} catch (Exception ex) {
47
				// result is a character string
48
				return Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
49
			}
50
		default:
51
			return Display.getCurrent().getSystemColor(SWT.COLOR_WHITE);
52
		}
53
	}
54
55
	@Override
56
	public String getColumnText(Object element, int columnIndex) {
57
		PMSymbolMatch p = (PMSymbolMatch) element;
58
		switch (columnIndex) {
59
		// function column
60
		case 0:
61
			return p.getName();
62
		// new column
63
		case 1:
64
			PMSymbol fresh = p.getFresh();
65
			return (fresh == null) ? "-" : String.valueOf(fresh.getPercent());
66
		// old column
67
		case 2:
68
			PMSymbol stale = p.getStale();
69
			return (stale == null) ? "-" : String.valueOf(stale.getPercent());
70
		// result column
71
		case 3:
72
			String result = p.getResult();
73
			try {
74
				Float.parseFloat(result);
75
				return result + "%";
76
			} catch (Exception e) {
77
				return result;
78
			}
79
		// event column
80
		case 4:
81
			return p.getEvent();
82
		case 5:
83
			return "";
84
		default:
85
			throw new RuntimeException("Something went wrong");
86
		}
87
	}
88
89
	@Override
90
	public void addListener(ILabelProviderListener listener) {
91
	}
92
93
	@Override
94
	public void dispose() {
95
	}
96
97
	@Override
98
	public boolean isLabelProperty(Object element, String property) {
99
		return false;
100
	}
101
102
	@Override
103
	public void removeListener(ILabelProviderListener listener) {
104
	}
105
106
	@Override
107
	public Color getForeground(Object element, int columnIndex) {
108
		return null;
109
	}
110
111
	@Override
112
	public Image getColumnImage(Object element, int columnIndex) {
113
		return null;
114
	}
115
}
(-)a/perf/org.eclipse.linuxtools.perf/src/org/eclipse/linuxtools/internal/perf/ui/PerfDiffTableSorter.java (-1 / +67 lines)
Added Link Here
0
- 
1
/*******************************************************************************
2
 * Copyright (c) 2012 Red Hat, Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *    Camilo Bernal <cabernal@redhat.com> - Initial Implementation.
10
 *******************************************************************************/
11
package org.eclipse.linuxtools.internal.perf.ui;
12
13
import org.eclipse.jface.viewers.Viewer;
14
import org.eclipse.jface.viewers.ViewerSorter;
15
import org.eclipse.linuxtools.internal.perf.model.PMSymbolMatch;
16
17
class PerfDiffTableSorter extends ViewerSorter {
18
	private int index;
19
	private int direction;
20
21
	public void setColumnIndex(int val) {
22
		if (index == val) {
23
			direction = 1 - direction;
24
		} else {
25
			direction = 0;
26
			index = val;
27
		}
28
	}
29
30
	@Override
31
	public int compare(Viewer viewer, Object e1, Object e2) {
32
		PMSymbolMatch s1 = (PMSymbolMatch) e1;
33
		PMSymbolMatch s2 = (PMSymbolMatch) e2;
34
		int ret = 0;
35
		switch (index) {
36
		// function column
37
		case 0:
38
			ret = s1.getName().compareTo(s2.getName());
39
			break;
40
		// new column
41
		case 1:
42
			ret = s1.compareSymbol(s2, /* compare fresh */true);
43
			break;
44
		// old column
45
		case 2:
46
			ret = s1.compareSymbol(s2, /* compare stale */false);
47
			break;
48
		// result column
49
		case 3:
50
			ret = s1.compareResult(s2);
51
			break;
52
		// event column
53
		case 4:
54
			ret = s1.getEvent().compareTo(s2.getEvent());
55
			break;
56
		case 5:
57
			break;
58
		default:
59
			ret = 0;
60
		}
61
		if (direction == 1) {
62
			return -ret;
63
		}
64
		return ret;
65
	}
66
67
}

Return to bug 371285