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