Skip to main content
summaryrefslogtreecommitdiffstats
blob: 23fe8d0e8881f755d5d1972ca687ee11ac7398cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*******************************************************************************
 * Copyright (c) 2003 - 2005 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylar.bugzilla.core.search;

import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.mylar.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.bugzilla.core.internal.HtmlStreamTokenizer;

/**
 * Label provider for Bugzilla search items.
 */
public class BugzillaLabelProvider extends LabelProvider 
{
	/** A list of the default severity labels */
	private static final String [] severityLabel = {"blocker", "critical", "major", "normal", "minor", "trivial", "enhancement"};
	
	/** A list of the default priority labels */
	private static final String [] priorityLabel = {"P1", "P2", "P3", "P4", "P5", "--"};
	
	/** A list of the default state labels */
	private static final String [] stateLabel = {"Unconfirmed", "New", "Assigned", "Reopened", "Resolved", "Verified", "Closed"};
	
	/** A list of the default result labels */
	private static final String [] resultLabel = {"", "fixed", "invalid", "wont fix", "later", "remind", "duplicate", "works for me"};
	
	/**
	 * Returns the text for the label of the given element.
	 * 
	 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
	 */
	@Override
	public String getText(Object element) {
		if (element instanceof IMarker) {

			try {
				IMarker marker = (IMarker) element;

				// get the severity of the bug
				String severity = severityLabel[((Integer) marker
						.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_SEVERITY))
						.intValue()];

				// get the priority of the bug
				String priority = priorityLabel[((Integer) marker
						.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_PRIORITY))
						.intValue()];

				// get the state of the bug
				String state = stateLabel[((Integer) marker
						.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_STATE))
						.intValue()];

				// get the resolution of the bug
				String result = resultLabel[((Integer) marker
						.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_RESULT))
						.intValue()];

				// return a string containing the information about the bug to
				// be displayed
				// in the searh window
				String assignedTo = HtmlStreamTokenizer.unescape(marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_OWNER).toString());
				String description = HtmlStreamTokenizer.unescape(marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_DESC).toString());
				return "Bug "
						+ marker.getAttribute(IBugzillaConstants.HIT_MARKER_ATTR_ID)
						+ " ("
						+ severity
						+ " - "
						+ priority
						+ " - "
						+ state
						+ (result.length() > 0 ? " " + result : "")
						+ ") "
						+ " - "
						+ description
						+ " ("
						+ assignedTo
						+ ") ";
			}
			catch (Exception ignored) {
				// ignore if there is a problem
			}
		}

		// return an empty string if there is a problem
		return "";
	}
}

Back to the top