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 | |
|
39 | 0 | public class ProgramWidget extends Composite implements AccessWidgetValue, HasDataValue { |
40 | |
|
41 | 0 | private CluSetRetriever courseMetadataRetriever = new CluSetRetrieverImpl(); |
42 | |
private Callback getCluNameCallback; |
43 | |
|
44 | |
|
45 | 0 | private VerticalSection layout = new VerticalSection(); |
46 | |
private KSDropDown programTypeWidget; |
47 | 0 | private KSPicker programWidget = null; |
48 | |
private KSLabel previousProgramCode; |
49 | |
private String previousProgramId; |
50 | |
|
51 | |
|
52 | 0 | private Metadata searchProgramMetadata = null; |
53 | 0 | private BlockingTask initializeTask = new BlockingTask("Initializing"); |
54 | |
|
55 | 0 | public ProgramWidget() { |
56 | 0 | this.initWidget(layout); |
57 | 0 | } |
58 | |
|
59 | |
@Override |
60 | |
public void initWidget(List<Metadata> fieldsMetadata) { |
61 | |
|
62 | 0 | previousProgramCode = null; |
63 | 0 | previousProgramId = null; |
64 | |
|
65 | 0 | layout.clear(); |
66 | |
|
67 | 0 | final VerticalSection choosingSection = new VerticalSection(); |
68 | 0 | choosingSection.addWidget(new KSLabel("<b>Add a program</b>")); |
69 | |
|
70 | |
|
71 | 0 | createAndAddProgramTypesDropdown(); |
72 | |
|
73 | 0 | retrieveMetadata(); |
74 | 0 | } |
75 | |
|
76 | |
private void createAndAddProgramTypesDropdown() { |
77 | 0 | programTypeWidget = new KSDropDown(); |
78 | 0 | SimpleListItems programTypes = new SimpleListItems(); |
79 | 0 | programTypes.addItem(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD, "Approved Program"); |
80 | 0 | programTypes.addItem(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD, "Proposed Program"); |
81 | 0 | programTypeWidget.setListItems(programTypes); |
82 | 0 | programTypeWidget.addSelectionChangeHandler(new SelectionChangeHandler() { |
83 | |
|
84 | |
@Override |
85 | |
public void onSelectionChange(SelectionChangeEvent event) { |
86 | 0 | String programTypeSelected = ((KSDropDownImpl)event.getWidget()).getSelectedItem(); |
87 | 0 | if (programTypeSelected == null) { |
88 | 0 | if (programWidget != null) { |
89 | 0 | layout.remove(programWidget); |
90 | |
} |
91 | 0 | return; |
92 | |
} |
93 | 0 | addProgramListWidget(true, programTypeSelected); |
94 | 0 | } |
95 | |
}); |
96 | 0 | layout.add(programTypeWidget); |
97 | 0 | } |
98 | |
|
99 | |
private void retrieveMetadata() { |
100 | 0 | if (searchProgramMetadata == null) { |
101 | 0 | KSBlockingProgressIndicator.addTask(initializeTask); |
102 | 0 | courseMetadataRetriever.getMetadata("programSet", new Callback<Metadata>(){ |
103 | |
@Override |
104 | |
public void exec(Metadata result) { |
105 | 0 | searchProgramMetadata = result; |
106 | 0 | searchProgramMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD).getConstraints().get(0).setMaxOccurs(1); |
107 | 0 | searchProgramMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD).getConstraints().get(0).setMaxOccurs(1); |
108 | 0 | searchProgramMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD).getConstraints().get(0).setId("single"); |
109 | 0 | searchProgramMetadata.getProperties().get(CommonWidgetConstants.CLU_SET_PROPOSED_CLUS_FIELD).getConstraints().get(0).setId("single"); |
110 | 0 | KSBlockingProgressIndicator.removeTask(initializeTask); |
111 | |
|
112 | 0 | if (previousProgramCode == null) { |
113 | 0 | programTypeWidget.selectItem(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD); |
114 | 0 | addProgramListWidget(true, programTypeWidget.getSelectedItem()); |
115 | |
} |
116 | 0 | } |
117 | |
}); |
118 | |
} else { |
119 | 0 | if (previousProgramCode == null) { |
120 | 0 | programTypeWidget.selectItem(CommonWidgetConstants.CLU_SET_APPROVED_CLUS_FIELD); |
121 | 0 | addProgramListWidget(true, programTypeWidget.getSelectedItem()); |
122 | |
} |
123 | |
} |
124 | 0 | } |
125 | |
|
126 | |
private void addProgramListWidget(boolean enabled, String programType) { |
127 | 0 | if (programWidget != null) { |
128 | 0 | layout.remove(programWidget); |
129 | |
} |
130 | 0 | if (previousProgramCode != null) { |
131 | 0 | layout.remove(previousProgramCode); |
132 | 0 | previousProgramCode = null; |
133 | 0 | previousProgramId = null; |
134 | |
} |
135 | 0 | programWidget = (KSPicker) DefaultWidgetFactory.getInstance().getWidget(searchProgramMetadata.getProperties().get(programType)); |
136 | |
|
137 | |
|
138 | 0 | layout.add(programWidget); |
139 | 0 | } |
140 | |
|
141 | |
protected MessageKeyInfo generateMessageInfo(String labelKey) { |
142 | 0 | return new MessageKeyInfo("clusetmanagement", "clusetmanagement", "draft", labelKey); |
143 | |
} |
144 | |
|
145 | |
@Override |
146 | |
public void addValueChangeCallback(Callback<Data.Value> callback) { |
147 | 0 | } |
148 | |
|
149 | |
@Override |
150 | |
public void setValue(Data.Value value) { |
151 | 0 | } |
152 | |
|
153 | |
@Override |
154 | |
public void getValue(Callback<String> doneSaveCallback) { |
155 | 0 | } |
156 | |
|
157 | |
@Override |
158 | |
public void setValue(final String id) { |
159 | 0 | if (id != null) { |
160 | 0 | getCluNameCallback.exec(id); |
161 | |
} |
162 | 0 | } |
163 | |
|
164 | |
public void setLabelContent(String id, final String code) { |
165 | 0 | layout.clear(); |
166 | 0 | previousProgramId = id; |
167 | 0 | previousProgramCode = new KSLabel(code); |
168 | 0 | layout.add(previousProgramCode); |
169 | 0 | createAndAddProgramTypesDropdown(); |
170 | 0 | } |
171 | |
|
172 | |
public void addGetCluNameCallback(Callback callback) { |
173 | 0 | this.getCluNameCallback = callback; |
174 | 0 | } |
175 | |
|
176 | |
@Override |
177 | |
public Data.Value getValue() { |
178 | 0 | Data.Value pickerValue = programWidget.getValue(); |
179 | 0 | if ((pickerValue.toString().isEmpty()) && (previousProgramCode != null) && (!previousProgramCode.getText().isEmpty())) { |
180 | 0 | return new Data.StringValue(previousProgramId); |
181 | |
} |
182 | |
|
183 | 0 | return pickerValue; |
184 | |
} |
185 | |
} |