View Javadoc

1   package org.kuali.student.lum.lu.ui.main.client.configuration;
2   
3   import java.util.List;
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.SectionTitle;
8   import org.kuali.student.common.ui.client.mvc.Callback;
9   import org.kuali.student.common.ui.client.widgets.KSLightBox;
10  import org.kuali.student.common.ui.client.widgets.layout.ContentBlockLayout;
11  import org.kuali.student.common.ui.client.widgets.layout.LinkContentBlock;
12  import org.kuali.student.common.ui.client.widgets.search.KSPicker;
13  import org.kuali.student.common.ui.client.widgets.search.SearchPanel;
14  import org.kuali.student.common.ui.client.widgets.search.SelectedResults;
15  import org.kuali.student.common.ui.shared.IdAttributes.IdType;
16  import org.kuali.student.core.assembly.data.Metadata;
17  import org.kuali.student.core.rice.StudentIdentityConstants;
18  import org.kuali.student.lum.common.client.widgets.AppLocations;
19  import org.kuali.student.lum.lu.ui.course.client.widgets.RecentlyViewedBlock;
20  import org.kuali.student.lum.program.client.ProgramClientConstants;
21  import org.kuali.student.lum.program.client.ProgramConstants;
22  import org.kuali.student.lum.program.client.ProgramRegistry;
23  
24  import com.google.gwt.event.dom.client.ClickEvent;
25  import com.google.gwt.event.dom.client.ClickHandler;
26  import com.google.gwt.event.logical.shared.ValueChangeEvent;
27  import com.google.gwt.event.logical.shared.ValueChangeHandler;
28  import com.google.gwt.user.client.ui.Anchor;
29  import com.google.gwt.user.client.ui.Hyperlink;
30  import com.google.gwt.user.client.ui.Label;
31  import com.google.gwt.user.client.ui.Widget;
32  
33  public class CurriculumHomeConfigurer implements CurriculumHomeConstants {
34  
35      protected Metadata searchMetadata;
36  
37      public Widget configure(Metadata searchMeta) {
38          this.searchMetadata = searchMeta;
39          ContentBlockLayout layout = new ContentBlockLayout(getMessage(CURRICULUM_MANAGEMENT));
40          layout.addContentTitleWidget(getHowToWidget());
41          layout.addContentTitleWidget(getActionListLink());
42  
43          //Create
44          LinkContentBlock create = new LinkContentBlock(
45                  getMessage(CREATE),
46                  getMessage(CREATE_DESC));
47          create.addNavLinkWidget(getMessage(CREATE_COURSE), AppLocations.Locations.COURSE_PROPOSAL.getLocation());
48          create.addNavLinkWidget(getMessage(CREATE_PROGRAM), AppLocations.Locations.EDIT_PROGRAM.getLocation());
49  
50  
51          //View + Modify
52          LinkContentBlock viewModify = new LinkContentBlock(
53                  getMessage(VIEW_MODIFY),
54                  getMessage(VIEW_MODIFY_DESC));
55          SectionTitle courses = SectionTitle.generateH4Title(getMessage("courses"));
56          courses.addStyleName("bold");
57          viewModify.add(courses);
58          viewModify.addNavLinkWidget(getMessage(BROWSE_CATALOG), AppLocations.Locations.BROWSE_CATALOG.getLocation());
59          viewModify.add(getFindCoursesWidget());
60          viewModify.add(getFindProposalsWidget());
61          SectionTitle programs = SectionTitle.generateH4Title(getMessage("programs"));
62          programs.addStyleName("bold");
63          viewModify.add(programs);
64          viewModify.add(getFindMajorsWidget());
65          viewModify.add(getFindCoreProgramWidget());
66          viewModify.add(getFindCredentialProgramWidget());
67  
68          //RecentlyViewed
69          RecentlyViewedBlock recent = new RecentlyViewedBlock(
70                  getMessage(RECENTLY_VIEWED),
71                  getMessage(RV_DESC));
72          recent.addStyleName("recentlyViewed-block");
73  
74          //Tools
75          LinkContentBlock tools = new LinkContentBlock(
76                  getMessage(TOOLS),
77                  getMessage(TOOLS_DESC));
78          tools.addNavLinkWidget(getMessage(COURSE_SETS), AppLocations.Locations.MANAGE_CLU_SETS.getLocation());
79          tools.addNavLinkWidget(getMessage(LO_CATEGORIES), AppLocations.Locations.MANAGE_LO_CATEGORIES.getLocation());
80          //Coming soon
81          Label depAnalysis = new Label(getMessage(DEP_ANALYSIS));
82          depAnalysis.setStyleName("contentBlock-navLink-disabled");
83          depAnalysis.setTitle("Coming Soon");
84          tools.add(depAnalysis);
85          Label learningObjectives = new Label(getMessage(LOS));
86          learningObjectives.setTitle("Coming Soon");
87          learningObjectives.setStyleName("contentBlock-navLink-disabled");
88          tools.add(learningObjectives);
89  
90          //Add all blocks
91          layout.addContentBlock(create);
92          layout.addContentBlock(viewModify);
93          recent.addBlock(tools);
94          layout.addContentBlock(recent);
95  
96          return layout;
97      }
98  
99      private Widget getFindCredentialProgramWidget() {
100         Anchor anchor = createNavigationWidget(getMessage(FIND_CREDENTIALS));
101         anchor.addClickHandler(new ClickHandler() {
102             @Override
103             public void onClick(ClickEvent event) {
104                 ProgramRegistry.setCreateNew(true);
105                 ViewContext baccViewContext = new ViewContext();
106                 baccViewContext.setId(ProgramClientConstants.CREDENTIAL_BACCALAUREATE_PROGRAM);
107                 Application.navigate(AppLocations.Locations.VIEW_BACC_PROGRAM.getLocation(), baccViewContext);
108             }
109         });
110         return anchor;
111     }
112 
113     private Widget getFindCoreProgramWidget() {
114         Anchor anchor = createNavigationWidget(getMessage(FIND_CORES));
115         anchor.addClickHandler(new ClickHandler() {
116             @Override
117             public void onClick(ClickEvent event) {
118                 ProgramRegistry.setCreateNew(true);
119                 Application.navigate(AppLocations.Locations.VIEW_CORE_PROGRAM.getLocation());
120             }
121         });
122         return anchor;
123     }
124 
125 
126     protected Widget getFindProposalsWidget() {
127         final Widget searchWidget;
128         if (searchMetadata != null) {
129             Metadata metadata = searchMetadata.getProperties().get("findProposal");
130             searchWidget = new KSPicker(metadata.getInitialLookup(), metadata.getAdditionalLookups());
131             SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel();
132             if (panel != null) {
133                 panel.setMutipleSelect(false);
134             }
135             ((KSPicker) searchWidget).setAdvancedSearchCallback(new Callback<List<SelectedResults>>() {
136 
137                 @Override
138                 public void exec(List<SelectedResults> result) {
139                 	if (result != null && result.size() > 0) {
140 	                    SelectedResults value = result.get(0);
141 	                    ViewContext viewContext = new ViewContext();
142 	                    viewContext.setId(value.getResultRow().getId());
143 	                    viewContext.setAttribute(StudentIdentityConstants.DOCUMENT_TYPE_NAME, value.getResultRow().getValue("proposal.resultColumn.proposalType"));
144 	                    viewContext.setIdType(IdType.KS_KEW_OBJECT_ID);
145 	                    Application.navigate(AppLocations.Locations.COURSE_PROPOSAL.getLocation(), viewContext);
146 	                    ((KSPicker) searchWidget).getSearchWindow().hide();
147                 	}
148                 }
149             });
150         } else {
151             searchWidget = new Label(getMessage(FIND_PROPOSALS));
152             searchWidget.setStyleName("contentBlock-navLink-disabled");
153         }
154         searchWidget.setStyleName("contentBlock-navLink");
155         return searchWidget;
156     }
157 
158     protected Widget getFindCoursesWidget() {
159         Widget searchWidget;
160         if (searchMetadata != null) {
161             Metadata metadata = searchMetadata.getProperties().get("findCourse");
162             searchWidget = new KSPicker(metadata.getInitialLookup(), metadata.getAdditionalLookups());
163             SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel();
164             if (panel != null) {
165                 panel.setMutipleSelect(false);
166             }
167             ((KSPicker) searchWidget).addValuesChangeHandler(new ValueChangeHandler<List<String>>() {
168                 public void onValueChange(ValueChangeEvent<List<String>> event) {
169                     List<String> selection = event.getValue();
170                     ViewContext viewContext = new ViewContext();
171                     viewContext.setId(selection.get(0));
172                     viewContext.setIdType(IdType.OBJECT_ID);
173                     Application.navigate(AppLocations.Locations.VIEW_COURSE.getLocation(), viewContext);
174                 }
175             });
176             searchWidget.setStyleName("contentBlock-navLink");
177         } else {
178             searchWidget = new Label(getMessage(FIND_COURSES));
179             searchWidget.setStyleName("contentBlock-navLink-disabled");
180         }
181         return searchWidget;
182     }
183 
184     protected Widget getFindMajorsWidget() {
185         final Widget searchWidget;
186         if (searchMetadata != null) {
187             Metadata metadata = searchMetadata.getProperties().get("findMajor");
188             searchWidget = new KSPicker(metadata.getInitialLookup(), metadata.getAdditionalLookups());
189             SearchPanel panel = ((KSPicker) searchWidget).getSearchPanel();
190             if (panel != null) {
191                 panel.setMutipleSelect(false);
192             }
193             ((KSPicker) searchWidget).setAdvancedSearchCallback(new Callback<List<SelectedResults>>() {
194 
195                 @Override
196                 public void exec(List<SelectedResults> result) {
197                     SelectedResults value = result.get(0);
198                     ViewContext viewContext = new ViewContext();
199                     viewContext.setId(value.getResultRow().getId());
200                     String cluType = value.getResultRow().getValue("lu.resultColumn.luOptionalType");
201                     if (cluType != null) {
202                         viewContext.setAttribute(ProgramConstants.TYPE, cluType);
203                     }
204                     String variationId = value.getResultRow().getValue("lu.resultColumn.variationId");
205                     if (variationId != null && !variationId.trim().isEmpty()) {
206                         viewContext.setAttribute(ProgramConstants.VARIATION_ID, variationId);
207                     }
208                     viewContext.setIdType(IdType.OBJECT_ID);
209                     ProgramRegistry.setCreateNew(true);
210                     Application.navigate(AppLocations.Locations.VIEW_PROGRAM.getLocation(), viewContext);
211                     ((KSPicker) searchWidget).getSearchWindow().hide();
212                 }
213             });
214 
215         } else {
216             searchWidget = new Label(getMessage(FIND_MAJORS));
217             searchWidget.setStyleName("contentBlock-navLink-disabled");
218         }
219         searchWidget.setStyleName("contentBlock-navLink");
220         return searchWidget;
221     }
222 
223     protected Widget getHowToWidget() {
224         Anchor widget = new Anchor(getMessage(HOW_TO));
225         widget.addClickHandler(new ClickHandler() {
226 
227             @Override
228             public void onClick(ClickEvent event) {
229                 final KSLightBox pop = new KSLightBox();
230                 pop.setWidget(new CurriculumHomeHelpTable());
231                 pop.setSize(800, 600);
232                 pop.show();
233             }
234         });
235         widget.setStyleName("contentBlock-navLink");
236         return widget;
237     }
238 
239     protected Widget getActionListLink() {
240         Hyperlink widget = new Hyperlink(getMessage(ACTIONLIST), AppLocations.Locations.HOME.getLocation());
241         widget.setStyleName("contentBlock-navLink");
242         return widget;
243     }
244 
245     private String getMessage(String key) {
246         return Application.getApplicationContext().getMessage(key);
247     }
248 
249     private Anchor createNavigationWidget(String title) {
250         Anchor anchor = new Anchor(title);
251         anchor.addStyleName("contentBlock-navLink");
252         return anchor;
253     }
254 
255 }