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.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 @Deprecated
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 = new MultiplicityGroup(config, swappableFieldsDefinition, deletionParentKeys);
122 } else {
123 widget = config.getCustomMultiplicityGroup();
124 }
125 config.getParentFd().setFieldWidget(widget);
126 config.getParentFd().setWidgetBinding(new MultiplicityGroupBinding());
127 this.addField(config.getParentFd());
128
129 break;
130 case TABLE:
131 if (config.getFields().size() > 1) {
132 KSErrorDialog.show (new Throwable ("MultiplicityTable can have only one row defined"));
133 return;
134 }
135 if (config.getTitle() == null) {
136 layout = new TableFieldLayout();
137 }
138 else {
139 layout = new TableFieldLayout(config.getTitle(), false);
140 }
141 widget = new MultiplicityTable(config);
142 config.getParentFd().setFieldWidget(widget);
143 config.getParentFd().setWidgetBinding(new MultiplicityTableBinding());
144 this.addField(config.getParentFd());
145
146 break;
147 default:
148 layout = null;
149 }
150 }
151
152 public void setParentPath(String parentPath) {
153 if (widget instanceof MultiplicityGroup) {
154 ((MultiplicityGroup)widget).setParentPath(parentPath);
155 }
156 else {
157 ((MultiplicityTable)widget).setParentPath(parentPath);
158 }
159
160 }
161
162 @Override
163 public void resetFieldInteractionFlags() {
164 super.resetFieldInteractionFlags();
165 if (widget instanceof MultiplicityGroup){
166 ((MultiplicityGroup)widget).resetDirtyFlags();
167 }
168 }
169
170 @Override
171 public void resetDirtyFlags() {
172 super.resetDirtyFlags();
173 if (widget instanceof MultiplicityGroup){
174 ((MultiplicityGroup)widget).resetDirtyFlags();
175 }
176 }
177
178 @Override
179 public boolean isDirty() {
180 boolean isDirty = super.isDirty();
181 if (!isDirty && widget instanceof MultiplicityGroup){
182 isDirty = ((MultiplicityGroup)widget).isDirty();
183 }
184
185 return isDirty;
186 }
187
188 public MultiplicityConfiguration getConfig(){
189 return config;
190 }
191 }