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.ui.client.configurable.mvc.DefaultWidgetFactory; |
20 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
21 | |
import org.kuali.student.common.ui.client.mvc.HasDataValue; |
22 | |
import org.kuali.student.common.ui.client.widgets.KSDropDown; |
23 | |
import org.kuali.student.common.ui.client.widgets.list.KSRadioButtonList; |
24 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent; |
25 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler; |
26 | |
import org.kuali.student.common.ui.client.widgets.list.impl.KSRadioButtonListImpl; |
27 | |
import org.kuali.student.common.ui.client.widgets.rules.AccessWidgetValue; |
28 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
29 | |
import org.kuali.student.core.assembly.data.Data; |
30 | |
import org.kuali.student.core.assembly.data.Metadata; |
31 | |
|
32 | |
import com.google.gwt.user.client.ui.Composite; |
33 | |
import com.google.gwt.user.client.ui.FlowPanel; |
34 | |
|
35 | 0 | public class GradeWidget extends Composite implements AccessWidgetValue, HasDataValue { |
36 | |
|
37 | 0 | private FlowPanel layout = new FlowPanel(); |
38 | |
KSPicker gradeTypeWidget; |
39 | 0 | KSPicker gradeWidget = null; |
40 | |
Metadata gradeMetadata; |
41 | |
|
42 | 0 | public GradeWidget() { |
43 | 0 | this.initWidget(layout); |
44 | 0 | } |
45 | |
|
46 | |
@Override |
47 | |
public void initWidget(List<Metadata> fieldsMetadata) { |
48 | 0 | layout.clear(); |
49 | 0 | gradeTypeWidget = (KSPicker) DefaultWidgetFactory.getInstance().getWidget(fieldsMetadata.get(0)); |
50 | 0 | layout.add(gradeTypeWidget); |
51 | 0 | gradeMetadata = fieldsMetadata.get(1); |
52 | 0 | setupHandlers(); |
53 | 0 | } |
54 | |
|
55 | |
private void setupHandlers() { |
56 | |
|
57 | 0 | ((KSRadioButtonList)gradeTypeWidget.getInputWidget()).addSelectionChangeHandler(new SelectionChangeHandler() { |
58 | |
|
59 | |
@Override |
60 | |
public void onSelectionChange(SelectionChangeEvent event) { |
61 | 0 | String gradeTypeSelected = ((KSRadioButtonListImpl)event.getWidget()).getSelectedItem(); |
62 | 0 | gradeMetadata.getInitialLookup().getParams().get(0).setDefaultValueList(null); |
63 | 0 | gradeMetadata.getInitialLookup().getParams().get(0).setDefaultValueString(gradeTypeSelected); |
64 | 0 | addGradeListWidget(true); |
65 | 0 | } |
66 | |
}); |
67 | 0 | } |
68 | |
|
69 | |
private void addGradeListWidget(boolean enabled) { |
70 | 0 | if (gradeWidget != null) { |
71 | 0 | layout.remove(gradeWidget); |
72 | |
} |
73 | 0 | gradeWidget = (KSPicker) DefaultWidgetFactory.getInstance().getWidget(gradeMetadata); |
74 | 0 | ((KSDropDown)gradeWidget.getInputWidget()).setEnabled(enabled); |
75 | 0 | layout.add(gradeWidget); |
76 | 0 | } |
77 | |
|
78 | |
@Override |
79 | |
public void addValueChangeCallback(Callback<Data.Value> callback) { |
80 | 0 | } |
81 | |
|
82 | |
@Override |
83 | |
public void setValue(Data.Value value) { |
84 | 0 | addGradeListWidget(false); |
85 | 0 | gradeWidget.setValue(value); |
86 | 0 | } |
87 | |
|
88 | |
@Override |
89 | |
public void getValue(Callback<String> doneSaveCallback) { |
90 | 0 | } |
91 | |
|
92 | |
@Override |
93 | |
public void setValue(String id) { |
94 | 0 | } |
95 | |
|
96 | |
@Override |
97 | |
public Data.Value getValue() { |
98 | 0 | return (gradeWidget != null ? gradeWidget.getValue() : null); |
99 | |
} |
100 | |
} |