| 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 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | 0 | if (tableModel == null){ |
| 215 | 0 | initializeDecisionTable(); |
| 216 | |
} |
| 217 | |
|
| 218 | 0 | tableModel.fireTableDataChanged(); |
| 219 | |
|
| 220 | |
} |
| 221 | 0 | } |
| 222 | |
|
| 223 | |
class RationaleRow extends Row { |
| 224 | |
|
| 225 | |
ResultRow row; |
| 226 | |
|
| 227 | 0 | public RationaleRow(ResultRow row) { |
| 228 | 0 | this.row = row; |
| 229 | 0 | } |
| 230 | |
|
| 231 | |
@Override |
| 232 | |
public Object getCellData(String columnId) { |
| 233 | 0 | return row.getValue(columnId); |
| 234 | |
} |
| 235 | |
|
| 236 | |
@Override |
| 237 | |
public void setCellData(String columnId, Object newValue) { |
| 238 | 0 | row.setValue(columnId, newValue.toString()); |
| 239 | 0 | } |
| 240 | |
|
| 241 | |
@Override |
| 242 | |
public String toString() { |
| 243 | 0 | return row.toString(); |
| 244 | |
} |
| 245 | |
|
| 246 | |
public ResultRow getResultRow() { |
| 247 | 0 | return row; |
| 248 | |
} |
| 249 | |
} |
| 250 | |
|
| 251 | |
private void initializeDecisionTable() { |
| 252 | 0 | ArrayList<String> tableHeaderList = new ArrayList<String>(); |
| 253 | 0 | tableHeaderList.add("Decision"); |
| 254 | 0 | tableHeaderList.add("Date"); |
| 255 | 0 | tableHeaderList.add("Actor"); |
| 256 | 0 | tableHeaderList.add("Rationale"); |
| 257 | 0 | tableModel = new DefaultTableModel(); |
| 258 | |
|
| 259 | 0 | for (String tableHeader : tableHeaderList) { |
| 260 | 0 | Column col1 = new Column(); |
| 261 | 0 | col1.setId(tableHeader); |
| 262 | 0 | String header = Application.getApplicationContext().getUILabel("", |
| 263 | |
null, null, tableHeader); |
| 264 | 0 | col1.setName(header); |
| 265 | 0 | if (tableHeader.equals("Rationale")) { |
| 266 | 0 | col1.setWidth("200px"); |
| 267 | 0 | } else if (tableHeader.equals("Actor")) { |
| 268 | 0 | col1.setWidth("150px"); |
| 269 | |
} else { |
| 270 | 0 | col1.setWidth("100px"); |
| 271 | |
} |
| 272 | 0 | if (tableHeader.equals("Date")) { |
| 273 | 0 | col1.setAscendingRowComparator(new FieldAscendingRowComparator( |
| 274 | |
"Date")); |
| 275 | |
} |
| 276 | 0 | tableModel.addColumn(col1); |
| 277 | 0 | } |
| 278 | |
|
| 279 | 0 | table.setTableModel(tableModel); |
| 280 | 0 | } |
| 281 | |
|
| 282 | |
@Override |
| 283 | |
public String getReferenceId() { |
| 284 | |
|
| 285 | 0 | return this.referenceId; |
| 286 | |
} |
| 287 | |
|
| 288 | |
@Override |
| 289 | |
public String getReferenceState() { |
| 290 | |
|
| 291 | 0 | return this.referenceState; |
| 292 | |
} |
| 293 | |
|
| 294 | |
@Override |
| 295 | |
public String getReferenceType() { |
| 296 | |
|
| 297 | 0 | return this.referenceType; |
| 298 | |
} |
| 299 | |
|
| 300 | |
@Override |
| 301 | |
public String getReferenceTypeKey() { |
| 302 | |
|
| 303 | 0 | return this.referenceTypeKey; |
| 304 | |
} |
| 305 | |
|
| 306 | |
public Map getReferenceAttributes() { |
| 307 | 0 | return referenceAttributes; |
| 308 | |
} |
| 309 | |
|
| 310 | |
@Override |
| 311 | |
public void setReferenceId(String id) { |
| 312 | 0 | this.referenceId = id; |
| 313 | |
|
| 314 | 0 | } |
| 315 | |
|
| 316 | |
@Override |
| 317 | |
public void setReferenceState(String state) { |
| 318 | 0 | this.referenceState = state; |
| 319 | |
|
| 320 | 0 | } |
| 321 | |
|
| 322 | |
@Override |
| 323 | |
public void setReferenceType(String type) { |
| 324 | 0 | this.referenceType = type; |
| 325 | |
|
| 326 | 0 | } |
| 327 | |
|
| 328 | |
@Override |
| 329 | |
public void setReferenceTypeKey(String key) { |
| 330 | 0 | this.referenceTypeKey = key; |
| 331 | |
|
| 332 | 0 | } |
| 333 | |
|
| 334 | |
public void setReferenceAttributes(Map referenceAttributes) { |
| 335 | 0 | this.referenceAttributes = referenceAttributes; |
| 336 | 0 | } |
| 337 | |
|
| 338 | |
@Override |
| 339 | |
public Image getImage() { |
| 340 | |
|
| 341 | 0 | return Theme.INSTANCE.getCommonImages().getCommentIcon(); |
| 342 | |
} |
| 343 | |
|
| 344 | |
@Override |
| 345 | |
public Enum<?> getViewEnum() { |
| 346 | |
|
| 347 | 0 | return viewEnum; |
| 348 | |
} |
| 349 | |
|
| 350 | |
@Override |
| 351 | |
public void setController(Controller controller) { |
| 352 | |
|
| 353 | 0 | this.controller = controller; |
| 354 | 0 | } |
| 355 | |
|
| 356 | |
@Override |
| 357 | |
public Widget asWidget() { |
| 358 | |
|
| 359 | 0 | return commentLightBox.getWidget(); |
| 360 | |
} |
| 361 | |
|
| 362 | |
@Override |
| 363 | |
public boolean beforeHide() { |
| 364 | |
|
| 365 | 0 | return true; |
| 366 | |
} |
| 367 | |
|
| 368 | |
@Override |
| 369 | |
public void beforeShow(Callback<Boolean> onReadyCallback) { |
| 370 | 0 | onReadyCallback.exec(true); |
| 371 | |
|
| 372 | 0 | } |
| 373 | |
|
| 374 | |
@Override |
| 375 | |
public void clear() { |
| 376 | |
|
| 377 | 0 | } |
| 378 | |
|
| 379 | |
@Override |
| 380 | |
public Controller getController() { |
| 381 | |
|
| 382 | 0 | return this.controller; |
| 383 | |
} |
| 384 | |
|
| 385 | |
@Override |
| 386 | |
public String getName() { |
| 387 | |
|
| 388 | 0 | return this.viewName; |
| 389 | |
} |
| 390 | |
|
| 391 | |
@Override |
| 392 | |
public void updateModel() { |
| 393 | |
|
| 394 | 0 | } |
| 395 | |
|
| 396 | |
@Override |
| 397 | |
public String collectHistory(String historyStack) { |
| 398 | |
|
| 399 | 0 | return null; |
| 400 | |
} |
| 401 | |
|
| 402 | |
@Override |
| 403 | |
public void onHistoryEvent(String historyStack) { |
| 404 | |
|
| 405 | 0 | } |
| 406 | |
|
| 407 | |
@Override |
| 408 | |
public void collectBreadcrumbNames(List<String> names) { |
| 409 | |
|
| 410 | 0 | } |
| 411 | |
|
| 412 | |
public void show() { |
| 413 | 0 | controller.requestModel(ReferenceModel.class, |
| 414 | 0 | new ModelRequestCallback<ReferenceModel>() { |
| 415 | |
public void onModelReady(ReferenceModel model) { |
| 416 | 0 | setReferenceId(model.getReferenceId()); |
| 417 | 0 | setReferenceTypeKey(model.getReferenceTypeKey()); |
| 418 | 0 | setReferenceType(model.getReferenceType()); |
| 419 | 0 | setReferenceState(model.getReferenceState()); |
| 420 | 0 | setReferenceAttributes(model.getReferenceAttributes()); |
| 421 | |
|
| 422 | 0 | referesh(); |
| 423 | 0 | commentLightBox.show(); |
| 424 | 0 | } |
| 425 | |
|
| 426 | |
public void onRequestFail(Throwable cause) { |
| 427 | 0 | Window.alert(cause.toString()); |
| 428 | 0 | } |
| 429 | |
}); |
| 430 | 0 | } |
| 431 | |
private static String getMessage(final String messageId) { |
| 432 | 0 | return Application.getApplicationContext().getMessage(messageId); |
| 433 | |
} |
| 434 | |
|
| 435 | |
public boolean isExportButtonActive() { |
| 436 | 0 | return false; |
| 437 | |
} |
| 438 | |
|
| 439 | |
@Override |
| 440 | |
public void showExport(boolean show) { |
| 441 | |
|
| 442 | |
|
| 443 | 0 | } |
| 444 | |
} |
| 445 | |
|
| 446 | 0 | class FieldAscendingRowComparator extends RowComparator { |
| 447 | |
|
| 448 | |
String columnId; |
| 449 | |
|
| 450 | 0 | FieldAscendingRowComparator(String columnId) { |
| 451 | 0 | this.columnId = columnId; |
| 452 | 0 | } |
| 453 | |
|
| 454 | |
@Override |
| 455 | |
public int compare(Row row0, Row row1) { |
| 456 | |
String id0, id1; |
| 457 | |
|
| 458 | 0 | id0 = (String) row0.getCellData(columnId); |
| 459 | 0 | id1 = (String) row1.getCellData(columnId); |
| 460 | |
|
| 461 | 0 | return id0.compareTo(id1); |
| 462 | |
} |
| 463 | |
|
| 464 | |
} |
| 465 | |
|
| 466 | 0 | class FieldDescendingRowComparator extends RowComparator { |
| 467 | |
|
| 468 | |
String columnId; |
| 469 | |
|
| 470 | 0 | FieldDescendingRowComparator(String columnId) { |
| 471 | 0 | this.columnId = columnId; |
| 472 | 0 | } |
| 473 | |
|
| 474 | |
@Override |
| 475 | |
public int compare(Row row0, Row row1) { |
| 476 | |
String id0, id1; |
| 477 | |
|
| 478 | 0 | id0 = (String) row0.getCellData(columnId); |
| 479 | 0 | id1 = (String) row1.getCellData(columnId); |
| 480 | |
|
| 481 | 0 | return id1.compareTo(id0); |
| 482 | |
} |
| 483 | |
} |