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.Iterator;
23 import java.util.List;
24
25 import org.universAAL.middleware.owl.MergedRestriction;
26 import org.universAAL.middleware.rdf.PropertyPath;
27
28
29
30
31
32
33
34
35 public abstract class Input extends FormControl {
36 public static final String MY_URI = Form.uAAL_DIALOG_NAMESPACE + "Input";
37
38
39
40
41
42
43 public static final String PROP_INPUT_ALERT = Form.uAAL_DIALOG_NAMESPACE
44 + "inputAlert";
45
46
47
48
49
50
51 public static final String PROP_IS_MANDATORY = Form.uAAL_DIALOG_NAMESPACE
52 + "isMandatory";
53
54 protected Input() {
55 super();
56 }
57
58 protected Input(String typeURI, Group parent, Label label,
59 PropertyPath ref, MergedRestriction valueRestriction,
60 Object initialValue) {
61 super(typeURI, parent, label, ref, valueRestriction, initialValue);
62 if (parent instanceof Repeat)
63 return;
64 if (ref == null)
65 throw new IllegalArgumentException(
66 "The property path for input controls must be not null!");
67 }
68
69 boolean checkSubmission() {
70 Repeat r = getAncestorRepeat();
71 if (r != null) {
72 if (isMandatory()) {
73 List values = r.getAllValues(getReferencedPPath());
74 if (values != null)
75 for (Iterator i = values.iterator(); i.hasNext();)
76 if (i.next() == null)
77 return false;
78 }
79 return r.checkSubmission();
80 }
81
82 Object o = getValue();
83 if (o == null)
84 return !isMandatory();
85
86 return !(o instanceof List) || this.getClass() == Select.class;
87 }
88
89
90
91
92 public String getAlertString() {
93 return (String) props.get(PROP_INPUT_ALERT);
94 }
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 public boolean isMandatory() {
110 return Boolean.TRUE.equals(props.get(PROP_IS_MANDATORY));
111 }
112
113
114
115
116 public void setAlertString(String value) {
117 if (value != null && !props.containsKey(PROP_INPUT_ALERT))
118 props.put(PROP_INPUT_ALERT, value);
119 }
120
121 void setMandatory() {
122 props.put(PROP_IS_MANDATORY, Boolean.TRUE);
123 }
124
125
126
127
128 public boolean setProperty(String propURI, Object value) {
129 if (PROP_INPUT_ALERT.equals(propURI)) {
130 if (value instanceof String && !props.containsKey(propURI)) {
131 props.put(propURI, value);
132 return true;
133 }
134 return false;
135 } else
136 return super.setProperty(propURI, value);
137 }
138
139
140
141
142
143 public boolean storeUserInput(Object value) {
144 if (isMandatory() && value == null)
145 return false;
146
147 Group g = getParentGroup();
148 if (g == null)
149 return false;
150
151 PropertyPath pp = getReferencedPPath();
152 return g.setValue((pp == null ? null : pp.getThePath()), value,
153 getLocalRestrictions());
154 }
155 }