Clover Coverage Report - Kuali Student 1.2-M6-SNAPSHOT (Aggregated)
Coverage timestamp: Mon Sep 12 2011 05:03:53 EDT
../../../../../../../img/srcFileCovDistChart0.png 42% of files have more coverage
58   185   26   3.87
18   139   0.45   15
15     1.73  
1    
 
  CourseWidget       Line # 39 58 0% 26 91 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15    package org.kuali.student.lum.common.client.widgets;
16   
17    import java.util.List;
18   
19    import org.kuali.student.common.assembly.data.Data;
20    import org.kuali.student.common.assembly.data.Metadata;
21    import org.kuali.student.common.ui.client.configurable.mvc.DefaultWidgetFactory;
22    import org.kuali.student.common.ui.client.configurable.mvc.sections.VerticalSection;
23    import org.kuali.student.common.ui.client.mvc.Callback;
24    import org.kuali.student.common.ui.client.mvc.HasDataValue;
25    import org.kuali.student.common.ui.client.widgets.KSDropDown;
26    import org.kuali.student.common.ui.client.widgets.KSLabel;
27    import org.kuali.student.common.ui.client.widgets.field.layout.element.MessageKeyInfo;
28    import org.kuali.student.common.ui.client.widgets.impl.KSDropDownImpl;
29    import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent;
30    import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler;
31    import org.kuali.student.common.ui.client.widgets.list.impl.SimpleListItems;
32    import org.kuali.student.common.ui.client.widgets.progress.BlockingTask;
33    import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator;
34    import org.kuali.student.common.ui.client.widgets.search.KSPicker;
35    import org.kuali.student.core.statement.ui.client.widgets.rules.AccessWidgetValue;
36   
37    import com.google.gwt.user.client.ui.Composite;
38   
 
39    public class CourseWidget extends Composite implements AccessWidgetValue, HasDataValue {
40   
41    private CluSetRetriever courseMetadataRetriever = new CluSetRetrieverImpl();
42    private Callback getCluNameCallback;
43   
44    //widgets
45    private VerticalSection layout = new VerticalSection();
46    private KSDropDown courseTypeWidget;
47    private KSPicker courseWidget = null;
48    private KSLabel previousCourseCode;
49    private String previousCourseId;
50   
51    //data
52    private Metadata searchCourseMetadata = null;
53    private BlockingTask initializeTask = new BlockingTask("Initializing");
54   
 
55  0 toggle public CourseWidget() {
56  0 this.initWidget(layout);
57    }
58   
 
59  0 toggle @Override
60    public void initWidget(List<Metadata> fieldsMetadata) {
61   
62  0 previousCourseCode = null;
63  0 previousCourseId = null;
64   
65  0 layout.clear();
66   
67  0 final VerticalSection choosingSection = new VerticalSection();
68  0 choosingSection.addWidget(new KSLabel("<b>Add a course</b>"));
69   
70    //first metadata is a drop down to select type of course
71  0 createAndAddCourseTypesDropdown();
72   
73  0 retrieveMetadata();
74    }
75   
 
76  0 toggle private void createAndAddCourseTypesDropdown() {
77  0 courseTypeWidget = new KSDropDown();
78  0 SimpleListItems courseTypes = new SimpleListItems();
79  0 courseTypes.addItem(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD, "Approved Courses");
80  0 courseTypes.addItem(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD, "Proposed Courses");
81  0 courseTypeWidget.setListItems(courseTypes);
82  0 courseTypeWidget.addSelectionChangeHandler(new SelectionChangeHandler() {
83   
 
84  0 toggle @Override
85    public void onSelectionChange(SelectionChangeEvent event) {
86  0 String courseTypeSelected = ((KSDropDownImpl)event.getWidget()).getSelectedItem();
87  0 if (courseTypeSelected == null) {
88  0 if (courseWidget != null) {
89  0 layout.remove(courseWidget);
90    }
91  0 return;
92    }
93  0 addCourseListWidget(true, courseTypeSelected);
94    }
95    });
96  0 layout.add(courseTypeWidget);
97    }
98   
 
99  0 toggle private void retrieveMetadata() {
100  0 if (searchCourseMetadata == null) {
101  0 KSBlockingProgressIndicator.addTask(initializeTask);
102  0 courseMetadataRetriever.getMetadata("courseSet", new Callback<Metadata>(){
 
103  0 toggle @Override
104    public void exec(Metadata result) {
105  0 searchCourseMetadata = result;
106  0 searchCourseMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD).getConstraints().get(0).setMaxOccurs(1);
107  0 searchCourseMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD).getConstraints().get(0).setMaxOccurs(1);
108  0 searchCourseMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD).getConstraints().get(0).setId("single");
109  0 searchCourseMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD).getConstraints().get(0).setId("single");
110  0 KSBlockingProgressIndicator.removeTask(initializeTask);
111   
112  0 if (previousCourseCode == null) {
113  0 courseTypeWidget.selectItem(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD);
114  0 addCourseListWidget(true, courseTypeWidget.getSelectedItem());
115    }
116    }
117    });
118    } else {
119  0 if (previousCourseCode == null) {
120  0 courseTypeWidget.selectItem(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD);
121  0 addCourseListWidget(true, courseTypeWidget.getSelectedItem());
122    }
123    }
124    }
125   
 
126  0 toggle private void addCourseListWidget(boolean enabled, String courseType) {
127  0 if (courseWidget != null) {
128  0 layout.remove(courseWidget);
129    }
130  0 if (previousCourseCode != null) {
131  0 layout.remove(previousCourseCode);
132  0 previousCourseCode = null;
133  0 previousCourseId = null;
134    }
135  0 courseWidget = (KSPicker) DefaultWidgetFactory.getInstance().getWidget(searchCourseMetadata.getProperties().get(courseType));
136  0 courseWidget.getSearchPanel().setMutipleSelect(false);
137    // ((KSSuggestBox) courseWidget.getInputWidget()).setEnabled(enabled);
138  0 layout.add(courseWidget);
139    }
140   
 
141  0 toggle protected MessageKeyInfo generateMessageInfo(String labelKey) {
142  0 return new MessageKeyInfo("clusetmanagement", "clusetmanagement", "draft", labelKey);
143    }
144   
 
145  0 toggle @Override
146    public void addValueChangeCallback(Callback<Data.Value> callback) {
147    }
148   
 
149  0 toggle @Override
150    public void setValue(Data.Value value) {
151    }
152   
 
153  0 toggle @Override
154    public void getValue(Callback<String> doneSaveCallback) {
155    }
156   
 
157  0 toggle @Override
158    public void setValue(final String id) {
159  0 if (id != null) {
160  0 getCluNameCallback.exec(id);
161    }
162    }
163   
 
164  0 toggle public void setLabelContent(String id, final String code) {
165  0 layout.clear();
166  0 previousCourseId = id;
167  0 previousCourseCode = new KSLabel(code);
168  0 layout.add(previousCourseCode);
169  0 createAndAddCourseTypesDropdown();
170    }
171   
 
172  0 toggle public void addGetCluNameCallback(Callback callback) {
173  0 this.getCluNameCallback = callback;
174    }
175   
 
176  0 toggle @Override
177    public Data.Value getValue() {
178  0 Data.Value pickerValue = courseWidget.getValue();
179  0 if ((pickerValue.toString().isEmpty()) && (previousCourseCode != null) && (!previousCourseCode.getText().isEmpty())) {
180  0 return new Data.StringValue(previousCourseId);
181    }
182   
183  0 return pickerValue;
184    }
185    }