Skip to main content
summaryrefslogtreecommitdiffstats
blob: 49f4c69aa509d64f5496b92fbe1a29a158d42f95 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*******************************************************************************
 * Copyright (c) 2004, 2014 Frank Becker 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:
 *     Frank Becker - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.bugzilla.core;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Class describing a custom Fields for a given Bugzilla installation.
 * 
 * @author Frank Becker
 * @since 2.3
 */
public class BugzillaCustomField implements Serializable {

	// old version	private static final long serialVersionUID = 5703683576871326128L;
	//              private static final long serialVersionUID = 7273310489883205486L;

	private static final long serialVersionUID = 8268371206426652131L;

	public static final String CUSTOM_FIELD_PREFIX = "cf_"; //$NON-NLS-1$

	public static enum FieldType {
		UNKNOWN, FreeText, DropDown, MultipleSelection, LargeText, DateTime, BugId;

		private static int parseInt(String type) {
			try {
				return Integer.parseInt(type);
			} catch (NumberFormatException e) {
				return -1;
			}
		}

		@Override
		public String toString() {
			switch (this.ordinal()) {
			case 1:
				return "Free Text"; //$NON-NLS-1$
			case 2:
				return "Drop Down"; //$NON-NLS-1$
			case 3:
				return "Multiple-Selection Box"; //$NON-NLS-1$
			case 4:
				return "Large Text Box"; //$NON-NLS-1$
			case 5:
				return "Date/Time"; //$NON-NLS-1$
			case 6:
				return "Bug ID"; //$NON-NLS-1$
			default:
				return super.toString();
			}
		}

		public static FieldType convert(String change) {
			switch (parseInt(change)) {
			case 1:
				return FreeText;
			case 2:
				return DropDown;
			case 3:
				return MultipleSelection;
			case 4:
				return LargeText;
			case 5:
				return DateTime;
			case 6:
				return BugId;
			default:
				return UNKNOWN;
			}
		}
	}

	private final String name;

	private final String description;

	private List<String> options = new ArrayList<String>();

	final private int type;

	final private FieldType fieldType;

	final private boolean enterBug;

	public BugzillaCustomField(String description, String name, String type, String enterBug) {
		this.description = description;
		this.name = name;
		this.type = parseInt(type);
		this.fieldType = FieldType.convert(type);
		this.enterBug = "1".equals(enterBug); //$NON-NLS-1$
	}

	private int parseInt(String type) {
		try {
			return Integer.parseInt(type);
		} catch (NumberFormatException e) {
			return -1;
		}
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public List<String> getOptions() {
		return options;
	}

	public void setOptions(List<String> options) {
		this.options = options;
	}

	public void addOption(String option) {
		this.options.add(option);
	}

	/**
	 * @since 3.0.2
	 * @deprecated use {@link #getFieldType()} instead
	 */
	@Deprecated
	public int getType() {
		return type;
	}

	/**
	 * @since 3.0.2
	 * @deprecated use {@link #getFieldType().toString()} instead
	 */
	@Deprecated
	public String getTypeDesc() {
		return getFieldType().toString();
	}

	/**
	 * @since 3.0.2
	 */
	public boolean isEnterBug() {
		return enterBug;
	}

	public FieldType getFieldType() {
		return fieldType;
	}

}

Back to the top