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