1 | |
package org.kuali.student.core.comments.ui.client.widgets.decisiontool; |
2 | |
|
3 | |
import java.text.SimpleDateFormat; |
4 | |
import java.util.ArrayList; |
5 | |
import java.util.List; |
6 | |
import java.util.Map; |
7 | |
|
8 | |
import org.kuali.student.common.ui.client.application.Application; |
9 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
10 | |
import org.kuali.student.common.ui.client.configurable.mvc.HasReferenceId; |
11 | |
import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle; |
12 | |
import org.kuali.student.common.ui.client.configurable.mvc.ToolView; |
13 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
14 | |
import org.kuali.student.common.ui.client.mvc.Controller; |
15 | |
import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; |
16 | |
import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel; |
17 | |
import org.kuali.student.common.ui.client.theme.Theme; |
18 | |
import org.kuali.student.common.ui.client.widgets.KSButton; |
19 | |
import org.kuali.student.common.ui.client.widgets.KSLightBox; |
20 | |
import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel; |
21 | |
import org.kuali.student.common.ui.client.widgets.searchtable.ResultRow; |
22 | |
import org.kuali.student.common.ui.client.widgets.table.scroll.Column; |
23 | |
import org.kuali.student.common.ui.client.widgets.table.scroll.DefaultTableModel; |
24 | |
import org.kuali.student.common.ui.client.widgets.table.scroll.Row; |
25 | |
import org.kuali.student.common.ui.client.widgets.table.scroll.RowComparator; |
26 | |
import org.kuali.student.common.ui.client.widgets.table.scroll.Table; |
27 | |
import org.kuali.student.core.comment.dto.CommentInfo; |
28 | |
import org.kuali.student.core.comments.ui.client.service.CommentRpcService; |
29 | |
import org.kuali.student.core.comments.ui.client.service.CommentRpcServiceAsync; |
30 | |
import org.kuali.student.core.organization.ui.client.mvc.model.MembershipInfo; |
31 | |
import org.kuali.student.core.organization.ui.client.service.OrgRpcService; |
32 | |
import org.kuali.student.core.organization.ui.client.service.OrgRpcServiceAsync; |
33 | |
import org.kuali.student.core.workflow.ui.client.widgets.WorkflowUtilities.DecisionRationaleDetail; |
34 | |
|
35 | |
import com.google.gwt.core.client.GWT; |
36 | |
import com.google.gwt.event.dom.client.ClickEvent; |
37 | |
import com.google.gwt.event.dom.client.ClickHandler; |
38 | |
import com.google.gwt.user.client.Window; |
39 | |
import com.google.gwt.user.client.ui.Image; |
40 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
41 | |
import com.google.gwt.user.client.ui.Widget; |
42 | |
|
43 | 0 | public class DecisionPanel implements HasReferenceId, ToolView { |
44 | |
|
45 | 0 | private CommentRpcServiceAsync commentServiceAsync = GWT |
46 | |
.create(CommentRpcService.class); |
47 | 0 | private OrgRpcServiceAsync orgProposalRpcServiceAsync = GWT |
48 | |
.create(OrgRpcService.class); |
49 | |
private String referenceId; |
50 | |
private String referenceTypeKey; |
51 | |
private String referenceType; |
52 | |
private String referenceState; |
53 | |
private Map referenceAttributes; |
54 | |
private KSLightBox commentLightBox; |
55 | |
private VerticalFlowPanel contentPanel; |
56 | |
private VerticalPanel titlePanel; |
57 | |
private VerticalPanel scrollPanel; |
58 | |
private SectionTitle title; |
59 | |
private SectionTitle proposalNameHeader; |
60 | |
private Table table; |
61 | |
private Controller controller; |
62 | |
private Enum<?> viewEnum; |
63 | |
private String viewName; |
64 | |
private String decisionTypeKey; |
65 | |
private ArrayList<String> personIds; |
66 | |
|
67 | |
private DefaultTableModel tableModel; |
68 | |
|
69 | |
public DecisionPanel(Enum<?> viewEnum, String viewName, |
70 | 0 | String decisionTypeKey) { |
71 | 0 | this.viewName = viewName; |
72 | 0 | this.viewEnum = viewEnum; |
73 | 0 | this.decisionTypeKey = decisionTypeKey; |
74 | 0 | init(); |
75 | 0 | } |
76 | |
|
77 | |
private void init() { |
78 | 0 | KSButton closeActionButton = new KSButton(getMessage("wrapperPanelClose")); |
79 | 0 | closeActionButton.addClickHandler(new ClickHandler() { |
80 | |
public void onClick(ClickEvent event) { |
81 | 0 | commentLightBox.hide(); |
82 | 0 | } |
83 | |
}); |
84 | 0 | if (commentLightBox == null) { |
85 | 0 | commentLightBox = new KSLightBox("Proposal Decisions"); |
86 | 0 | commentLightBox.addButton(closeActionButton); |
87 | |
} |
88 | 0 | scrollPanel = new VerticalPanel(); |
89 | 0 | contentPanel = new VerticalFlowPanel(); |
90 | |
|
91 | |
|
92 | 0 | table = new Table(); |
93 | 0 | table.getScrollPanel().setHeight("400px"); |
94 | 0 | table.setTableModel(tableModel); |
95 | 0 | scrollPanel.add(table); |
96 | |
|
97 | |
|
98 | 0 | contentPanel.add(scrollPanel); |
99 | |
|
100 | 0 | commentLightBox.setWidget(contentPanel); |
101 | 0 | commentLightBox.setMaxHeight(600); |
102 | |
|
103 | 0 | } |
104 | |
|
105 | |
private void referesh() { |
106 | 0 | contentPanel.clear(); |
107 | 0 | init(); |
108 | 0 | StringBuilder titleTextSb = new StringBuilder(); |
109 | 0 | titleTextSb.append(referenceAttributes.get("name")); |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | 0 | getDecisions(); |
117 | 0 | } |
118 | |
|
119 | |
private void getDecisions() { |
120 | |
try { |
121 | 0 | commentServiceAsync.getComments(referenceId, referenceTypeKey, |
122 | 0 | new KSAsyncCallback<List<CommentInfo>>() { |
123 | |
|
124 | |
@Override |
125 | |
public void onSuccess(final List<CommentInfo> result) { |
126 | 0 | if(result==null||result.isEmpty()){ |
127 | 0 | initializeDecisionTable(); |
128 | |
|
129 | |
} |
130 | |
else{ |
131 | 0 | getPersonNames(result); |
132 | |
} |
133 | |
|
134 | 0 | } |
135 | |
|
136 | |
}); |
137 | 0 | } catch (Exception e) { |
138 | 0 | Window.alert("Failed to refresh Comments"); |
139 | 0 | GWT.log("refresh Comments Failed", e); |
140 | 0 | } |
141 | 0 | } |
142 | |
|
143 | |
private void getPersonNames(final List<CommentInfo> comments) { |
144 | 0 | personIds = new ArrayList<String>(); |
145 | 0 | for (CommentInfo comment : comments) { |
146 | 0 | if(comment.getMetaInfo().getCreateId()!=null){ |
147 | 0 | personIds.add(comment.getMetaInfo().getCreateId()); |
148 | |
} |
149 | |
else{ |
150 | 0 | personIds.add(""); |
151 | |
} |
152 | |
} |
153 | |
|
154 | 0 | orgProposalRpcServiceAsync.getNamesForPersonIds(personIds, |
155 | 0 | new KSAsyncCallback<Map<String, MembershipInfo>>() { |
156 | |
|
157 | |
@Override |
158 | |
public void onSuccess(Map<String, MembershipInfo> members) { |
159 | 0 | redrawDecisionTable(comments, members); |
160 | |
|
161 | 0 | } |
162 | |
}); |
163 | |
|
164 | |
|
165 | |
|
166 | 0 | } |
167 | |
|
168 | |
private void redrawDecisionTable(List<CommentInfo> commentInfos, |
169 | |
Map<String, MembershipInfo> members) { |
170 | 0 | if (commentInfos != null) { |
171 | 0 | int rowIndex = 0; |
172 | 0 | for (final CommentInfo commentInfo : commentInfos) { |
173 | |
|
174 | |
|
175 | |
|
176 | 0 | DecisionRationaleDetail drDetails = DecisionRationaleDetail.getByType(commentInfo.getType()); |
177 | 0 | if (drDetails != null) { |
178 | 0 | int columnIndex = 0; |
179 | 0 | if (rowIndex == 0) { |
180 | 0 | initializeDecisionTable(); |
181 | 0 | rowIndex++; |
182 | |
} |
183 | 0 | ResultRow theRow = new ResultRow(); |
184 | 0 | theRow.setId(commentInfo.getId()); |
185 | 0 | theRow.setValue("Decision", drDetails.getLabel()); |
186 | 0 | SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy"); |
187 | 0 | StringBuilder rationaleDate = new StringBuilder(dateformat |
188 | |
.format(commentInfo.getMetaInfo().getCreateTime())); |
189 | |
|
190 | 0 | theRow.setId(commentInfo.getId()); |
191 | 0 | theRow.setValue("Date", rationaleDate.toString()); |
192 | |
|
193 | 0 | if (members.get(commentInfo.getMetaInfo().getCreateId()) != null) { |
194 | 0 | MembershipInfo memberInfo = members.get(commentInfo |
195 | |
.getMetaInfo().getCreateId()); |
196 | 0 | StringBuilder memberName = new StringBuilder(); |
197 | 0 | memberName.append(memberInfo.getFirstName()); |
198 | 0 | memberName.append(" "); |
199 | 0 | memberName.append(memberInfo.getLastName()); |
200 | 0 | theRow.setId(commentInfo.getId()); |
201 | 0 | theRow.setValue("Actor", memberName.toString()); |
202 | |
} |
203 | 0 | theRow.setId(commentInfo.getId()); |
204 | 0 | theRow.setValue("Rationale", commentInfo.getCommentText() |
205 | |
.getPlain()); |
206 | |
|
207 | 0 | tableModel.addRow(new RationaleRow(theRow)); |
208 | |
} |
209 | 0 | } |
210 | 0 | tableModel.fireTableDataChanged(); |
211 | |
|
212 | |
} |
213 | 0 | } |
214 | |
|
215 | |
class RationaleRow extends Row { |
216 | |
|
217 | |
ResultRow row; |
218 | |
|
219 | 0 | public RationaleRow(ResultRow row) { |
220 | 0 | this.row = row; |
221 | 0 | } |
222 | |
|
223 | |
@Override |
224 | |
public Object getCellData(String columnId) { |
225 | 0 | return row.getValue(columnId); |
226 | |
} |
227 | |
|
228 | |
@Override |
229 | |
public void setCellData(String columnId, Object newValue) { |
230 | 0 | row.setValue(columnId, newValue.toString()); |
231 | 0 | } |
232 | |
|
233 | |
@Override |
234 | |
public String toString() { |
235 | 0 | return row.toString(); |
236 | |
} |
237 | |
|
238 | |
public ResultRow getResultRow() { |
239 | 0 | return row; |
240 | |
} |
241 | |
} |
242 | |
|
243 | |
private void initializeDecisionTable() { |
244 | 0 | ArrayList<String> tableHeaderList = new ArrayList<String>(); |
245 | 0 | tableHeaderList.add("Decision"); |
246 | 0 | tableHeaderList.add("Date"); |
247 | 0 | tableHeaderList.add("Actor"); |
248 | 0 | tableHeaderList.add("Rationale"); |
249 | 0 | tableModel = new DefaultTableModel(); |
250 | |
|
251 | 0 | for (String tableHeader : tableHeaderList) { |
252 | 0 | Column col1 = new Column(); |
253 | 0 | col1.setId(tableHeader); |
254 | 0 | String header = Application.getApplicationContext().getUILabel("", |
255 | |
null, null, tableHeader); |
256 | 0 | col1.setName(header); |
257 | 0 | if (tableHeader.equals("Rationale")) { |
258 | 0 | col1.setWidth("200px"); |
259 | 0 | } else if (tableHeader.equals("Actor")) { |
260 | 0 | col1.setWidth("150px"); |
261 | |
} else { |
262 | 0 | col1.setWidth("100px"); |
263 | |
} |
264 | 0 | if (tableHeader.equals("Date")) { |
265 | 0 | col1.setAscendingRowComparator(new FieldAscendingRowComparator( |
266 | |
"Date")); |
267 | |
} |
268 | 0 | tableModel.addColumn(col1); |
269 | 0 | } |
270 | |
|
271 | 0 | table.setTableModel(tableModel); |
272 | 0 | } |
273 | |
|
274 | |
@Override |
275 | |
public String getReferenceId() { |
276 | |
|
277 | 0 | return this.referenceId; |
278 | |
} |
279 | |
|
280 | |
@Override |
281 | |
public String getReferenceState() { |
282 | |
|
283 | 0 | return this.referenceState; |
284 | |
} |
285 | |
|
286 | |
@Override |
287 | |
public String getReferenceType() { |
288 | |
|
289 | 0 | return this.referenceType; |
290 | |
} |
291 | |
|
292 | |
@Override |
293 | |
public String getReferenceTypeKey() { |
294 | |
|
295 | 0 | return this.referenceTypeKey; |
296 | |
} |
297 | |
|
298 | |
public Map getReferenceAttributes() { |
299 | 0 | return referenceAttributes; |
300 | |
} |
301 | |
|
302 | |
@Override |
303 | |
public void setReferenceId(String id) { |
304 | 0 | this.referenceId = id; |
305 | |
|
306 | 0 | } |
307 | |
|
308 | |
@Override |
309 | |
public void setReferenceState(String state) { |
310 | 0 | this.referenceState = state; |
311 | |
|
312 | 0 | } |
313 | |
|
314 | |
@Override |
315 | |
public void setReferenceType(String type) { |
316 | 0 | this.referenceType = type; |
317 | |
|
318 | 0 | } |
319 | |
|
320 | |
@Override |
321 | |
public void setReferenceTypeKey(String key) { |
322 | 0 | this.referenceTypeKey = key; |
323 | |
|
324 | 0 | } |
325 | |
|
326 | |
public void setReferenceAttributes(Map referenceAttributes) { |
327 | 0 | this.referenceAttributes = referenceAttributes; |
328 | 0 | } |
329 | |
|
330 | |
@Override |
331 | |
public Image getImage() { |
332 | |
|
333 | 0 | return Theme.INSTANCE.getCommonImages().getCommentIcon(); |
334 | |
} |
335 | |
|
336 | |
@Override |
337 | |
public Enum<?> getViewEnum() { |
338 | |
|
339 | 0 | return viewEnum; |
340 | |
} |
341 | |
|
342 | |
@Override |
343 | |
public void setController(Controller controller) { |
344 | |
|
345 | 0 | this.controller = controller; |
346 | 0 | } |
347 | |
|
348 | |
@Override |
349 | |
public Widget asWidget() { |
350 | |
|
351 | 0 | return commentLightBox.getWidget(); |
352 | |
} |
353 | |
|
354 | |
@Override |
355 | |
public boolean beforeHide() { |
356 | |
|
357 | 0 | return true; |
358 | |
} |
359 | |
|
360 | |
@Override |
361 | |
public void beforeShow(Callback<Boolean> onReadyCallback) { |
362 | 0 | onReadyCallback.exec(true); |
363 | |
|
364 | 0 | } |
365 | |
|
366 | |
@Override |
367 | |
public void clear() { |
368 | |
|
369 | 0 | } |
370 | |
|
371 | |
@Override |
372 | |
public Controller getController() { |
373 | |
|
374 | 0 | return this.controller; |
375 | |
} |
376 | |
|
377 | |
@Override |
378 | |
public String getName() { |
379 | |
|
380 | 0 | return this.viewName; |
381 | |
} |
382 | |
|
383 | |
@Override |
384 | |
public void updateModel() { |
385 | |
|
386 | 0 | } |
387 | |
|
388 | |
@Override |
389 | |
public String collectHistory(String historyStack) { |
390 | |
|
391 | 0 | return null; |
392 | |
} |
393 | |
|
394 | |
@Override |
395 | |
public void onHistoryEvent(String historyStack) { |
396 | |
|
397 | 0 | } |
398 | |
|
399 | |
@Override |
400 | |
public void collectBreadcrumbNames(List<String> names) { |
401 | |
|
402 | 0 | } |
403 | |
|
404 | |
public void show() { |
405 | 0 | controller.requestModel(ReferenceModel.class, |
406 | 0 | new ModelRequestCallback<ReferenceModel>() { |
407 | |
public void onModelReady(ReferenceModel model) { |
408 | 0 | setReferenceId(model.getReferenceId()); |
409 | 0 | setReferenceTypeKey(model.getReferenceTypeKey()); |
410 | 0 | setReferenceType(model.getReferenceType()); |
411 | 0 | setReferenceState(model.getReferenceState()); |
412 | 0 | setReferenceAttributes(model.getReferenceAttributes()); |
413 | |
|
414 | 0 | referesh(); |
415 | 0 | commentLightBox.show(); |
416 | 0 | } |
417 | |
|
418 | |
public void onRequestFail(Throwable cause) { |
419 | 0 | Window.alert(cause.toString()); |
420 | 0 | } |
421 | |
}); |
422 | 0 | } |
423 | |
private static String getMessage(final String messageId) { |
424 | 0 | return Application.getApplicationContext().getMessage(messageId); |
425 | |
} |
426 | |
|
427 | |
public boolean isExportButtonActive() { |
428 | 0 | return false; |
429 | |
} |
430 | |
|
431 | |
@Override |
432 | |
public void showExport(boolean show) { |
433 | |
|
434 | |
|
435 | 0 | } |
436 | |
} |
437 | |
|
438 | 0 | class FieldAscendingRowComparator extends RowComparator { |
439 | |
|
440 | |
String columnId; |
441 | |
|
442 | 0 | FieldAscendingRowComparator(String columnId) { |
443 | 0 | this.columnId = columnId; |
444 | 0 | } |
445 | |
|
446 | |
@Override |
447 | |
public int compare(Row row0, Row row1) { |
448 | |
String id0, id1; |
449 | |
|
450 | 0 | id0 = (String) row0.getCellData(columnId); |
451 | 0 | id1 = (String) row1.getCellData(columnId); |
452 | |
|
453 | 0 | return id0.compareTo(id1); |
454 | |
} |
455 | |
|
456 | |
} |
457 | |
|
458 | 0 | class FieldDescendingRowComparator extends RowComparator { |
459 | |
|
460 | |
String columnId; |
461 | |
|
462 | 0 | FieldDescendingRowComparator(String columnId) { |
463 | 0 | this.columnId = columnId; |
464 | 0 | } |
465 | |
|
466 | |
@Override |
467 | |
public int compare(Row row0, Row row1) { |
468 | |
String id0, id1; |
469 | |
|
470 | 0 | id0 = (String) row0.getCellData(columnId); |
471 | 0 | id1 = (String) row1.getCellData(columnId); |
472 | |
|
473 | 0 | return id1.compareTo(id0); |
474 | |
} |
475 | |
} |