1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.client.configurable.mvc.impl; |
17 | |
|
18 | |
import org.kuali.student.common.assembly.data.LookupMetadata; |
19 | |
import org.kuali.student.common.assembly.data.LookupParamMetadata; |
20 | |
import org.kuali.student.common.assembly.data.Metadata; |
21 | |
import org.kuali.student.common.assembly.data.MetadataInterrogator; |
22 | |
import org.kuali.student.common.assembly.data.Data.DataType; |
23 | |
import org.kuali.student.common.assembly.data.MetadataInterrogator.ConstraintIds; |
24 | |
import org.kuali.student.common.ui.client.configurable.mvc.DefaultWidgetFactory; |
25 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
26 | |
import org.kuali.student.common.ui.client.configurable.mvc.WidgetConfigInfo; |
27 | |
import org.kuali.student.common.ui.client.widgets.BooleanDisplayLabel; |
28 | |
import org.kuali.student.common.ui.client.widgets.KSCheckBox; |
29 | |
import org.kuali.student.common.ui.client.widgets.KSDatePicker; |
30 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
31 | |
import org.kuali.student.common.ui.client.widgets.KSPlaceholder; |
32 | |
import org.kuali.student.common.ui.client.widgets.KSRichEditor; |
33 | |
import org.kuali.student.common.ui.client.widgets.KSTextArea; |
34 | |
import org.kuali.student.common.ui.client.widgets.KSTextBox; |
35 | |
import org.kuali.student.common.ui.client.widgets.list.KSSelectedList; |
36 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
37 | |
|
38 | |
import com.google.gwt.user.client.ui.Widget; |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class DefaultWidgetFactoryImpl extends DefaultWidgetFactory { |
47 | |
|
48 | |
@Override |
49 | |
public Widget getWidget(FieldDescriptor field) { |
50 | 0 | return getWidget(field.getMetadata()); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public Widget getWidget(Metadata meta) { |
55 | 0 | WidgetConfigInfo config = new WidgetConfigInfo(); |
56 | 0 | if (meta != null) { |
57 | 0 | config.access = meta.getWriteAccess(); |
58 | 0 | config.isMultiLine = MetadataInterrogator.isMultilined(meta); |
59 | 0 | config.isRepeating = MetadataInterrogator.isRepeating(meta); |
60 | 0 | config.isRichText = MetadataInterrogator.hasConstraint(meta, ConstraintIds.RICH_TEXT); |
61 | 0 | config.maxLength = MetadataInterrogator.getSmallestMaxLength(meta); |
62 | 0 | config.type = meta.getDataType(); |
63 | 0 | config.metadata = meta; |
64 | 0 | config.lookupMeta = meta.getInitialLookup(); |
65 | 0 | config.additionalLookups = meta.getAdditionalLookups(); |
66 | 0 | config.canEdit = meta.isCanEdit(); |
67 | 0 | config.canUnmask = meta.isCanUnmask(); |
68 | 0 | config.canView = meta.isCanView(); |
69 | |
} |
70 | 0 | return _getWidget(config); |
71 | |
} |
72 | |
|
73 | |
@Override |
74 | |
public Widget getReadOnlyWidget(Metadata meta){ |
75 | 0 | WidgetConfigInfo config = new WidgetConfigInfo(); |
76 | 0 | if (meta != null) { |
77 | 0 | config.access = meta.getWriteAccess(); |
78 | 0 | config.isMultiLine = MetadataInterrogator.isMultilined(meta); |
79 | 0 | config.isRepeating = MetadataInterrogator.isRepeating(meta); |
80 | 0 | config.isRichText = MetadataInterrogator.hasConstraint(meta, ConstraintIds.RICH_TEXT); |
81 | 0 | config.maxLength = MetadataInterrogator.getSmallestMaxLength(meta); |
82 | 0 | config.type = meta.getDataType(); |
83 | 0 | config.metadata = meta; |
84 | 0 | config.lookupMeta = meta.getInitialLookup(); |
85 | 0 | config.additionalLookups = meta.getAdditionalLookups(); |
86 | 0 | config.canEdit = false; |
87 | 0 | config.canUnmask = meta.isCanUnmask(); |
88 | 0 | config.canView = meta.isCanView(); |
89 | |
} |
90 | 0 | return _getWidget(config); |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public Widget getWidget(LookupParamMetadata meta) { |
95 | 0 | WidgetConfigInfo config = new WidgetConfigInfo(); |
96 | 0 | if (meta != null) { |
97 | 0 | config.access = meta.getWriteAccess(); |
98 | 0 | config.type = meta.getDataType(); |
99 | 0 | config.lookupMeta = meta.getChildLookup(); |
100 | |
} |
101 | 0 | return _getWidget(config); |
102 | |
} |
103 | |
|
104 | |
private Widget _getWidget(WidgetConfigInfo config) { |
105 | 0 | Widget result = null; |
106 | 0 | if(!config.canView) { |
107 | 0 | result = new KSPlaceholder(); |
108 | 0 | result.setVisible(config.canView); |
109 | 0 | } else if(!config.canEdit && (config.lookupMeta == null || config.lookupMeta.getWidget() == null)) { |
110 | 0 | if(config.type == DataType.BOOLEAN){ |
111 | 0 | result = new BooleanDisplayLabel(); |
112 | |
} |
113 | |
else{ |
114 | 0 | result = new KSLabel(); |
115 | |
} |
116 | |
} else { |
117 | 0 | if (config.lookupMeta != null && config.lookupMeta.getWidget() != null) { |
118 | |
|
119 | 0 | if (config.metadata != null && MetadataInterrogator.isRepeating(config.metadata) && !LookupMetadata.Widget.CHECKBOX_LIST.equals(config.lookupMeta.getWidget())) { |
120 | 0 | result = new KSSelectedList(config); |
121 | |
} else { |
122 | 0 | result = new KSPicker(config); |
123 | |
} |
124 | |
} else { |
125 | 0 | switch (config.type) { |
126 | |
case BOOLEAN: |
127 | 0 | result = new KSCheckBox(); |
128 | 0 | break; |
129 | |
|
130 | |
case DATE: |
131 | |
|
132 | |
|
133 | |
case TRUNCATED_DATE: |
134 | 0 | result = new KSDatePicker(); |
135 | 0 | break; |
136 | |
|
137 | |
case DATA: |
138 | 0 | if (config.isRichText) { |
139 | 0 | result = new KSRichEditor(); |
140 | 0 | break; |
141 | |
} |
142 | |
default: |
143 | 0 | if (config.isMultiLine) { |
144 | 0 | result = new KSTextArea(); |
145 | 0 | result.addStyleName("ks-textarea-width"); |
146 | 0 | if(config.maxLength != null){ |
147 | 0 | ((KSTextArea)(result)).setMaxLength(config.maxLength); |
148 | 0 | if(config.maxLength < 250){ |
149 | 0 | result.addStyleName("ks-textarea-small-height"); |
150 | |
} |
151 | 0 | else if(config.maxLength < 500){ |
152 | 0 | result.addStyleName("ks-textarea-medium-height"); |
153 | |
} |
154 | |
else{ |
155 | 0 | result.addStyleName("ks-textarea-large-height"); |
156 | |
} |
157 | |
} |
158 | |
else{ |
159 | 0 | result.addStyleName("ks-textarea-medium-height"); |
160 | |
} |
161 | |
} else { |
162 | 0 | KSTextBox text = new KSTextBox(); |
163 | |
|
164 | 0 | if (config.maxLength != null) { |
165 | 0 | text.setMaxLength(config.maxLength); |
166 | 0 | if(config.maxLength < 5 ){ |
167 | 0 | switch(config.maxLength){ |
168 | |
case 1: |
169 | 0 | text.addStyleName("ks-one-width"); |
170 | 0 | break; |
171 | |
case 2: |
172 | 0 | text.addStyleName("ks-two-width"); |
173 | 0 | break; |
174 | |
case 3: |
175 | 0 | text.addStyleName("ks-three-width"); |
176 | 0 | break; |
177 | |
case 4: |
178 | 0 | text.addStyleName("ks-four-width"); |
179 | 0 | break; |
180 | |
} |
181 | |
} |
182 | 0 | else if(config.maxLength < 23){ |
183 | 0 | text.addStyleName("ks-small-width"); |
184 | |
} |
185 | 0 | else if(config.maxLength < 35){ |
186 | 0 | text.addStyleName("ks-medium-width"); |
187 | |
} |
188 | 0 | else if(config.maxLength < 60){ |
189 | 0 | text.addStyleName("ks-large-width"); |
190 | |
} |
191 | |
else{ |
192 | 0 | text.addStyleName("ks-extra-large-width"); |
193 | |
} |
194 | |
} |
195 | |
else{ |
196 | 0 | text.addStyleName("ks-medium-width"); |
197 | |
} |
198 | |
|
199 | 0 | result = text; |
200 | |
} |
201 | |
} |
202 | |
} |
203 | |
} |
204 | 0 | return result; |
205 | |
} |
206 | |
} |