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