| 1 | |
package org.kuali.student.lum.common.client.widgets; |
| 2 | |
|
| 3 | |
import java.util.HashMap; |
| 4 | |
import java.util.List; |
| 5 | |
import java.util.Map; |
| 6 | |
|
| 7 | |
import com.google.gwt.user.client.ui.ListBox; |
| 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 | |
|
| 64 | |
public void clear() { |
| 65 | 0 | super.clear(); |
| 66 | 0 | model.clear(); |
| 67 | 0 | index = 0; |
| 68 | 0 | } |
| 69 | |
|
| 70 | |
public void removeItem(String value) { |
| 71 | 0 | if (null != model.get(value)) { |
| 72 | 0 | removeItem(model.get(value)); |
| 73 | |
} |
| 74 | 0 | } |
| 75 | |
} |