1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.kuali.student.common.ui.client.configurable.mvc.sections;
21
22 import java.util.List;
23 import java.util.Map;
24
25 import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor;
26 import org.kuali.student.common.ui.client.configurable.mvc.binding.MultiplicityGroupBinding;
27 import org.kuali.student.common.ui.client.configurable.mvc.binding.MultiplicityTableBinding;
28 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityConfiguration;
29 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityGroup;
30 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityTable;
31 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.SwapCompositeCondition;
32 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.SwapCompositeConditionFieldConfig;
33 import org.kuali.student.common.ui.client.widgets.KSErrorDialog;
34 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.TableFieldLayout;
35 import org.kuali.student.common.ui.client.widgets.field.layout.layouts.VerticalFieldLayout;
36
37 import com.google.gwt.core.client.GWT;
38 import com.google.gwt.user.client.ui.Widget;
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 public class MultiplicitySection extends BaseSection {
77
78 private MultiplicityConfiguration config;
79 private Widget widget;
80 private Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition;
81 private List<String> deletionParentKeys;
82 public MultiplicitySection(MultiplicityConfiguration config) {
83 this.config = config;
84 initialize();
85 }
86
87 public MultiplicitySection(
88 MultiplicityConfiguration config,
89 Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition,
90 List<String> deletionParentKeys) {
91 this.config = config;
92 this.swappableFieldsDefinition = swappableFieldsDefinition;
93 this.deletionParentKeys = deletionParentKeys;
94 initialize();
95 }
96
97
98 private void initialize() {
99 buildLayout();
100 this.add(layout);
101 }
102
103
104
105
106
107
108
109
110
111 private void buildLayout() {
112
113 if (config.getParentFd() == null) {
114 KSErrorDialog.show (new Throwable ("Multiplicity Parent FD cannot be null"));
115 return;
116 }
117 switch (config.getLayoutType()) {
118 case GROUP:
119 layout = new VerticalFieldLayout(config.getTitle());
120 if (config.getCustomMultiplicityGroup() == null) {
121 widget = GWT.create(MultiplicityGroup.class);
122 ((MultiplicityGroup) widget).init(config, swappableFieldsDefinition, deletionParentKeys);
123 } else {
124 widget = config.getCustomMultiplicityGroup();
125 }
126 config.getParentFd().setFieldWidget(widget);
127 config.getParentFd().setWidgetBinding(new MultiplicityGroupBinding());
128 this.addField(config.getParentFd());
129
130 break;
131 case TABLE:
132 if (config.getFields().size() > 1) {
133 KSErrorDialog.show (new Throwable ("MultiplicityTable can have only one row defined"));
134 return;
135 }
136 if (config.getTitle() == null) {
137 layout = new TableFieldLayout();
138 }
139 else {
140 layout = new TableFieldLayout(config.getTitle(), false);
141 }
142 widget = new MultiplicityTable(config);
143 config.getParentFd().setFieldWidget(widget);
144 config.getParentFd().setWidgetBinding(new MultiplicityTableBinding());
145 this.addField(config.getParentFd());
146
147 break;
148 default:
149 layout = null;
150 }
151 }
152
153 public void setParentPath(String parentPath) {
154 if (widget instanceof MultiplicityGroup) {
155 ((MultiplicityGroup)widget).setParentPath(parentPath);
156 }
157 else {
158 ((MultiplicityTable)widget).setParentPath(parentPath);
159 }
160
161 }
162
163 @Override
164 public void resetFieldInteractionFlags() {
165 super.resetFieldInteractionFlags();
166 if (widget instanceof MultiplicityGroup){
167 ((MultiplicityGroup)widget).resetDirtyFlags();
168 }
169 }
170
171 @Override
172 public void resetDirtyFlags() {
173 super.resetDirtyFlags();
174 if (widget instanceof MultiplicityGroup){
175 ((MultiplicityGroup)widget).resetDirtyFlags();
176 }
177 }
178
179 @Override
180 public boolean isDirty() {
181 boolean isDirty = super.isDirty();
182 if (!isDirty && widget instanceof MultiplicityGroup){
183 isDirty = ((MultiplicityGroup)widget).isDirty();
184 }
185
186 return isDirty;
187 }
188
189 public MultiplicityConfiguration getConfig(){
190 return config;
191 }
192 }