1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.universAAL.middleware.ui.rdf;
21
22 import java.util.ArrayList;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.List;
26 import java.util.Set;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public class Submit extends FormControl {
43 public static final String MY_URI = Form.uAAL_DIALOG_NAMESPACE + "Submit";
44
45
46
47
48
49
50
51
52 public static final int CONFIRMATION_TYPE_OK_CANCEL = 0;
53
54
55
56
57
58
59
60
61 public static final int CONFIRMATION_TYPE_YES_NO = 1;
62
63
64
65
66
67
68
69
70 public static final String PROP_CONFIRMATION_MESSAGE = uAAL_VOCABULARY_NAMESPACE
71 + "confirmationMessage";
72
73
74
75
76
77
78
79
80 public static final String PROP_CONFIRMATION_TYPE = uAAL_VOCABULARY_NAMESPACE
81 + "confirmationType";
82
83
84
85
86
87
88 public static final String PROP_MANDATORY_INPUT = uAAL_VOCABULARY_NAMESPACE
89 + "mandatoryInput";
90
91
92
93
94
95 public static final String PROP_SUBMISSION_ID = uAAL_VOCABULARY_NAMESPACE
96 + "submissionID";
97
98
99
100
101 protected List mandatoryList = null;
102
103
104
105
106 public Submit() {
107 super();
108 mandatoryList = new ArrayList();
109 props.put(PROP_MANDATORY_INPUT, mandatoryList);
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123
124 public Submit(Group parent, Label label, String id) {
125 super(MY_URI, parent, label, null, null, null);
126 props.put(PROP_SUBMISSION_ID, id);
127 mandatoryList = new ArrayList();
128 props.put(PROP_MANDATORY_INPUT, mandatoryList);
129 }
130
131 protected Submit(String typeURI, Group parent, Label label, String id) {
132 super(typeURI, parent, label, null, null, null);
133 props.put(PROP_SUBMISSION_ID, id);
134 mandatoryList = new ArrayList();
135 props.put(PROP_MANDATORY_INPUT, mandatoryList);
136 }
137
138
139
140
141
142
143 public void addMandatoryInput(Input in) {
144 if (in != null) {
145 mandatoryList.add(in);
146 in.setMandatory();
147 }
148 }
149
150
151
152
153 public String getConfirmationMessage() {
154 return (String) props.get(PROP_CONFIRMATION_MESSAGE);
155 }
156
157
158
159
160 public int getConfirmationType() {
161 Object o = props.get(PROP_CONFIRMATION_TYPE);
162 return (o instanceof Integer) ? ((Integer) o).intValue() : -1;
163 }
164
165
166
167
168
169
170 public String getDialogID() {
171 Form f = getFormObject();
172 if (f == null)
173 return null;
174
175 Group stdButtons = f.getStandardButtons();
176 if (stdButtons != null) {
177 Group parent = getParentGroup();
178 while (parent != null && parent != stdButtons)
179 parent = parent.getParentGroup();
180 if (parent == stdButtons)
181 return f.getStandardButtonsDialogID();
182 }
183
184 return f.getDialogID();
185 }
186
187
188
189
190 public String getID() {
191 return (String) props.get(PROP_SUBMISSION_ID);
192 }
193
194
195
196
197
198 public int getMaxLength() {
199 Label l = getLabel();
200 return (l == null) ? -1 : l.getMaxLength();
201 }
202
203
204
205
206 public Input[] getMandatoryInputControls() {
207 if (mandatoryList == null || mandatoryList.isEmpty())
208 return new Input[0];
209
210 return (Input[]) mandatoryList.toArray(new Input[mandatoryList.size()]);
211 }
212
213
214
215
216
217
218
219
220
221 public Input getMissingInputControl() {
222 if (mandatoryList == null)
223 return null;
224
225 for (Iterator i = mandatoryList.iterator(); i.hasNext();) {
226 Input in = (Input) i.next();
227 if (!in.checkSubmission())
228 return in;
229 }
230 return null;
231 }
232
233
234
235
236
237 public Set getMissingInputControls() {
238 if (mandatoryList == null)
239 return null;
240 HashSet inputs = new HashSet();
241 for (Iterator i = mandatoryList.iterator(); i.hasNext();) {
242 Input in = (Input) i.next();
243 if (!in.checkSubmission())
244 inputs.add(in);
245 }
246 return inputs;
247 }
248
249
250
251
252
253
254
255
256
257
258
259
260
261 public FormControl[] getRelatedControls() {
262 if (mandatoryList == null || mandatoryList.isEmpty())
263 return new FormControl[0];
264
265
266 Group[] superGroups = ((Input) mandatoryList.get(0)).getSuperGroups();
267 int lcpIndex = superGroups.length - 1;
268 for (int i = 1; i < mandatoryList.size(); i++) {
269 FormControl fc = (FormControl) mandatoryList.get(i);
270 while (fc != null) {
271 fc = fc.getParentGroup();
272 for (int j = 0; j < lcpIndex; j++)
273 if (fc == superGroups[j]) {
274 lcpIndex = j;
275 break;
276 }
277 }
278 if (lcpIndex == 0)
279 break;
280 }
281
282 return superGroups[lcpIndex].getSubtree(this);
283 }
284
285
286
287
288
289 public boolean hasMandatoryInput(Input fc) {
290 return mandatoryList != null && mandatoryList.contains(fc);
291 }
292
293
294
295
296
297
298 public void setConfirmationOkCancel(String msg) {
299 if (msg != null) {
300 props.put(PROP_CONFIRMATION_MESSAGE, msg);
301 props.put(PROP_CONFIRMATION_TYPE, new Integer(
302 CONFIRMATION_TYPE_OK_CANCEL));
303 }
304 }
305
306
307
308
309
310
311 public void setConfirmationYesNo(String msg) {
312 if (msg != null) {
313 props.put(PROP_CONFIRMATION_MESSAGE, msg);
314 props.put(PROP_CONFIRMATION_TYPE, new Integer(
315 CONFIRMATION_TYPE_YES_NO));
316 }
317 }
318
319
320
321
322 public boolean setProperty(String propURI, Object value) {
323 if (PROP_MANDATORY_INPUT.equals(propURI)) {
324 if (mandatoryList.isEmpty()) {
325 if (value instanceof List) {
326 boolean retVal = false;
327 for (Iterator i = ((List) value).iterator(); i.hasNext();) {
328 value = i.next();
329 if (!(value instanceof Input)) {
330 mandatoryList.clear();
331 return false;
332 } else
333 retVal = mandatoryList.add(value) || retVal;
334 }
335 return retVal;
336 } else if (value instanceof Input)
337 return mandatoryList.add(value);
338 else
339 return false;
340 }
341 } else if (PROP_SUBMISSION_ID.equals(propURI)) {
342 if (value instanceof String && !"".equals(value)) {
343 props.put(propURI, value);
344 return true;
345 }
346 } else if (PROP_CONFIRMATION_MESSAGE.equals(propURI)) {
347 if (value instanceof String && !"".equals(value)) {
348 props.put(propURI, value);
349 return true;
350 }
351 } else if (PROP_CONFIRMATION_TYPE.equals(propURI)) {
352 if (value instanceof Integer) {
353 props.put(propURI, value);
354 return true;
355 }
356 } else
357 return super.setProperty(propURI, value);
358 return false;
359 }
360 }