1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.client.configurable.mvc.views; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.student.common.assembly.data.Metadata; |
22 | |
import org.kuali.student.common.assembly.data.ModelDefinition; |
23 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
24 | |
import org.kuali.student.common.ui.client.configurable.mvc.LayoutController; |
25 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection; |
26 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
27 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
28 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
29 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
30 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
31 | |
import org.kuali.student.common.ui.client.mvc.View; |
32 | |
|
33 | |
import com.google.gwt.user.client.Window; |
34 | |
import com.google.gwt.user.client.ui.Widget; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public abstract class SectionView extends BaseSection implements View { |
44 | |
|
45 | |
protected String modelId; |
46 | |
protected DataModel model; |
47 | |
|
48 | |
private Enum<?> viewEnum; |
49 | |
private String viewName; |
50 | |
|
51 | 0 | private List<View> views = new ArrayList<View>(); |
52 | |
|
53 | 0 | public SectionView() {} |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | 0 | public SectionView(Enum<?> viewEnum, String viewName) { |
60 | 0 | this.viewEnum = viewEnum; |
61 | 0 | this.viewName = viewName; |
62 | 0 | } |
63 | |
|
64 | |
public void init(Enum<?> viewEnum, String viewName) { |
65 | 0 | this.viewEnum = viewEnum; |
66 | 0 | this.viewName = viewName; |
67 | 0 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
@Override |
75 | |
public Enum<?> getViewEnum() { |
76 | 0 | return viewEnum; |
77 | |
} |
78 | |
|
79 | |
public void setViewEnum(Enum<?> viewEnum) { |
80 | 0 | this.viewEnum = viewEnum; |
81 | 0 | } |
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
@Override |
92 | |
public void beforeShow(final Callback<Boolean> onReadyCallback) { |
93 | |
|
94 | 0 | super.clearValidationErrors(); |
95 | |
|
96 | 0 | if (getController() != null) { |
97 | 0 | getController().requestModel(modelId, new ModelRequestCallback<DataModel>() { |
98 | |
|
99 | |
@Override |
100 | |
public void onRequestFail(Throwable cause) { |
101 | 0 | Window.alert("Failed to get model: " + modelId + " for SectionView " + getName()); |
102 | 0 | onReadyCallback.exec(false); |
103 | 0 | } |
104 | |
|
105 | |
@Override |
106 | |
public void onModelReady(DataModel m) { |
107 | 0 | model = m; |
108 | 0 | updateWidgetData(m); |
109 | 0 | resetFieldInteractionFlags(); |
110 | 0 | onReadyCallback.exec(true); |
111 | 0 | } |
112 | |
|
113 | |
}); |
114 | |
} |
115 | |
|
116 | 0 | for (Section section : sections) { |
117 | 0 | if (section instanceof SectionView) { |
118 | 0 | ((SectionView) section).beforeShow(new Callback<Boolean>() { |
119 | |
@Override |
120 | |
public void exec(Boolean result) { |
121 | 0 | } |
122 | |
}); |
123 | |
} |
124 | |
} |
125 | 0 | for (View view : views) { |
126 | 0 | view.beforeShow(Controller.NO_OP_CALLBACK); |
127 | |
} |
128 | |
|
129 | 0 | } |
130 | |
|
131 | |
public String getModelId() { |
132 | 0 | return modelId; |
133 | |
} |
134 | |
|
135 | |
public void setModelId(String modelId) { |
136 | 0 | this.modelId = modelId; |
137 | 0 | } |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
@Override |
146 | |
public boolean beforeHide() { |
147 | 0 | return true; |
148 | |
} |
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
@Override |
156 | |
public Controller getController() { |
157 | 0 | return super.getLayoutController(); |
158 | |
} |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
@Override |
166 | |
public String getName() { |
167 | 0 | return viewName; |
168 | |
} |
169 | |
|
170 | |
public void setName(String name) { |
171 | 0 | this.viewName = name; |
172 | 0 | } |
173 | |
|
174 | |
public void setController(Controller controller) { |
175 | 0 | if (controller instanceof LayoutController) { |
176 | 0 | super.setLayoutController((LayoutController) controller); |
177 | |
} else { |
178 | 0 | throw new IllegalArgumentException("Configurable UI sections require a LayoutController, not a base MVC controller"); |
179 | |
} |
180 | 0 | } |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
public void updateView() { |
186 | 0 | getController().requestModel(modelId, new ModelRequestCallback<DataModel>() { |
187 | |
@Override |
188 | |
public void onModelReady(DataModel m) { |
189 | |
|
190 | 0 | SectionView.this.model = m; |
191 | 0 | updateWidgetData(m); |
192 | 0 | } |
193 | |
|
194 | |
|
195 | |
@Override |
196 | |
public void onRequestFail(Throwable cause) { |
197 | 0 | Window.alert("Failed to get model"); |
198 | 0 | } |
199 | |
}); |
200 | |
|
201 | 0 | } |
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
public void updateView(DataModel m) { |
208 | 0 | this.model = m; |
209 | 0 | updateWidgetData(m); |
210 | 0 | } |
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
public Widget asWidget() { |
216 | 0 | return this.getLayout(); |
217 | |
} |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
@Override |
223 | |
public String collectHistory(String historyStack) { |
224 | 0 | return null; |
225 | |
} |
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
@Override |
231 | |
public void onHistoryEvent(String historyStack) { |
232 | |
|
233 | 0 | } |
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
@Override |
239 | |
public void collectBreadcrumbNames(List<String> names) { |
240 | 0 | names.add(this.getName()); |
241 | 0 | } |
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
public void addView(View view) { |
248 | 0 | views.add(view); |
249 | 0 | addWidget(view.asWidget()); |
250 | 0 | } |
251 | |
|
252 | |
public DataModel getModel() { |
253 | 0 | return model; |
254 | |
} |
255 | |
|
256 | |
public void updateMetadata(ModelDefinition modelDefinition) { |
257 | 0 | updateMetadata(modelDefinition, this); |
258 | 0 | } |
259 | |
|
260 | |
private void updateMetadata(ModelDefinition modelDefinition, Section topSection) { |
261 | 0 | for (Section section : topSection.getSections()) { |
262 | 0 | updateMetadata(modelDefinition, section); |
263 | |
} |
264 | 0 | for (FieldDescriptor field : topSection.getFields()) { |
265 | 0 | Metadata newMetadata = modelDefinition.getMetadata(field.getFieldKey()); |
266 | 0 | if (newMetadata != null) { |
267 | 0 | field.setMetadata(newMetadata); |
268 | |
} |
269 | 0 | } |
270 | 0 | } |
271 | |
|
272 | |
@Override |
273 | |
public String toString() { |
274 | 0 | return viewName; |
275 | |
} |
276 | |
|
277 | |
public boolean isExportButtonActive() { |
278 | 0 | return false; |
279 | |
} |
280 | |
|
281 | |
@Override |
282 | |
public void showExport(boolean show) { |
283 | |
|
284 | |
|
285 | 0 | } |
286 | |
} |