1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.lum.common.client.lo; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.List; |
20 | |
|
21 | |
import org.kuali.student.common.ui.client.application.Application; |
22 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
23 | |
import org.kuali.student.common.ui.client.widgets.KSLabel; |
24 | |
import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle; |
25 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent; |
26 | |
import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler; |
27 | |
import org.kuali.student.common.ui.client.widgets.search.KSPicker; |
28 | |
import org.kuali.student.core.assembly.data.Metadata; |
29 | |
import org.kuali.student.lum.common.client.lu.LUUIConstants; |
30 | |
|
31 | |
import com.google.gwt.event.dom.client.ChangeEvent; |
32 | |
import com.google.gwt.event.dom.client.ChangeHandler; |
33 | |
import com.google.gwt.event.dom.client.ClickEvent; |
34 | |
import com.google.gwt.event.dom.client.ClickHandler; |
35 | |
import com.google.gwt.event.logical.shared.ValueChangeEvent; |
36 | |
import com.google.gwt.event.logical.shared.ValueChangeHandler; |
37 | |
import com.google.gwt.event.shared.HandlerRegistration; |
38 | |
import com.google.gwt.user.client.ui.Composite; |
39 | |
import com.google.gwt.user.client.ui.HasValue; |
40 | |
import com.google.gwt.user.client.ui.HorizontalPanel; |
41 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public class LOBuilder extends Composite implements HasValue<List<OutlineNode<LOPicker>>> { |
56 | |
|
57 | |
private static String type; |
58 | |
private static String state; |
59 | |
private static String repoKey; |
60 | |
private static String messageGroup; |
61 | |
|
62 | 0 | VerticalPanel main = new VerticalPanel(); |
63 | 0 | HorizontalPanel searchMainPanel = new HorizontalPanel(); |
64 | |
KSPicker searchWindow; |
65 | 0 | VerticalPanel loPanel = new VerticalPanel(); |
66 | |
|
67 | |
LearningObjectiveList loList; |
68 | |
KSLabel instructions; |
69 | |
|
70 | 0 | protected LOBuilder() { |
71 | 0 | } |
72 | |
|
73 | |
public LOBuilder(String luType, String luState, String luGroup, String loRepoKey, final Metadata metadata) { |
74 | 0 | super(); |
75 | 0 | initWidget(main); |
76 | |
|
77 | 0 | type = luType; |
78 | 0 | state = luState; |
79 | 0 | repoKey = loRepoKey; |
80 | 0 | messageGroup = luGroup; |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | 0 | instructions = new KSLabel(getLabel(LUUIConstants.LO_INSTRUCTIONS_KEY)); |
106 | |
|
107 | 0 | loList = new LearningObjectiveList(); |
108 | 0 | loPanel.add(loList); |
109 | |
|
110 | |
|
111 | 0 | searchMainPanel.addStyleName("KS-LOBuilder-Search-Panel"); |
112 | 0 | loPanel.addStyleName("KS-LOBuilder-LO-Panel"); |
113 | 0 | instructions.addStyleName("KS-LOBuilder-Instructions"); |
114 | |
|
115 | 0 | main.add(searchMainPanel); |
116 | 0 | main.add(instructions); |
117 | 0 | main.add(loPanel); |
118 | 0 | } |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
@Override |
125 | |
public void setValue(List<OutlineNode<LOPicker>> value, boolean fireEvents) { |
126 | 0 | setValue(value); |
127 | 0 | } |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
@Override |
133 | |
public void setValue(List<OutlineNode<LOPicker>> data) { |
134 | 0 | loList.setValue(data); |
135 | 0 | } |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
@Override |
141 | |
public List<OutlineNode<LOPicker>> getValue() { |
142 | 0 | return loList.getValue(); |
143 | |
} |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
@Override |
149 | |
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<List<OutlineNode<LOPicker>>> handler) { |
150 | 0 | return loList.addValueChangeHandler(handler); |
151 | |
} |
152 | |
|
153 | |
private static String getLabel(String labelKey) { |
154 | 0 | return Application.getApplicationContext().getUILabel(messageGroup, |
155 | |
type, state, labelKey); |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
public static String getType() { |
162 | 0 | return type; |
163 | |
} |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public static String getState() { |
169 | 0 | return state; |
170 | |
} |
171 | |
|
172 | |
public static String getRepoKey() { |
173 | 0 | return repoKey; |
174 | |
} |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
public static String getMessageGroup() { |
180 | 0 | return messageGroup; |
181 | |
} |
182 | |
|
183 | 0 | public static class LearningObjectiveList extends Composite implements HasValue<List<OutlineNode<LOPicker>>> { |
184 | 0 | OutlineNodeModel<LOPicker> outlineModel = new OutlineNodeModel<LOPicker>(); |
185 | 0 | OutlineManager outlineComposite = new OutlineManager(); |
186 | 0 | VerticalPanel mainPanel = new VerticalPanel(); |
187 | |
|
188 | 0 | SelectionChangeHandler loPickerChangeHandler = new SelectionChangeHandler(){ |
189 | |
public void onSelectionChange(SelectionChangeEvent event) { |
190 | 0 | fireChangeEvent(); |
191 | 0 | } |
192 | |
}; |
193 | |
|
194 | 0 | public LearningObjectiveList() { |
195 | 0 | mainPanel.add(outlineComposite); |
196 | 0 | KSButton addnew = new KSButton("Add item",ButtonStyle.SECONDARY, new ClickHandler() { |
197 | |
public void onClick(ClickEvent event) { |
198 | 0 | setValue(getValue()); |
199 | 0 | appendLO(""); |
200 | 0 | reDraw(); |
201 | 0 | } |
202 | |
}); |
203 | |
|
204 | 0 | addnew.addStyleName("KS-LOBuilder-New"); |
205 | 0 | mainPanel.add(addnew); |
206 | 0 | super.initWidget(mainPanel); |
207 | |
|
208 | 0 | outlineComposite.setValue(outlineModel); |
209 | 0 | outlineModel.addChangeHandler(new ChangeHandler() { |
210 | |
public void onChange(ChangeEvent event) { |
211 | 0 | outlineComposite.render(); |
212 | 0 | fireChangeEvent(); |
213 | 0 | } |
214 | |
}); |
215 | |
|
216 | 0 | initEmptyLoList(); |
217 | 0 | } |
218 | |
|
219 | |
protected void initEmptyLoList(){ |
220 | 0 | List<String> list = new ArrayList<String>(); |
221 | 0 | list.add(""); |
222 | 0 | list.add(""); |
223 | 0 | list.add(""); |
224 | 0 | list.add(""); |
225 | 0 | list.add(""); |
226 | 0 | addSelectedLOs(list); |
227 | 0 | } |
228 | |
|
229 | |
protected void fireChangeEvent(){ |
230 | 0 | ValueChangeEvent.fire(this, outlineModel.getOutlineNodes()); |
231 | 0 | } |
232 | |
|
233 | |
public List<OutlineNode<LOPicker>> getValue() { |
234 | 0 | return outlineModel.getOutlineNodes(); |
235 | |
} |
236 | |
|
237 | |
public void setValue(List<OutlineNode<LOPicker>> value) { |
238 | 0 | outlineModel.clearNodes(); |
239 | 0 | outlineModel.getOutlineNodes().addAll(value); |
240 | |
|
241 | 0 | if (value == null || value.isEmpty()){ |
242 | 0 | initEmptyLoList(); |
243 | |
} else { |
244 | |
|
245 | 0 | for (OutlineNode<LOPicker> node:value){ |
246 | 0 | LOPicker picker = node.getUserObject(); |
247 | 0 | if (!picker.hasChangeHandler()){ |
248 | 0 | picker.addSelectionChangeHandler(loPickerChangeHandler); |
249 | |
} |
250 | 0 | } |
251 | |
|
252 | 0 | reDraw(); |
253 | |
} |
254 | 0 | } |
255 | |
|
256 | |
private void appendLO(String loValue) { |
257 | 0 | OutlineNode<LOPicker> aNode = new OutlineNode<LOPicker>(); |
258 | 0 | LOPicker newPicker = new LOPicker(messageGroup, type, state, |
259 | |
repoKey); |
260 | |
|
261 | 0 | newPicker.addSelectionChangeHandler(loPickerChangeHandler); |
262 | 0 | newPicker.setLOText(loValue); |
263 | 0 | aNode.setUserObject(newPicker); |
264 | 0 | aNode.setModel(outlineModel); |
265 | |
|
266 | 0 | outlineModel.addOutlineNode(aNode); |
267 | 0 | } |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
public void addSelectedLOs(List<String> loDescription) { |
273 | |
|
274 | 0 | List<OutlineNode<LOPicker>> existingLOs = outlineModel |
275 | |
.getOutlineNodes(); |
276 | |
|
277 | 0 | int ix = existingLOs.size(); |
278 | 0 | for (String strValue : loDescription) { |
279 | |
|
280 | 0 | boolean foundEmptyBox = false; |
281 | 0 | while (ix > 0) { |
282 | 0 | ix--; |
283 | 0 | if (existingLOs.get(ix).getUserObject().getLOText().trim() |
284 | |
.length() == 0) { |
285 | 0 | existingLOs.get(ix).getUserObject().setLOText(strValue); |
286 | 0 | foundEmptyBox = true; |
287 | 0 | break; |
288 | |
} |
289 | |
} |
290 | |
|
291 | |
|
292 | 0 | if (foundEmptyBox == false) { |
293 | 0 | appendLO(strValue); |
294 | |
} |
295 | 0 | } |
296 | 0 | reDraw(); |
297 | 0 | } |
298 | |
|
299 | |
private void reDraw() { |
300 | 0 | outlineComposite.render(); |
301 | 0 | } |
302 | |
|
303 | |
public HandlerRegistration addValueChangeHandler(ValueChangeHandler<List<OutlineNode<LOPicker>>> handler) { |
304 | 0 | return addHandler(handler, ValueChangeEvent.getType()); |
305 | |
} |
306 | |
|
307 | |
public SelectionChangeHandler getChangeHandlerForLOPicker(){ |
308 | 0 | return loPickerChangeHandler; |
309 | |
} |
310 | |
|
311 | |
@Override |
312 | |
public void setValue(List<OutlineNode<LOPicker>> value, |
313 | |
boolean fireEvents) { |
314 | 0 | setValue(value); |
315 | 0 | } |
316 | |
} |
317 | |
} |