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 public class MultiplicitySection extends BaseSection {
76
77 private MultiplicityConfiguration config;
78 private Widget widget;
79 private Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition;
80 private List<String> deletionParentKeys;
81 public MultiplicitySection(MultiplicityConfiguration config) {
82 this.config = config;
83 initialize();
84 }
85
86 public MultiplicitySection(
87 MultiplicityConfiguration config,
88 Map<SwapCompositeCondition, List<SwapCompositeConditionFieldConfig>> swappableFieldsDefinition,
89 List<String> deletionParentKeys) {
90 this.config = config;
91 this.swappableFieldsDefinition = swappableFieldsDefinition;
92 this.deletionParentKeys = deletionParentKeys;
93 initialize();
94 }
95
96
97 private void initialize() {
98 buildLayout();
99 this.add(layout);
100 }
101
102
103
104
105
106
107
108
109
110 private void buildLayout() {
111
112 if (config.getParentFd() == null) {
113 KSErrorDialog.show (new Throwable ("Multiplicity Parent FD cannot be null"));
114 return;
115 }
116 switch (config.getLayoutType()) {
117 case GROUP:
118 layout = new VerticalFieldLayout(config.getTitle());
119 if (config.getCustomMultiplicityGroup() == null) {
120 widget = new MultiplicityGroup(config, swappableFieldsDefinition, deletionParentKeys);
121 } else {
122 widget = config.getCustomMultiplicityGroup();
123 }
124 config.getParentFd().setFieldWidget(widget);
125 config.getParentFd().setWidgetBinding(new MultiplicityGroupBinding());
126 this.addField(config.getParentFd());
127
128 break;
129 case TABLE:
130 if (config.getFields().size() > 1) {
131 KSErrorDialog.show (new Throwable ("MultiplicityTable can have only one row defined"));
132 return;
133 }
134 if (config.getTitle() == null) {
135 layout = new TableFieldLayout();
136 }
137 else {
138 layout = new TableFieldLayout(config.getTitle(), false);
139 }
140 widget = new MultiplicityTable(config);
141 config.getParentFd().setFieldWidget(widget);
142 config.getParentFd().setWidgetBinding(new MultiplicityTableBinding());
143 this.addField(config.getParentFd());
144
145 break;
146 default:
147 layout = null;
148 }
149 }
150
151 public void setParentPath(String parentPath) {
152 if (widget instanceof MultiplicityGroup) {
153 ((MultiplicityGroup)widget).setParentPath(parentPath);
154 }
155 else {
156 ((MultiplicityTable)widget).setParentPath(parentPath);
157 }
158
159 }
160
161 @Override
162 public void resetFieldInteractionFlags() {
163 super.resetFieldInteractionFlags();
164 if (widget instanceof MultiplicityGroup){
165 ((MultiplicityGroup)widget).resetDirtyFlags();
166 }
167 }
168
169 @Override
170 public void resetDirtyFlags() {
171 super.resetDirtyFlags();
172 if (widget instanceof MultiplicityGroup){
173 ((MultiplicityGroup)widget).resetDirtyFlags();
174 }
175 }
176
177 @Override
178 public boolean isDirty() {
179 boolean isDirty = super.isDirty();
180 if (!isDirty && widget instanceof MultiplicityGroup){
181 isDirty = ((MultiplicityGroup)widget).isDirty();
182 }
183
184 return isDirty;
185 }
186
187 public MultiplicityConfiguration getConfig(){
188 return config;
189 }
190 }