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