1 package org.kuali.student.lum.lu.ui.main.client.controllers;
2
3 import java.util.Map;
4
5 import org.kuali.student.common.ui.client.application.Application;
6 import org.kuali.student.common.ui.client.application.ViewContext;
7 import org.kuali.student.common.ui.client.configurable.mvc.LayoutController;
8 import org.kuali.student.common.ui.client.mvc.Callback;
9 import org.kuali.student.common.ui.client.mvc.Controller;
10 import org.kuali.student.common.ui.client.mvc.View;
11 import org.kuali.student.common.ui.client.util.WindowTitleUtils;
12 import org.kuali.student.common.ui.client.widgets.field.layout.element.SpanPanel;
13 import org.kuali.student.common.ui.shared.IdAttributes.IdType;
14 import org.kuali.student.lum.common.client.configuration.LUMViews;
15 import org.kuali.student.lum.common.client.widgets.AppLocations;
16 import org.kuali.student.lum.lu.ui.browseprogram.client.controllers.BrowseProgramController;
17 import org.kuali.student.lum.lu.ui.course.client.controllers.CourseAdminController;
18 import org.kuali.student.lum.lu.ui.course.client.controllers.CourseAdminRetireController;
19 import org.kuali.student.lum.lu.ui.course.client.controllers.CourseAdminWithoutVersionController;
20 import org.kuali.student.lum.lu.ui.course.client.controllers.CourseProposalController;
21 import org.kuali.student.lum.lu.ui.course.client.controllers.CourseRetireByProposalController;
22 import org.kuali.student.lum.lu.ui.course.client.controllers.ViewCourseParentController;
23 import org.kuali.student.lum.lu.ui.course.client.views.CategoryManagementView;
24 import org.kuali.student.lum.lu.ui.course.client.views.CurriculumHomeView;
25 import org.kuali.student.lum.lu.ui.dependency.client.controllers.DependencyAnalysisController;
26 import org.kuali.student.lum.lu.ui.tools.client.configuration.CatalogBrowserController;
27 import org.kuali.student.lum.lu.ui.tools.client.configuration.CluSetsManagementController;
28 import org.kuali.student.lum.program.client.ProgramConstants;
29 import org.kuali.student.lum.program.client.ProgramRegistry;
30 import org.kuali.student.lum.program.client.core.CoreManager;
31 import org.kuali.student.lum.program.client.credential.CredentialManager;
32 import org.kuali.student.lum.program.client.major.MajorManager;
33
34 import com.google.gwt.core.client.GWT;
35 import com.google.gwt.core.client.RunAsyncCallback;
36 import com.google.gwt.user.client.Window;
37
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 public class CurriculumHomeController extends LayoutController {
66
67 private CurriculumHomeView home;
68 private final SpanPanel panel = new SpanPanel();
69
70 private CourseProposalController courseProposalController;
71 private CourseRetireByProposalController courseRetireByProposalController;
72 private CourseAdminController courseAdminController;
73 private CourseAdminWithoutVersionController courseAdminWithoutVersionController;
74 private CourseAdminRetireController courseAdminRetireController;
75 private LayoutController viewCourseController;
76 private LayoutController manageCluSetsController;
77 private LayoutController browseCatalogController;
78 private LayoutController dependencyAnalysisController;
79 private LayoutController browseProgramController;
80 private MajorManager majorManager = new MajorManager();
81 private CredentialManager credentialManager = new CredentialManager();
82 private CoreManager coreManager = new CoreManager();
83
84 private abstract class RunAsyncGetView implements RunAsyncCallback {
85 public void onFailure(Throwable reason) {
86 Window.alert("Download failed. Please try again.");
87 }
88 }
89
90 public CurriculumHomeController() {
91 super();
92 this.setDefaultView(LUMViews.DEFAULT);
93 this.initWidget(panel);
94 setupDefaultView();
95 }
96
97 public CurriculumHomeController(Controller controller, String name, Enum<?> viewType) {
98 super();
99 super.setController(controller);
100 super.setName(name);
101 super.setViewEnum(viewType);
102 this.setDefaultView(LUMViews.DEFAULT);
103 this.initWidget(panel);
104 setupDefaultView();
105 }
106
107 private void setupDefaultView() {
108 home = new CurriculumHomeView(this, LUMViews.DEFAULT);
109 }
110
111 @Override
112 public <V extends Enum<?>> void getView(V viewType, final Callback<View> callback, Map<String, String> tokenMap) {
113
114
115 switch ((LUMViews) viewType) {
116 case DEFAULT:
117 callback.exec(home);
118 break;
119 case COURSE_PROPOSAL:
120
121
122
123 callback.exec(getCourseProposalController());
124
125
126 break;
127 case COURSE_RETIRE_BY_PROPOSAL:
128
129
130
131 callback.exec(getCourseRetirebyProposalController());
132
133
134 break;
135 case COURSE_ADMIN:
136
137
138
139 callback.exec(getCourseAdminController());
140
141
142 break;
143 case COURSE_ADMIN_NO_VERSION:
144
145
146
147 callback.exec(getCourseAdminWithoutVersionController());
148
149
150 break;
151 case COURSE_ADMIN_RETIRE:
152
153
154
155 callback.exec(getCourseAdminRetireController());
156
157
158 break;
159
160 case VIEW_COURSE:
161
162
163
164 callback.exec(getViewCourseController());
165
166
167 break;
168 case PROGRAM_PROPOSAL:
169
170
171
172 if (ProgramRegistry.isCreateNew()) {
173 ProgramRegistry.setCreateNew(false);
174 majorManager = new MajorManager();
175 }
176 callback.exec(majorManager.getMajorProposalController());
177
178
179 break;
180 case PROGRAM_VIEW:
181
182
183
184 if (ProgramRegistry.isCreateNew()) {
185 ProgramRegistry.setCreateNew(false);
186 majorManager = new MajorManager();
187 }
188 callback.exec(majorManager.getProgramViewController());
189
190
191 break;
192 case PROGRAM_EDIT:
193
194
195
196 Application.getApplicationContext().setParentPath("");
197 if (ProgramRegistry.isCreateNew()) {
198 ProgramRegistry.setCreateNew(false);
199 majorManager = new MajorManager();
200 }
201 callback.exec(majorManager.getProgramEditController());
202
203
204 break;
205 case PROGRAM_SPEC_EDIT:
206
207
208
209 if (ProgramRegistry.isCreateNew()) {
210 ProgramRegistry.setCreateNew(false);
211 majorManager = new MajorManager();
212 }
213 callback.exec(majorManager.getProgramSpecEditController());
214
215
216 break;
217 case PROGRAM_CREATE:
218
219
220
221 majorManager = new MajorManager();
222 callback.exec(majorManager.getProgramEditController());
223
224
225 break;
226 case PROGRAM_VERSIONS:
227
228
229
230 callback.exec(majorManager.getProgramVersionsController());
231
232
233 break;
234 case CLU_SETS:
235
236
237
238 callback.exec(getCluSetsController());
239
240
241 break;
242 case COURSE_CATALOG:
243
244
245
246 callback.exec(getBrowseCatalogController());
247
248
249 break;
250 case VARIATION_VIEW:
251
252
253
254
255 if(majorManager.getProgramModel()!=null && majorManager.getProgramModel().getDefinition()!=null){
256 callback.exec(majorManager.getVariationViewController());
257 }else{
258
259
260
261 ViewContext viewContext = new ViewContext();
262 viewContext.setId(tokenMap.get("docId"));
263 viewContext.setAttribute(ProgramConstants.VARIATION_ID, tokenMap.get(ProgramConstants.VARIATION_ID));
264 viewContext.setAttribute(ProgramConstants.TYPE, ProgramConstants.VARIATION_TYPE_KEY);
265 viewContext.setIdType(IdType.OBJECT_ID);
266 ProgramRegistry.setCreateNew(true);
267 Application.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), viewContext);
268 }
269
270
271 break;
272 case VARIATION_EDIT:
273
274
275
276 if(majorManager.getProgramModel()!=null && majorManager.getProgramModel().getDefinition()!=null){
277 callback.exec(majorManager.getVariationEditController());
278 }else{
279
280 Application.getApplicationContext().setParentPath("");
281 if (ProgramRegistry.isCreateNew()) {
282 ProgramRegistry.setCreateNew(false);
283 majorManager = new MajorManager();
284 }
285 callback.exec(majorManager.getProgramEditController());
286 }
287
288
289 break;
290 case CORE_PROGRAM_VIEW:
291
292
293
294 if (ProgramRegistry.isCreateNew()) {
295 ProgramRegistry.setCreateNew(false);
296 coreManager = new CoreManager();
297 }
298 callback.exec(coreManager.getViewController());
299
300
301 break;
302 case CORE_PROGRAM_EDIT:
303
304
305
306 callback.exec(coreManager.getEditController());
307
308
309 break;
310 case CORE_PROGRAM_VERSIONS:
311
312
313
314 callback.exec(coreManager.getProgramVersionsController());
315
316
317 break;
318 case BACC_PROGRAM_VIEW:
319
320
321
322 if (ProgramRegistry.isCreateNew()) {
323 ProgramRegistry.setCreateNew(false);
324 credentialManager = new CredentialManager();
325 }
326 callback.exec(credentialManager.getBaccViewController());
327
328
329 break;
330 case BACC_PROGRAM_EDIT:
331
332
333
334 callback.exec(credentialManager.getBaccEditController());
335
336
337 break;
338 case BACC_PROGRAM_VERSIONS:
339
340
341
342 callback.exec(credentialManager.getProgramVersionsController());
343
344
345 break;
346 case LO_CATEGORIES:
347
348
349
350 callback.exec(getCategoryManagementController());
351
352
353 break;
354 case DEPENDENCY_ANALYSIS:
355
356
357
358 callback.exec(getDependencyAnalysisController());
359
360
361 break;
362 case BROWSE_PROGRAM:
363
364
365
366 callback.exec(getBrowseProgramController());
367
368
369 break;
370 default:
371 callback.exec(home);
372 }
373 }
374
375
376 protected View getCategoryManagementController() {
377 return new CategoryManagementView(this, "Learning Objective Categories", LUMViews.LO_CATEGORIES);
378 }
379
380 private CourseProposalController getCourseProposalController() {
381 courseProposalController = GWT.create(CourseProposalController.class);
382 return courseProposalController;
383 }
384
385 private CourseProposalController getCourseRetirebyProposalController(){
386 courseRetireByProposalController = GWT.create(CourseRetireByProposalController.class);
387 return courseRetireByProposalController;
388 }
389
390 private CourseAdminController getCourseAdminController() {
391 courseAdminController = GWT.create(CourseAdminController.class);
392 return courseAdminController;
393 }
394
395 private CourseAdminWithoutVersionController getCourseAdminRetireController(){
396 courseAdminRetireController = GWT.create(CourseAdminRetireController.class);
397 return courseAdminRetireController;
398 }
399
400 private CourseAdminWithoutVersionController getCourseAdminWithoutVersionController(){
401 courseAdminWithoutVersionController = GWT.create(CourseAdminWithoutVersionController.class);
402 return courseAdminWithoutVersionController;
403 }
404
405 private LayoutController getViewCourseController() {
406 if (viewCourseController == null) {
407 viewCourseController = GWT.create(ViewCourseParentController.class);
408 }
409 return this.viewCourseController;
410 }
411
412 private LayoutController getCluSetsController() {
413 manageCluSetsController = GWT.create(CluSetsManagementController.class);
414 return manageCluSetsController;
415 }
416
417 private LayoutController getBrowseCatalogController() {
418 browseCatalogController = new CatalogBrowserController(this);
419 return browseCatalogController;
420 }
421
422 private LayoutController getDependencyAnalysisController() {
423 dependencyAnalysisController = new DependencyAnalysisController("DependencyAnalaysis");
424 return dependencyAnalysisController;
425 }
426
427 private LayoutController getBrowseProgramController() {
428 browseProgramController = new BrowseProgramController("BrowseProgram");
429 return browseProgramController;
430 }
431
432 @Override
433 protected void hideView(View view) {
434 ApplicationController.getApplicationViewContainer().clear();
435 }
436
437 @Override
438 protected void renderView(View view) {
439 ApplicationController.getApplicationViewContainer().add(view.asWidget());
440 }
441
442 @Override
443 public Enum<?> getViewEnumValue(String enumValue) {
444 return LUMViews.valueOf(enumValue);
445 }
446
447 @Override
448 public void updateModel() {
449
450 }
451
452 public <V extends Enum<?>> void showView(V viewType, Callback<Boolean> onReadyCallback) {
453 if (viewType == LUMViews.DEFAULT) {
454 WindowTitleUtils.setContextTitle(name);
455 }
456 super.showView(viewType, onReadyCallback);
457 }
458 }