| 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; |
| 17 | |
|
| 18 | |
|
| 19 | |
import org.kuali.student.common.assembly.data.Metadata; |
| 20 | |
import org.kuali.student.common.assembly.data.MetadataInterrogator; |
| 21 | |
import org.kuali.student.common.ui.client.application.Application; |
| 22 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding; |
| 23 | |
import org.kuali.student.common.ui.client.configurable.mvc.binding.MultiplicityCompositeBinding; |
| 24 | |
import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityComposite; |
| 25 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
| 26 | |
import org.kuali.student.common.ui.client.mvc.HasCrossConstraints; |
| 27 | |
import org.kuali.student.common.ui.client.mvc.HasDataValue; |
| 28 | |
import org.kuali.student.common.ui.client.widgets.KSCheckBox; |
| 29 | |
import org.kuali.student.common.ui.client.widgets.KSTextBox; |
| 30 | |
import org.kuali.student.common.ui.client.widgets.RichTextEditor; |
| 31 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.FieldElement; |
| 32 | |
import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo; |
| 33 | |
import org.kuali.student.common.ui.client.widgets.list.KSSelectItemWidgetAbstract; |
| 34 | |
|
| 35 | |
import com.google.gwt.user.client.ui.HasText; |
| 36 | |
import com.google.gwt.user.client.ui.HasValue; |
| 37 | |
import com.google.gwt.user.client.ui.Widget; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
public class FieldDescriptor { |
| 94 | |
protected String fieldKey; |
| 95 | |
protected Metadata metadata; |
| 96 | |
@SuppressWarnings("unchecked") |
| 97 | |
private ModelWidgetBinding modelWidgetBinding; |
| 98 | |
private Callback<Boolean> validationRequestCallback; |
| 99 | 0 | private boolean dirty = false; |
| 100 | 0 | private boolean hasHadFocus = false; |
| 101 | |
private final FieldElement fieldElement; |
| 102 | |
private String modelId; |
| 103 | |
private MessageKeyInfo messageKey; |
| 104 | 0 | private boolean optional = false; |
| 105 | 0 | private boolean ignoreShowRequired = false; |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | 0 | public FieldDescriptor(String fieldKey, MessageKeyInfo messageKey, Metadata metadata) { |
| 114 | 0 | this.fieldKey = fieldKey; |
| 115 | 0 | this.metadata = metadata; |
| 116 | 0 | if(messageKey == null){ |
| 117 | 0 | messageKey = new MessageKeyInfo(""); |
| 118 | |
} |
| 119 | 0 | setMessageKey(messageKey); |
| 120 | 0 | fieldElement = new FieldElement(fieldKey, messageKey, createFieldWidget(), metadata); |
| 121 | 0 | setupField(); |
| 122 | |
|
| 123 | |
|
| 124 | 0 | if((getFieldWidget() instanceof HasDataValue || getFieldWidget() instanceof KSTextBox || getFieldWidget() instanceof HasValue)&&!(this instanceof FieldDescriptorReadOnly)){ |
| 125 | 0 | Application.getApplicationContext().putPathToFieldMapping(null, Application.getApplicationContext().getParentPath()+fieldKey, this); |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | 0 | if(fieldElement.getFieldWidget() instanceof HasCrossConstraints){ |
| 130 | 0 | HasCrossConstraints crossConstraintWidget = (HasCrossConstraints) fieldElement.getFieldWidget(); |
| 131 | 0 | if(crossConstraintWidget!=null&&crossConstraintWidget.getCrossConstraints()!=null){ |
| 132 | 0 | for(String path:crossConstraintWidget.getCrossConstraints()){ |
| 133 | 0 | Application.getApplicationContext().putCrossConstraint(null, path, crossConstraintWidget); |
| 134 | |
} |
| 135 | |
} |
| 136 | |
} |
| 137 | 0 | } |
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
|
| 145 | |
|
| 146 | 0 | public FieldDescriptor(String fieldKey, MessageKeyInfo messageKey, Metadata metadata, Widget fieldWidget){ |
| 147 | 0 | this.fieldKey = fieldKey; |
| 148 | 0 | this.metadata = metadata; |
| 149 | 0 | if(messageKey == null){ |
| 150 | 0 | messageKey = new MessageKeyInfo(""); |
| 151 | |
} |
| 152 | 0 | setMessageKey(messageKey); |
| 153 | 0 | addStyleToWidget(fieldWidget); |
| 154 | 0 | fieldElement = new FieldElement(fieldKey, messageKey, fieldWidget, metadata); |
| 155 | 0 | setupField(); |
| 156 | |
|
| 157 | |
|
| 158 | 0 | if((fieldWidget instanceof HasDataValue || fieldWidget instanceof KSTextBox) &&!(this instanceof FieldDescriptorReadOnly)){ |
| 159 | 0 | Application.getApplicationContext().putPathToFieldMapping(null, Application.getApplicationContext().getParentPath()+fieldKey, this); |
| 160 | |
} |
| 161 | |
|
| 162 | |
|
| 163 | 0 | if(fieldElement.getFieldWidget() instanceof HasCrossConstraints){ |
| 164 | 0 | HasCrossConstraints crossConstraintWidget = (HasCrossConstraints) fieldElement.getFieldWidget(); |
| 165 | 0 | if(crossConstraintWidget!=null&&crossConstraintWidget.getCrossConstraints()!=null){ |
| 166 | 0 | for(String path:crossConstraintWidget.getCrossConstraints()){ |
| 167 | 0 | Application.getApplicationContext().putCrossConstraint(null, path, crossConstraintWidget); |
| 168 | |
} |
| 169 | |
} |
| 170 | |
} |
| 171 | |
|
| 172 | 0 | } |
| 173 | |
|
| 174 | |
protected void addStyleToWidget(Widget w){ |
| 175 | 0 | if(fieldKey != null && !fieldKey.isEmpty() && w != null){ |
| 176 | 0 | String style = this.fieldKey.replaceAll("/", "-"); |
| 177 | 0 | w.addStyleName(style); |
| 178 | |
} |
| 179 | 0 | } |
| 180 | |
|
| 181 | |
protected void setupField() { |
| 182 | 0 | if(metadata != null){ |
| 183 | 0 | if(MetadataInterrogator.isRequired(metadata)){ |
| 184 | 0 | fieldElement.setRequiredString("requiredMarker", "ks-form-module-elements-required"); |
| 185 | |
} |
| 186 | 0 | else if(MetadataInterrogator.isRequiredForNextState(metadata)){ |
| 187 | 0 | String nextState = MetadataInterrogator.getNextState(metadata); |
| 188 | 0 | if(nextState != null){ |
| 189 | 0 | if(nextState.equalsIgnoreCase("SUBMITTED")){ |
| 190 | 0 | fieldElement.setRequiredString("requiredOnSubmit", "ks-form-required-for-submit"); |
| 191 | |
} |
| 192 | 0 | else if(nextState.equalsIgnoreCase("APPROVED")){ |
| 193 | 0 | fieldElement.setRequiredString("reqApproval", "ks-form-required-for-submit"); |
| 194 | |
} |
| 195 | 0 | else if(nextState.equalsIgnoreCase("ACTIVE")){ |
| 196 | 0 | fieldElement.setRequiredString("reqActivate", "ks-form-required-for-submit"); |
| 197 | |
} |
| 198 | 0 | else if(nextState.equalsIgnoreCase("SUSPENDED") || |
| 199 | |
nextState.equalsIgnoreCase("RETIRED")){ |
| 200 | 0 | fieldElement.setRequiredString("reqDeactivate", "ks-form-required-for-submit"); |
| 201 | |
} |
| 202 | |
else { |
| 203 | 0 | fieldElement.setRequiredString("requiredOnSubmit", "ks-form-required-for-submit"); |
| 204 | |
} |
| 205 | |
|
| 206 | |
} |
| 207 | 0 | } else{ |
| 208 | 0 | fieldElement.clearRequiredText(); |
| 209 | |
} |
| 210 | |
} |
| 211 | 0 | } |
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
public void hideLabel(){ |
| 217 | 0 | fieldElement.hideLabel(); |
| 218 | 0 | } |
| 219 | |
|
| 220 | |
public boolean isLabelShown(){ |
| 221 | 0 | return fieldElement.isLabelShown(); |
| 222 | |
} |
| 223 | |
|
| 224 | |
public FieldElement getFieldElement(){ |
| 225 | 0 | return fieldElement; |
| 226 | |
} |
| 227 | |
|
| 228 | |
public String getFieldKey() { |
| 229 | 0 | return fieldKey; |
| 230 | |
} |
| 231 | |
|
| 232 | |
public void setFieldKey(String fieldKey) { |
| 233 | 0 | this.fieldKey = fieldKey; |
| 234 | 0 | } |
| 235 | |
|
| 236 | |
public String getFieldLabel() { |
| 237 | 0 | return fieldElement.getFieldName(); |
| 238 | |
} |
| 239 | |
|
| 240 | |
public Widget getFieldWidget(){ |
| 241 | 0 | if (fieldElement.getFieldWidget() == null){ |
| 242 | 0 | Widget w = createFieldWidget(); |
| 243 | 0 | fieldElement.setWidget(w); |
| 244 | |
} |
| 245 | 0 | return fieldElement.getFieldWidget(); |
| 246 | |
} |
| 247 | |
|
| 248 | |
protected Widget createFieldWidget() { |
| 249 | 0 | if (metadata == null) { |
| 250 | |
|
| 251 | |
|
| 252 | 0 | Widget result = new KSTextBox(); |
| 253 | 0 | addStyleToWidget(result); |
| 254 | 0 | return result; |
| 255 | |
} else { |
| 256 | 0 | Widget result = DefaultWidgetFactory.getInstance().getWidget(this); |
| 257 | 0 | addStyleToWidget(result); |
| 258 | 0 | return result; |
| 259 | |
} |
| 260 | |
} |
| 261 | |
|
| 262 | |
public ModelWidgetBinding<?> getModelWidgetBinding() { |
| 263 | 0 | if(modelWidgetBinding == null){ |
| 264 | 0 | if(fieldElement.getFieldWidget() instanceof RichTextEditor){ |
| 265 | 0 | modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.RichTextBinding.INSTANCE; |
| 266 | 0 | } else if (fieldElement.getFieldWidget() instanceof KSCheckBox){ |
| 267 | 0 | modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.HasValueBinding.INSTANCE; |
| 268 | 0 | } else if(fieldElement.getFieldWidget() instanceof MultiplicityComposite){ |
| 269 | 0 | modelWidgetBinding = MultiplicityCompositeBinding.INSTANCE; |
| 270 | 0 | } else if (fieldElement.getFieldWidget()instanceof HasText) { |
| 271 | 0 | modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.HasTextBinding.INSTANCE; |
| 272 | 0 | } else if (fieldElement.getFieldWidget() instanceof KSSelectItemWidgetAbstract){ |
| 273 | 0 | modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.SelectItemWidgetBinding.INSTANCE; |
| 274 | 0 | } else if (fieldElement.getFieldWidget() instanceof HasDataValue){ |
| 275 | 0 | modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.HasDataValueBinding.INSTANCE; |
| 276 | 0 | } else if (fieldElement.getFieldWidget() instanceof HasValue){ |
| 277 | 0 | modelWidgetBinding = org.kuali.student.common.ui.client.configurable.mvc.binding.HasValueBinding.INSTANCE; |
| 278 | |
} |
| 279 | |
} |
| 280 | 0 | return modelWidgetBinding; |
| 281 | |
} |
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
|
| 287 | |
|
| 288 | |
public void setValidationCallBack(Callback<Boolean> callback){ |
| 289 | 0 | validationRequestCallback = callback; |
| 290 | 0 | } |
| 291 | |
|
| 292 | |
public Callback<Boolean> getValidationRequestCallback(){ |
| 293 | 0 | return validationRequestCallback; |
| 294 | |
} |
| 295 | |
|
| 296 | |
|
| 297 | |
|
| 298 | |
|
| 299 | |
|
| 300 | |
|
| 301 | |
public boolean isDirty() { |
| 302 | 0 | return dirty; |
| 303 | |
} |
| 304 | |
|
| 305 | |
public void setDirty(boolean dirty) { |
| 306 | 0 | this.dirty = dirty; |
| 307 | 0 | } |
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
|
| 312 | |
|
| 313 | |
public boolean hasHadFocus() { |
| 314 | 0 | return hasHadFocus; |
| 315 | |
} |
| 316 | |
|
| 317 | |
public void setHasHadFocus(boolean hasHadFocus) { |
| 318 | 0 | this.hasHadFocus = hasHadFocus; |
| 319 | 0 | } |
| 320 | |
|
| 321 | |
public Metadata getMetadata() { |
| 322 | 0 | return metadata; |
| 323 | |
} |
| 324 | |
|
| 325 | |
public void setMetadata(Metadata metadata) { |
| 326 | 0 | this.metadata = metadata; |
| 327 | 0 | setupField(); |
| 328 | 0 | } |
| 329 | |
|
| 330 | |
public void setFieldWidget(Widget fieldWidget) { |
| 331 | 0 | this.fieldElement.setWidget(fieldWidget); |
| 332 | 0 | } |
| 333 | |
|
| 334 | |
public String getModelId() { |
| 335 | 0 | return modelId; |
| 336 | |
} |
| 337 | |
|
| 338 | |
public void setModelId(String modelId) { |
| 339 | 0 | this.modelId = modelId; |
| 340 | 0 | } |
| 341 | |
|
| 342 | |
|
| 343 | |
|
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
public void setWidgetBinding(ModelWidgetBinding widgetBinding) { |
| 349 | 0 | this.modelWidgetBinding = widgetBinding; |
| 350 | 0 | } |
| 351 | |
|
| 352 | |
public MessageKeyInfo getMessageKey() { |
| 353 | 0 | return messageKey; |
| 354 | |
} |
| 355 | |
|
| 356 | |
public void setMessageKey(MessageKeyInfo messageKey) { |
| 357 | 0 | this.messageKey = messageKey; |
| 358 | 0 | } |
| 359 | |
|
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
public void setOptional(boolean optional){ |
| 367 | 0 | this.optional = optional; |
| 368 | 0 | } |
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
|
| 373 | |
|
| 374 | |
public boolean isOptional(){ |
| 375 | 0 | return optional; |
| 376 | |
} |
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
public boolean isVisible() { |
| 382 | 0 | if (metadata != null){ |
| 383 | 0 | return metadata.isCanView(); |
| 384 | |
} else { |
| 385 | 0 | return true; |
| 386 | |
} |
| 387 | |
} |
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
public void setRequired(Boolean isRequired){ |
| 395 | 0 | fieldElement.setRequiredString("requiredMarker", "ks-form-module-elements-required"); |
| 396 | 0 | fieldElement.setRequired(isRequired); |
| 397 | |
|
| 398 | |
|
| 399 | 0 | if (isRequired){ |
| 400 | 0 | getMetadata().getConstraints().get(0).setMinOccurs(1); |
| 401 | |
} else { |
| 402 | 0 | getMetadata().getConstraints().get(0).setMinOccurs(0); |
| 403 | |
} |
| 404 | 0 | } |
| 405 | |
|
| 406 | |
public boolean isIgnoreShowRequired() { |
| 407 | 0 | return ignoreShowRequired; |
| 408 | |
} |
| 409 | |
|
| 410 | |
public void setIgnoreShowRequired(boolean ignoreShowRequired) { |
| 411 | 0 | this.ignoreShowRequired = ignoreShowRequired; |
| 412 | 0 | } |
| 413 | |
|
| 414 | |
} |