1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 91 (91) |
Complexity: 26 |
Complexity Density: 0.45 |
|
39 |
|
public class CourseWidget extends Composite implements AccessWidgetValue, HasDataValue { |
40 |
|
|
41 |
|
private CluSetRetriever courseMetadataRetriever = new CluSetRetrieverImpl(); |
42 |
|
private Callback getCluNameCallback; |
43 |
|
|
44 |
|
|
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 |
|
|
52 |
|
private Metadata searchCourseMetadata = null; |
53 |
|
private BlockingTask initializeTask = new BlockingTask("Initializing"); |
54 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
55 |
0
|
public CourseWidget() {... |
56 |
0
|
this.initWidget(layout); |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
59 |
0
|
@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 |
|
|
71 |
0
|
createAndAddCourseTypesDropdown(); |
72 |
|
|
73 |
0
|
retrieveMetadata(); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
76 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
84 |
0
|
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
99 |
0
|
private void retrieveMetadata() {... |
100 |
0
|
if (searchCourseMetadata == null) { |
101 |
0
|
KSBlockingProgressIndicator.addTask(initializeTask); |
102 |
0
|
courseMetadataRetriever.getMetadata("courseSet", new Callback<Metadata>(){ |
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.22 |
|
103 |
0
|
@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 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
126 |
0
|
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 |
|
|
138 |
0
|
layout.add(courseWidget); |
139 |
|
} |
140 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
0
|
protected MessageKeyInfo generateMessageInfo(String labelKey) {... |
142 |
0
|
return new MessageKeyInfo("clusetmanagement", "clusetmanagement", "draft", labelKey); |
143 |
|
} |
144 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
145 |
0
|
@Override... |
146 |
|
public void addValueChangeCallback(Callback<Data.Value> callback) { |
147 |
|
} |
148 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
149 |
0
|
@Override... |
150 |
|
public void setValue(Data.Value value) { |
151 |
|
} |
152 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
153 |
0
|
@Override... |
154 |
|
public void getValue(Callback<String> doneSaveCallback) { |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
157 |
0
|
@Override... |
158 |
|
public void setValue(final String id) { |
159 |
0
|
if (id != null) { |
160 |
0
|
getCluNameCallback.exec(id); |
161 |
|
} |
162 |
|
} |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
164 |
0
|
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 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
0
|
public void addGetCluNameCallback(Callback callback) {... |
173 |
0
|
this.getCluNameCallback = callback; |
174 |
|
} |
175 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 4 |
Complexity Density: 1 |
|
176 |
0
|
@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 |
|
} |