1 | |
package org.kuali.student.lum.common.client.widgets; |
2 | |
|
3 | |
import com.google.gwt.user.client.ui.ListBox; |
4 | |
|
5 | |
import java.util.HashMap; |
6 | |
import java.util.List; |
7 | |
import java.util.Map; |
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
public class DropdownList extends ListBox { |
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | 0 | private Map<String, Integer> model = new HashMap<String, Integer>(); |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | 0 | private Integer index = 0; |
26 | |
|
27 | 0 | public DropdownList() { |
28 | 0 | } |
29 | |
|
30 | 0 | public DropdownList(List<String> list) { |
31 | 0 | for (String s : list) { |
32 | 0 | addItem(s); |
33 | |
} |
34 | 0 | } |
35 | |
|
36 | |
@Override |
37 | |
public void addItem(String value) { |
38 | 0 | model.put(value, index++); |
39 | 0 | super.addItem(value); |
40 | 0 | } |
41 | |
|
42 | |
public void setSelectedItem(String value) { |
43 | 0 | if (model.get(value) == null) { |
44 | 0 | setSelectedIndex(0); |
45 | |
} else { |
46 | 0 | setSelectedIndex(model.get(value)); |
47 | |
} |
48 | 0 | } |
49 | |
|
50 | |
public String getSelectedValue() { |
51 | 0 | return getValue(getSelectedIndex()); |
52 | |
} |
53 | |
|
54 | |
public void setList(List<String> relationship) { |
55 | 0 | for (String s : relationship) { |
56 | 0 | addItem(s); |
57 | |
} |
58 | 0 | } |
59 | |
|
60 | |
public void reset() { |
61 | 0 | setSelectedIndex(0); |
62 | 0 | } |
63 | |
} |