1 package org.kuali.student.common.ui.client.configurable.mvc.multiplicity;
2
3 import org.kuali.student.common.assembly.data.Metadata;
4 import org.kuali.student.common.assembly.data.MetadataInterrogator;
5 import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBinding;
6 import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
7
8 public class MultiplicityFieldConfiguration {
9
10 private String fieldPath;
11 private MessageKeyInfo messageKeyInfo;
12 private Metadata metadata;
13 private MultiplicityFieldWidgetInitializer fieldWidgetInitializer;
14 @SuppressWarnings("unchecked")
15 private ModelWidgetBinding modelWidgetBinding;
16 private boolean isRequired;
17 private boolean optional = false;
18
19 public MultiplicityFieldConfiguration(
20 String fieldPath,
21 MessageKeyInfo messageKeyInfo,
22 Metadata metadata,
23 MultiplicityFieldWidgetInitializer fieldWidgetInitializer) {
24 setFieldPath(fieldPath);
25 setMessageKeyInfo(messageKeyInfo);
26 setMetadata(metadata);
27 setFieldWidgetInitializer(fieldWidgetInitializer);
28 setupField();
29 }
30
31 public String getFieldPath() {
32 return fieldPath;
33 }
34 public void setFieldPath(String fieldPath) {
35 this.fieldPath = fieldPath;
36 }
37 public MessageKeyInfo getMessageKeyInfo() {
38 return messageKeyInfo;
39 }
40 public void setMessageKeyInfo(MessageKeyInfo messageKeyInfo) {
41 this.messageKeyInfo = messageKeyInfo;
42 }
43 public Metadata getMetadata() {
44 return metadata;
45 }
46 public void setMetadata(Metadata metadata) {
47 this.metadata = metadata;
48 }
49 public MultiplicityFieldWidgetInitializer getFieldWidgetInitializer() {
50 return fieldWidgetInitializer;
51 }
52 public void setFieldWidgetInitializer(MultiplicityFieldWidgetInitializer fieldWidgetInitializer) {
53 this.fieldWidgetInitializer = fieldWidgetInitializer;
54 }
55
56 public boolean isRequired() {
57 return isRequired;
58 }
59
60 public void setRequired(boolean isRequired) {
61 this.isRequired = isRequired;
62 }
63
64 public void setModelWidgetBinding(ModelWidgetBinding modelWidgetBinding) {
65 this.modelWidgetBinding = modelWidgetBinding;
66 }
67
68 public ModelWidgetBinding getModelWidgetBinding() {
69 return modelWidgetBinding;
70 }
71
72
73
74
75
76
77
78
79 public void setOptional(boolean optional){
80 this.optional = optional;
81 }
82
83
84
85
86
87 public boolean isOptional(){
88 return optional;
89 }
90
91 protected void setupField() {
92 if(metadata != null){
93 if(MetadataInterrogator.isRequired(metadata)){
94 this.setRequired(true);
95 }
96 else if(MetadataInterrogator.isRequiredForNextState(metadata)){
97 String nextState = MetadataInterrogator.getNextState(metadata);
98 if(nextState != null){
99 this.setRequired(true);
100 }
101 } else{
102 this.setRequired(false);
103 }
104 }
105 }
106 }