View Javadoc

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   *   Curriculum home controller which controls the main LayoutController views of the lum application.  The
40   * default view of this controller is the Curriculum Home Landing page.  The following views are views within
41   * this controller's scope:<br>
42   * 		COURSE_PROPOSAL<br>
43          COURSE_RETIRE_BY_PROPOSAL<br>
44          VIEW_COURSE<br>
45          PROGRAM_VIEW<br>
46          PROGRAM_EDIT<br>
47          PROGRAM_CREATE<br>
48          PROGRAM_VERSIONS<br>
49          CLU_SETS<br>
50          VARIATION_VIEW<br>
51          VARIATION_EDIT<br>
52          COURSE_CATALOG<br>
53          LO_CATEGORIES<br>
54          BACC_PROGRAM_VIEW<br>
55          BACC_PROGRAM_EDIT<br>
56          BACC_PROGRAM_VERSIONS<br>
57          CORE_PROGRAM_VIEW<br>
58          CORE_PROGRAM_EDIT<br>
59          CORE_PROGRAM_VERSIONS<br>
60   * These views can be accessed through links and searches provided by the CurriculumHomeView (the default view).
61   * 
62   * @author Kuali Student Team
63   * @see CurriculumHomeView
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         //this is done so the views can have delayed loading
114 
115         switch ((LUMViews) viewType) {
116             case DEFAULT:
117                 callback.exec(home);
118                 break;
119             case COURSE_PROPOSAL:
120 //                GWT.runAsync(new RunAsyncGetView() {
121 //                    @Override
122 //                    public void onSuccess() {
123                         callback.exec(getCourseProposalController());
124 //                    }
125 //                });
126                 break;
127             case COURSE_RETIRE_BY_PROPOSAL:
128 //              GWT.runAsync(new RunAsyncGetView() {
129 //                  @Override
130 //                  public void onSuccess() {
131                       callback.exec(getCourseRetirebyProposalController());
132 //                  }
133 //              });
134               break;  
135             case COURSE_ADMIN:
136 //                GWT.runAsync(new RunAsyncGetView() {
137 //                    @Override
138 //                    public void onSuccess() {
139                         callback.exec(getCourseAdminController());
140 //                    }
141 //                });
142                 break;
143             case COURSE_ADMIN_NO_VERSION:
144 //                GWT.runAsync(new RunAsyncGetView() {
145 //                    @Override
146 //                    public void onSuccess() {
147                         callback.exec(getCourseAdminWithoutVersionController());
148 //                    }
149 //                });
150                 break;
151             case COURSE_ADMIN_RETIRE:
152 //              GWT.runAsync(new RunAsyncGetView() {
153 //                  @Override
154 //                  public void onSuccess() {
155                       callback.exec(getCourseAdminRetireController());
156 //                  }
157 //              });
158               break;
159 
160             case VIEW_COURSE:
161 //                GWT.runAsync(new RunAsyncGetView() {
162 //                    @Override
163 //                    public void onSuccess() {
164                         callback.exec(getViewCourseController());
165 //                    }
166 //                });
167                 break;
168             case PROGRAM_PROPOSAL:
169 //                GWT.runAsync(new RunAsyncGetView() {
170 //                    @Override
171 //                    public void onSuccess() {
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 //                GWT.runAsync(new RunAsyncGetView() {
182 //                   @Override
183 //                    public void onSuccess() {
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 //                GWT.runAsync(new RunAsyncGetView() {
194 //                    @Override
195 //                    public void onSuccess() {
196                     	Application.getApplicationContext().setParentPath("");//Reset the parent path when navigating back
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 //                GWT.runAsync(new RunAsyncGetView() {
207 //                    @Override
208 //                    public void onSuccess() {
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 //                GWT.runAsync(new RunAsyncGetView() {
219 //                    @Override
220 //                    public void onSuccess() {
221                         majorManager = new MajorManager();
222                         callback.exec(majorManager.getProgramEditController());
223 //                    }
224 //                });
225                 break;
226             case PROGRAM_VERSIONS:
227 //                GWT.runAsync(new RunAsyncGetView() {
228 //                    @Override
229 //                    public void onSuccess() {
230                         callback.exec(majorManager.getProgramVersionsController());
231 //                    }
232 //                });
233                 break;
234             case CLU_SETS:
235 //                GWT.runAsync(new RunAsyncGetView() {
236 //                    @Override
237 //                    public void onSuccess() {
238                         callback.exec(getCluSetsController());
239 //                    }
240 //                });
241                 break;
242             case COURSE_CATALOG:
243 //                GWT.runAsync(new RunAsyncGetView() {
244 //                    @Override
245 //                    public void onSuccess() {
246                         callback.exec(getBrowseCatalogController());
247 //                    }
248 //                });
249                 break;
250             case VARIATION_VIEW:
251 //                GWT.runAsync(new RunAsyncGetView() {
252 //                    @Override
253 //                    public void onSuccess() {
254             	//Check if key data has been initialized (the program was loaded before the variation)
255             	if(majorManager.getProgramModel()!=null && majorManager.getProgramModel().getDefinition()!=null){	
256                         callback.exec(majorManager.getVariationViewController());
257             	}else{
258             		//If it has not yet been initialized, we need to pull some context information and 
259             		//navigate to the program view which will initialize program information and then load the variation view.
260             		//This is similar to the getFindMajorsWidget() in the CurriculumHomeConfigurer
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 //                GWT.runAsync(new RunAsyncGetView() {
274 //                    @Override
275 //                    public void onSuccess() {
276             	if(majorManager.getProgramModel()!=null && majorManager.getProgramModel().getDefinition()!=null){	
277                     callback.exec(majorManager.getVariationEditController());
278             	}else{
279             		//If the variation edit is refreshed, bring the user to the program screen first
280                 	Application.getApplicationContext().setParentPath("");//Reset the parent path when navigating back
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 //                GWT.runAsync(new RunAsyncGetView() {
292 //                    @Override
293 //                    public void onSuccess() {
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 //                GWT.runAsync(new RunAsyncGetView() {
304 //                    @Override
305 //                    public void onSuccess() {
306                         callback.exec(coreManager.getEditController());
307 //                    }
308 //                });
309                 break;
310             case CORE_PROGRAM_VERSIONS:
311 //                GWT.runAsync(new RunAsyncGetView() {
312 //                    @Override
313 //                    public void onSuccess() {
314                         callback.exec(coreManager.getProgramVersionsController());
315 //                    }
316 //                });
317                 break;
318             case BACC_PROGRAM_VIEW:
319 //                GWT.runAsync(new RunAsyncGetView() {
320 //                    @Override
321 //                    public void onSuccess() {
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 //                GWT.runAsync(new RunAsyncGetView() {
332 //                    @Override
333 //                    public void onSuccess() {
334                         callback.exec(credentialManager.getBaccEditController());
335 //                    }
336 //                });
337                 break;
338             case BACC_PROGRAM_VERSIONS:
339 //                GWT.runAsync(new RunAsyncGetView() {
340 //                    @Override
341 //                    public void onSuccess() {
342                         callback.exec(credentialManager.getProgramVersionsController());
343 //                    }
344 //                });
345                 break;
346             case LO_CATEGORIES:
347 //                GWT.runAsync(new RunAsyncGetView() {
348 //                    @Override
349 //                    public void onSuccess() {
350                         callback.exec(getCategoryManagementController());
351 //                    }
352 //                });
353                 break;
354             case DEPENDENCY_ANALYSIS:
355 //                GWT.runAsync(new RunAsyncGetView() {
356 //                    @Override
357 //                    public void onSuccess() {
358                         callback.exec(getDependencyAnalysisController());
359 //                    }
360 //                });
361                 break;
362             case BROWSE_PROGRAM:
363 //                GWT.runAsync(new RunAsyncGetView() {
364 //                    @Override
365 //                    public void onSuccess() {
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         // No model needed here
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 }