1 | |
package org.kuali.rice.core.api.uif; |
2 | |
|
3 | |
import org.kuali.rice.core.api.CoreConstants; |
4 | |
import org.kuali.rice.core.api.util.jaxb.MapStringStringAdapter; |
5 | |
import org.w3c.dom.Element; |
6 | |
|
7 | |
import javax.xml.bind.annotation.XmlAccessType; |
8 | |
import javax.xml.bind.annotation.XmlAccessorType; |
9 | |
import javax.xml.bind.annotation.XmlAnyElement; |
10 | |
import javax.xml.bind.annotation.XmlElement; |
11 | |
import javax.xml.bind.annotation.XmlElementWrapper; |
12 | |
import javax.xml.bind.annotation.XmlRootElement; |
13 | |
import javax.xml.bind.annotation.XmlType; |
14 | |
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; |
15 | |
import java.util.ArrayList; |
16 | |
import java.util.Collection; |
17 | |
import java.util.Collections; |
18 | |
import java.util.HashMap; |
19 | |
import java.util.List; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
@XmlRootElement(name = RemotableSelect.Constants.ROOT_ELEMENT_NAME) |
26 | |
@XmlAccessorType(XmlAccessType.NONE) |
27 | |
@XmlType(name = RemotableSelect.Constants.TYPE_NAME, propOrder = { |
28 | |
RemotableSelect.Elements.KEY_LABELS, |
29 | |
RemotableSelect.Elements.GROUPS, |
30 | |
RemotableSelect.Elements.SIZE, |
31 | |
RemotableSelect.Elements.MULTIPLE, |
32 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS }) |
33 | 7 | public final class RemotableSelect extends RemotableAbstractControl implements Select { |
34 | |
|
35 | |
@XmlElement(name = Elements.KEY_LABELS, required = false) |
36 | |
@XmlJavaTypeAdapter(value = MapStringStringAdapter.class) |
37 | |
private final Map<String, String> keyLabels; |
38 | |
|
39 | |
@XmlElementWrapper(name = Elements.GROUPS, required = true) |
40 | |
@XmlElement(name = Elements.GROUP, required = false) |
41 | |
private final List<RemotableSelectGroup> groups; |
42 | |
|
43 | |
@XmlElement(name = Elements.SIZE, required = false) |
44 | |
private final Integer size; |
45 | |
|
46 | |
@XmlElement(name = Elements.MULTIPLE, required = false) |
47 | |
private final boolean multiple; |
48 | |
|
49 | 13 | @SuppressWarnings("unused") |
50 | |
@XmlAnyElement |
51 | |
private final Collection<Element> _futureElements = null; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@SuppressWarnings("unused") |
57 | 6 | private RemotableSelect() { |
58 | 6 | size = null; |
59 | 6 | keyLabels = null; |
60 | 6 | groups = null; |
61 | 6 | multiple = false; |
62 | 6 | } |
63 | |
|
64 | 7 | private RemotableSelect(Builder b) { |
65 | 7 | size = b.size; |
66 | 7 | keyLabels = b.keyLabels; |
67 | |
|
68 | 7 | final List<RemotableSelectGroup> temp = new ArrayList<RemotableSelectGroup>(); |
69 | 7 | for (RemotableSelectGroup.Builder attr : b.groups) { |
70 | 2 | temp.add(attr.build()); |
71 | |
} |
72 | 7 | this.groups = Collections.unmodifiableList(temp); |
73 | |
|
74 | 7 | multiple = b.multiple; |
75 | 7 | } |
76 | |
|
77 | |
@Override |
78 | |
public Map<String, String> getKeyLabels() { |
79 | 0 | return keyLabels; |
80 | |
} |
81 | |
|
82 | |
@Override |
83 | |
public Integer getSize() { |
84 | 0 | return size; |
85 | |
} |
86 | |
|
87 | |
@Override |
88 | |
public List<RemotableSelectGroup> getGroups() { |
89 | 0 | return groups; |
90 | |
} |
91 | |
|
92 | |
@Override |
93 | |
public boolean isMultiple() { |
94 | 0 | return multiple; |
95 | |
} |
96 | |
|
97 | 37 | public static final class Builder extends RemotableAbstractControl.Builder implements Select { |
98 | |
private Integer size; |
99 | 11 | private Map<String, String> keyLabels = Collections.emptyMap(); |
100 | 11 | private List<RemotableSelectGroup.Builder> groups = Collections.emptyList(); |
101 | |
private boolean multiple; |
102 | |
|
103 | 8 | private Builder(Map<String, String> keyLabels) { |
104 | 8 | setKeyLabels(keyLabels); |
105 | 8 | } |
106 | |
|
107 | 3 | private Builder(List<RemotableSelectGroup.Builder> groups) { |
108 | 3 | setGroups(groups); |
109 | 2 | } |
110 | |
|
111 | |
public static Builder create(Map<String, String> keyLabels) { |
112 | 8 | return new Builder(keyLabels); |
113 | |
} |
114 | |
|
115 | |
public static Builder create(List<RemotableSelectGroup.Builder> groups) { |
116 | 3 | return new Builder(groups); |
117 | |
} |
118 | |
|
119 | |
@Override |
120 | |
public Integer getSize() { |
121 | 0 | return size; |
122 | |
} |
123 | |
|
124 | |
public void setSize(Integer size) { |
125 | 8 | if (size != null && size < 1) { |
126 | 1 | throw new IllegalArgumentException("size was < 1"); |
127 | |
} |
128 | |
|
129 | 7 | this.size = size; |
130 | 7 | } |
131 | |
|
132 | |
@Override |
133 | |
public Map<String, String> getKeyLabels() { |
134 | 0 | return keyLabels; |
135 | |
} |
136 | |
|
137 | |
public void setKeyLabels(Map<String, String> keyLabels) { |
138 | 8 | if (keyLabels == null) { |
139 | 0 | throw new IllegalArgumentException("keyLabels was null"); |
140 | |
} |
141 | |
|
142 | 8 | this.keyLabels = Collections.unmodifiableMap(new HashMap<String, String>(keyLabels)); |
143 | 8 | } |
144 | |
|
145 | |
@Override |
146 | |
public List<RemotableSelectGroup.Builder> getGroups() { |
147 | 0 | return groups; |
148 | |
} |
149 | |
|
150 | |
public void setGroups(List<RemotableSelectGroup.Builder> groups) { |
151 | 3 | if (groups == null) { |
152 | 1 | throw new IllegalArgumentException("groups was null"); |
153 | |
} |
154 | |
|
155 | 2 | this.groups = Collections.unmodifiableList(new ArrayList<RemotableSelectGroup.Builder>(groups)); |
156 | 2 | } |
157 | |
|
158 | |
@Override |
159 | |
public boolean isMultiple() { |
160 | 0 | return multiple; |
161 | |
} |
162 | |
|
163 | |
public void setMultiple(boolean multiple) { |
164 | 2 | this.multiple = multiple; |
165 | 2 | } |
166 | |
|
167 | |
@Override |
168 | |
public RemotableSelect build() { |
169 | 9 | if (keyLabels.isEmpty() && groups.isEmpty()) { |
170 | 2 | throw new IllegalStateException("the keyLabels or groups must be set to a non-empty collection"); |
171 | |
} |
172 | |
|
173 | 7 | return new RemotableSelect(this); |
174 | |
} |
175 | |
} |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | 0 | static final class Constants { |
181 | |
static final String TYPE_NAME = "SelectType"; |
182 | |
final static String ROOT_ELEMENT_NAME = "select"; |
183 | |
} |
184 | |
|
185 | 0 | static final class Elements { |
186 | |
static final String SIZE = "size"; |
187 | |
static final String KEY_LABELS = "keyLabels"; |
188 | |
static final String GROUPS = "groups"; |
189 | |
static final String GROUP = "group"; |
190 | |
static final String MULTIPLE = "multiple"; |
191 | |
} |
192 | |
} |