Coverage Report - org.kuali.student.core.comments.ui.client.widgets.commenttool.CommentTool
 
Classes in this File Line Coverage Branch Coverage Complexity
CommentTool
0%
0/166
0%
0/28
2
CommentTool$1
0%
0/3
0%
0/2
2
CommentTool$10
0%
0/5
N/A
2
CommentTool$10$1
0%
0/6
N/A
2
CommentTool$10$1$1
0%
0/6
N/A
2
CommentTool$11
0%
0/7
0%
0/4
2
CommentTool$11$1
0%
0/6
0%
0/4
2
CommentTool$12
0%
0/18
0%
0/6
2
CommentTool$13
0%
0/1
N/A
2
CommentTool$2
0%
0/7
0%
0/4
2
CommentTool$3
0%
0/3
N/A
2
CommentTool$4
0%
0/3
N/A
2
CommentTool$5
0%
0/29
0%
0/5
2
CommentTool$5$1
0%
0/5
N/A
2
CommentTool$5$2
0%
0/6
N/A
2
CommentTool$6
0%
0/13
0%
0/6
2
CommentTool$7
0%
0/7
0%
0/4
2
CommentTool$8
0%
0/8
0%
0/3
2
CommentTool$9
0%
0/7
0%
0/4
2
CommentTool$EditMode
0%
0/2
N/A
2
 
 1  
 package org.kuali.student.core.comments.ui.client.widgets.commenttool;
 2  
 
 3  
 import java.text.DateFormat;
 4  
 import java.text.SimpleDateFormat;
 5  
 import java.util.ArrayList;
 6  
 import java.util.Collections;
 7  
 import java.util.Comparator;
 8  
 import java.util.Date;
 9  
 import java.util.List;
 10  
 import java.util.Map;
 11  
 
 12  
 import org.kuali.student.common.dto.RichTextInfo;
 13  
 import org.kuali.student.common.dto.StatusInfo;
 14  
 import org.kuali.student.common.dto.DtoConstants.DtoState;
 15  
 import org.kuali.student.common.ui.client.application.Application;
 16  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 17  
 import org.kuali.student.common.ui.client.configurable.mvc.HasReferenceId;
 18  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 19  
 import org.kuali.student.common.ui.client.mvc.Callback;
 20  
 import org.kuali.student.common.ui.client.mvc.Controller;
 21  
 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback;
 22  
 import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel;
 23  
 import org.kuali.student.common.ui.client.widgets.KSButton;
 24  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 25  
 import org.kuali.student.common.ui.client.widgets.KSLightBox;
 26  
 import org.kuali.student.common.ui.client.widgets.KSTextArea;
 27  
 import org.kuali.student.common.ui.client.widgets.KSButtonAbstract.ButtonStyle;
 28  
 import org.kuali.student.common.ui.client.widgets.buttongroups.OkGroup;
 29  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.OkEnum;
 30  
 import org.kuali.student.common.ui.client.widgets.dialog.ConfirmationDialog;
 31  
 import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
 32  
 import org.kuali.student.core.comment.dto.CommentInfo;
 33  
 import org.kuali.student.core.comments.ui.client.service.CommentRpcService;
 34  
 import org.kuali.student.core.comments.ui.client.service.CommentRpcServiceAsync;
 35  
 
 36  
 import com.google.gwt.core.client.GWT;
 37  
 import com.google.gwt.dom.client.Style;
 38  
 import com.google.gwt.event.dom.client.ClickEvent;
 39  
 import com.google.gwt.event.dom.client.ClickHandler;
 40  
 import com.google.gwt.event.dom.client.KeyUpEvent;
 41  
 import com.google.gwt.event.dom.client.KeyUpHandler;
 42  
 import com.google.gwt.user.client.Window;
 43  
 import com.google.gwt.user.client.rpc.AsyncCallback;
 44  
 import com.google.gwt.user.client.ui.FlexTable;
 45  
 import com.google.gwt.user.client.ui.FlowPanel;
 46  
 import com.google.gwt.user.client.ui.HTML;
 47  
 import com.google.gwt.user.client.ui.HorizontalPanel;
 48  
 import com.google.gwt.user.client.ui.Widget;
 49  
 
 50  0
 public class CommentTool implements HasReferenceId {
 51  
 
 52  0
     private CommentRpcServiceAsync commentServiceAsync = GWT.create(CommentRpcService.class);
 53  
     private String referenceId;
 54  
     private String referenceTypeKey;
 55  
     private String referenceType;
 56  
     private String referenceState;
 57  
     private KSLightBox commentLightBox;
 58  0
     private HTML loggedInUserNameHTML = new HTML();
 59  
     private String loggedInUserId;
 60  0
     private KSTextArea commentTextArea = new KSTextArea();
 61  0
     private KSButton cancelEditButton = new KSButton("Cancel");
 62  0
     private KSButton submitCommentButton = new KSButton("Submit");
 63  0
     private FlexTable commentsTableLayout = new FlexTable();
 64  0
     private static final DateFormat df = new SimpleDateFormat("MMMM dd, yyyy - hh:mmaaa");
 65  
     private Controller controller;    
 66  
     private Enum<?> viewEnum;
 67  
     private String viewName;    //View name is being used as menu item label   
 68  0
     VerticalFlowPanel loggedInLabelsPanel = new VerticalFlowPanel();
 69  0
     VerticalFlowPanel commentEditPanel = new VerticalFlowPanel();
 70  0
     KSLabel notAuthorizedToAddComments = new KSLabel("The document must be saved before Comments can be added.");
 71  0
     private EditMode editMode = EditMode.ADD_COMMENT;
 72  
     private CommentInfo selectedComment;
 73  0
     private List<Callback<EditMode>> editControlsCallbacks = new ArrayList<Callback<EditMode>>();
 74  
     private String commentTypeKey;
 75  
     private Map<String, String> referenceAttributes;
 76  0
     private KSLabel proposalTitle = new KSLabel();
 77  
     private String title;
 78  
     private HTML htmlLabel;
 79  
     private SectionTitle leaveACommentTitle;
 80  
     private HorizontalPanel commentSectionPanel;
 81  0
     private final KSButton editButton = new KSButton("Edit", ButtonStyle.DEFAULT_ANCHOR);
 82  0
     private final KSButton deleteButton = new KSButton("Delete", ButtonStyle.DEFAULT_ANCHOR);
 83  
     
 84  
 
 85  0
     public enum EditMode {
 86  0
         ADD_COMMENT, UPDATE_COMMENT, VIEW_COMMENT
 87  
     }
 88  
     
 89  0
     public CommentTool(Enum<?> viewEnum, String viewName, String commentTypeKey, String title) {
 90  0
         this.viewName = viewName;
 91  0
         this.viewEnum = viewEnum;
 92  0
         this.commentTypeKey = commentTypeKey;
 93  0
         this.title = title;
 94  0
         init();
 95  
         
 96  0
     }
 97  
     
 98  
     public Controller getController() {
 99  0
         return this.controller;
 100  
     }
 101  
 
 102  
 
 103  
     public void setController(Controller controller){
 104  0
         this.controller = controller;
 105  0
     }
 106  
 
 107  
     
 108  
     public Widget asWidget(){
 109  0
         return commentLightBox.getWidget();
 110  
     }
 111  
     
 112  0
     private OkGroup buttonPanel = new OkGroup(new Callback<OkEnum>(){
 113  
 
 114  
         @Override
 115  
         public void exec(OkEnum result) {
 116  0
             if(result == OkEnum.Ok){
 117  
             }
 118  
 
 119  0
         }
 120  
     });
 121  
     
 122  
     private void init() {
 123  0
         commentLightBox = new KSLightBox();
 124  0
         VerticalFlowPanel contentPanel = new VerticalFlowPanel();
 125  
         // light box title and instructions
 126  0
         SectionTitle title = SectionTitle.generateH2Title(this.title);
 127  0
         title.addStyleName("ks-layout-header");
 128  0
         htmlLabel = new HTML("<b>All comments posted here will be visible to authors, and " +
 129  
                         "to reviewers after you submit the proposal.</b>");
 130  0
         title.setStyleName("cluProposalTitleSection");
 131  0
         proposalTitle.setVisible(false);
 132  0
         contentPanel.add(proposalTitle);
 133  0
         contentPanel.add(title);
 134  0
         contentPanel.add(htmlLabel);
 135  
         
 136  
         // comments section title
 137  0
         leaveACommentTitle = SectionTitle.generateH3Title("Leave a Comment");
 138  0
         leaveACommentTitle.getElement().getStyle().setProperty("borderBottom", "1px solid #D8D8D8");
 139  0
         leaveACommentTitle.getElement().getStyle().setProperty("marginTop", "2em");
 140  0
         contentPanel.add(leaveACommentTitle);
 141  
         
 142  
         // comments section
 143  0
         HTML loggedInAsLabel = new HTML("<b>Logged in as:<b/>");
 144  0
         loggedInLabelsPanel.add(loggedInAsLabel);
 145  0
         final String userId = Application.getApplicationContext().getUserId();
 146  0
         commentServiceAsync.getUserRealName(userId, new AsyncCallback<String>() {
 147  
             @Override
 148  
             public void onFailure(Throwable caught) {
 149  0
                 loggedInUserNameHTML.setHTML("<b>" + userId + "</b>");
 150  0
             }
 151  
             @Override
 152  
             public void onSuccess(String result) {
 153  0
                 if (result != null && !result.isEmpty()) {
 154  0
                     loggedInUserNameHTML.setHTML("<b>" + result + "</b>");
 155  
                 } else {
 156  0
                     loggedInUserNameHTML.setHTML("<b>" + userId + "</b>");
 157  
                 }
 158  0
             }
 159  
         });
 160  
         
 161  0
         loggedInUserId = userId;
 162  0
         loggedInLabelsPanel.add(loggedInUserNameHTML);
 163  0
         commentTextArea.setSize("500", "100");
 164  0
         commentEditPanel.add(commentTextArea);
 165  0
         FlowPanel buttonsPanel = new FlowPanel();
 166  0
         buttonsPanel.add(cancelEditButton);
 167  0
         cancelEditButton.addClickHandler(new ClickHandler() {
 168  
             @Override
 169  
             public void onClick(ClickEvent event) {
 170  0
                 setEditMode(EditMode.ADD_COMMENT);
 171  0
             }
 172  
         });
 173  0
         buttonsPanel.add(submitCommentButton);
 174  0
         submitCommentButton.setEnabled(false);
 175  0
         commentEditPanel.add(buttonsPanel);
 176  0
         buttonsPanel.addStyleName("KS-Comment-Button-Panel");
 177  
         
 178  0
         commentTextArea.addKeyUpHandler(new KeyUpHandler() {
 179  
             @Override
 180  
             public void onKeyUp(KeyUpEvent event) {
 181  0
                 submitCommentButton.setEnabled(true);
 182  0
             }
 183  
         });
 184  
         
 185  
         // if edit mode is add coment call addComment
 186  
         // if edit mode is edit comment call updateComment
 187  0
         submitCommentButton.addClickHandler(new ClickHandler() {
 188  
             @Override
 189  
             public void onClick(ClickEvent event) {
 190  0
                 switch (editMode) {
 191  
                     case ADD_COMMENT: {
 192  0
                         CommentInfo newComment = new CommentInfo();
 193  
 
 194  0
                         RichTextInfo text = new RichTextInfo();
 195  0
                         text.setFormatted(commentTextArea.getText());
 196  0
                         text.setPlain(commentTextArea.getText());
 197  0
                         newComment.setType(commentTypeKey);
 198  0
                         newComment.setReferenceId(referenceId);
 199  0
                         newComment.setReferenceTypeKey(referenceTypeKey);
 200  0
                         newComment.setState(DtoState.ACTIVE.toString());
 201  0
                         newComment.setCommentText(text);
 202  
 
 203  
                         try {
 204  0
                             commentServiceAsync.addComment(referenceId, referenceTypeKey, newComment, new KSAsyncCallback<CommentInfo>(){
 205  
 
 206  
                                 @Override
 207  
                                 public void handleFailure(Throwable caught) {
 208  0
                                     GWT.log("Add Comment Failed", caught);
 209  0
                                 }
 210  
 
 211  
                                 @Override
 212  
                                 public void onSuccess(CommentInfo result) {
 213  0
                                     refreshComments();
 214  0
                                 }
 215  
                             });
 216  0
                         } catch (Exception e) {
 217  0
                             GWT.log("Add Comment Failed", e);
 218  0
                         }
 219  0
                         break;
 220  
                     }
 221  
                     case UPDATE_COMMENT: {
 222  0
                         if (selectedComment != null) {
 223  0
                             RichTextInfo text = new RichTextInfo();
 224  0
                             text.setFormatted(commentTextArea.getText());
 225  0
                             text.setPlain(commentTextArea.getText());
 226  0
                             selectedComment.setReferenceId(referenceId);
 227  0
                             selectedComment.setReferenceTypeKey(referenceTypeKey);
 228  0
                             selectedComment.setCommentText(text);
 229  
 //                            selectedComment.setType("commentType." + referenceType + "." + referenceState);
 230  0
                             selectedComment.setType(commentTypeKey);
 231  
                         }
 232  
 
 233  
                         try {
 234  0
                             commentServiceAsync.updateComment(referenceId, referenceTypeKey, selectedComment, new KSAsyncCallback<CommentInfo>(){
 235  
 
 236  
                                 @Override
 237  
                                 public void handleFailure(Throwable caught) {
 238  0
                                     GWT.log("Add Comment Failed", caught);
 239  0
                                 }
 240  
 
 241  
                                 @Override
 242  
                                 public void onSuccess(CommentInfo result) {
 243  0
                                     refreshComments();
 244  0
                                     setEditMode(EditMode.ADD_COMMENT);
 245  0
                                 }
 246  
                             });
 247  0
                         } catch (Exception e) {
 248  0
                             GWT.log("Add Comment Failed", e);
 249  0
                         }
 250  
                         break;
 251  
                     }
 252  
                 }
 253  0
             }
 254  
         });
 255  
         
 256  0
         commentSectionPanel = new HorizontalPanel();
 257  0
         commentSectionPanel.add(loggedInLabelsPanel);
 258  0
         commentSectionPanel.add(commentEditPanel);
 259  0
         commentSectionPanel.add(notAuthorizedToAddComments);
 260  0
         contentPanel.add(commentSectionPanel);
 261  
         
 262  
         // comments table
 263  0
         contentPanel.add(commentsTableLayout);
 264  
         
 265  
         
 266  
 //        scrollPanel.setHeight(height)
 267  
         
 268  0
         commentLightBox.setWidget(contentPanel);
 269  0
         setEditMode(EditMode.ADD_COMMENT);
 270  0
     }
 271  
     
 272  
     private void checkPermissionsAndRedrawTable(final List<CommentInfo> commentInfos) {
 273  
         // check permission to see if user can comment
 274  0
         commentServiceAsync.isAuthorizedAddComment(referenceId, referenceTypeKey, new KSAsyncCallback<Boolean>() {
 275  
 
 276  
             @Override
 277  
             public void onFailure(Throwable caught) {
 278  0
                 GWT.log("Error checking permission for adding comments: ", caught);
 279  0
                 throw new RuntimeException("Error checking Permissions: ", caught);
 280  
             }
 281  
 
 282  
             @Override
 283  
             public void onSuccess(Boolean result) {
 284  0
                 GWT.log("User is " + ((result) ? "" : "not ") + 
 285  
                         "authorized to add comment.", null);
 286  0
                 if(referenceId != null && !(referenceId.isEmpty())){
 287  0
                     notAuthorizedToAddComments.setVisible(false);
 288  0
                     commentEditPanel.setVisible(result);
 289  0
                     commentsTableLayout.setVisible(true);
 290  0
                     redrawCommentsTable(commentInfos);
 291  
                 }
 292  
                 else{
 293  0
                     notAuthorizedToAddComments.setVisible(true);
 294  0
                     commentEditPanel.setVisible(false);
 295  0
                     commentsTableLayout.setVisible(false);
 296  
                 }
 297  0
             }
 298  
 
 299  
         });
 300  0
     }
 301  
     
 302  
     private void redrawCommentsTable(List<CommentInfo> commentInfos) {
 303  0
         commentsTableLayout.clear();
 304  0
         editControlsCallbacks.clear();
 305  
         
 306  0
         if (commentInfos != null) {
 307  0
             int rowIndex = 0;
 308  0
             int commentCounter = 0;
 309  0
             for (final CommentInfo commentInfo : commentInfos) {
 310  0
                 int columnIndex = 0;
 311  0
                 if (commentInfo.getType() != null && 
 312  
                         commentInfo.getType().startsWith("kuali.comment.type.workflowDecisionRationale")) {
 313  
                     // do not display comments for workflow decision rationale.
 314  0
                     continue;
 315  
                 }
 316  0
                 if (rowIndex == 0) {
 317  0
                     StringBuilder titleTextSb = new StringBuilder();
 318  0
                     titleTextSb.append("Comments (").append(commentInfos.size()).append(")");
 319  0
                     SectionTitle commentsSectionHeader = SectionTitle.generateH3Title(titleTextSb.toString());
 320  0
                     commentsSectionHeader.getElement().getStyle().setProperty("borderBottom", "1px solid #D8D8D8");
 321  0
                     commentsTableLayout.setWidget(rowIndex, columnIndex, commentsSectionHeader);
 322  0
                     commentsTableLayout.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 3);
 323  0
                     rowIndex++;
 324  
                 }
 325  0
                 if (commentCounter > 0) {
 326  0
                     VerticalFlowPanel space = new VerticalFlowPanel();
 327  0
                     space.getElement().getStyle().setPaddingBottom(5d, Style.Unit.PX);
 328  0
                     commentsTableLayout.setWidget(rowIndex, columnIndex, space);
 329  0
                     commentsTableLayout.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 3);
 330  0
                     rowIndex++;
 331  
                 }
 332  0
                 VerticalFlowPanel userNameAndTime = new VerticalFlowPanel();
 333  0
                 final HTML userNameLabel = new HTML();
 334  
                 // TODO use user id for now change to user name
 335  0
                 final String userId = commentInfo.getMetaInfo().getUpdateId();
 336  0
                 commentServiceAsync.getUserRealName(userId, new AsyncCallback<String>() {
 337  
                     @Override
 338  
                     public void onFailure(Throwable caught) {
 339  0
                         userNameLabel.setHTML("<b>" + userId + "</b>");
 340  0
                     }
 341  
                     @Override
 342  
                     public void onSuccess(String result) {
 343  0
                         if (result != null && !result.isEmpty()) {
 344  0
                             userNameLabel.setHTML("<b>" + result + "</b>");
 345  
                         } else {
 346  0
                             userNameLabel.setHTML("<b>" + userId + "</b>");
 347  
                         }
 348  0
                     }
 349  
                 });
 350  0
                 Date createTime = commentInfo.getMetaInfo().getCreateTime();
 351  0
                 userNameAndTime.add(userNameLabel);
 352  0
                 userNameAndTime.add(new KSLabel(df.format(createTime)));
 353  0
                 userNameAndTime.getElement().getStyle().setPaddingRight(20d, Style.Unit.PX);
 354  0
                 commentsTableLayout.setWidget(rowIndex, columnIndex, userNameAndTime);
 355  0
                 columnIndex++;
 356  
                 
 357  0
                 RichTextInfo commentRT = commentInfo.getCommentText();
 358  0
                 String commentText = commentRT.getPlain();
 359  0
                 KSLabel commentTextLabel = new KSLabel(commentText);
 360  0
                 commentTextLabel.getElement().getStyle().setPaddingRight(20d, Style.Unit.PX);
 361  0
                 commentTextLabel.setWidth("120px");
 362  0
                 commentTextLabel.getElement().getStyle().setProperty("wordWrap", "break-word");
 363  0
                 commentsTableLayout.setWidget(rowIndex, columnIndex, commentTextLabel);
 364  0
                 columnIndex++;
 365  0
                 editButton.getElement().getStyle().setPadding(5d, Style.Unit.PX);
 366  0
                 editControlsCallbacks.add(new Callback<EditMode>() {
 367  
                     @Override
 368  
                     public void exec(EditMode result) {
 369  0
                         switch (editMode) {
 370  
                             case UPDATE_COMMENT:
 371  
 //                                editButton.setStyleName("KS-CommentButtonDisabled");
 372  
 //                                deleteButton.setStyleName("KS-CommentButtonDisabled");
 373  0
                                 editButton.setEnabled(false);
 374  0
                                 deleteButton.setEnabled(false);
 375  0
                                 break;
 376  
                             case ADD_COMMENT:
 377  
 //                                editButton.setStyleName("KS-CommentButton");
 378  
 //                                deleteButton.setStyleName("KS-CommentButton");
 379  0
                                 editButton.setEnabled(true);
 380  0
                                 deleteButton.setEnabled(true);
 381  
                                 break;
 382  
                         }
 383  0
                     }
 384  
                 });
 385  
                 
 386  0
                 editButton.addClickHandler(new ClickHandler() {
 387  
                     @Override
 388  
                     public void onClick(ClickEvent event) {
 389  0
                         String commentText = (commentInfo == null ||
 390  
                                 commentInfo.getCommentText() == null)? "" :
 391  
                                     commentInfo.getCommentText().getPlain();
 392  0
                         selectedComment = commentInfo;
 393  0
                         commentTextArea.setText(commentText);
 394  0
                         commentTextArea.setFocus(true);
 395  0
                         setEditMode(EditMode.UPDATE_COMMENT);
 396  0
                     }
 397  
                 });
 398  0
                 deleteButton.addClickHandler(new ClickHandler() {
 399  
                     @Override
 400  
                     public void onClick(ClickEvent event) {
 401  0
                             final ConfirmationDialog confirmDeletion =
 402  
                                 new ConfirmationDialog("Delete Comment",  
 403  
                                     "You are about to delete a comment.  Are you sure?");
 404  0
                             confirmDeletion.getConfirmButton().addClickHandler(new ClickHandler(){
 405  
                                 @Override
 406  
                                 public void onClick(ClickEvent event) {
 407  
                                     try {
 408  0
                                         commentServiceAsync.removeComment(commentInfo.getId(), 
 409  
                                                 referenceId, referenceTypeKey, 
 410  0
                                                 new KSAsyncCallback<StatusInfo>(){
 411  
 
 412  
                                             @Override
 413  
                                             public void handleFailure(Throwable caught) {
 414  0
                                                 GWT.log("remove Comment Failed", caught);
 415  0
                                             }
 416  
 
 417  
                                             @Override
 418  
                                             public void onSuccess(StatusInfo result) {
 419  0
                                                 confirmDeletion.hide();
 420  0
                                                 refreshComments();
 421  0
                                             }
 422  
 
 423  
                                         });
 424  0
                                     } catch (Exception e) {
 425  0
                                         GWT.log("remove Comment Failed", e);
 426  0
                                     }
 427  0
                                 }
 428  
                             });
 429  0
                             confirmDeletion.show();
 430  0
                     }
 431  
                 });
 432  0
                 commentsTableLayout.setWidget(rowIndex, columnIndex, editButton);
 433  0
                 columnIndex++;
 434  0
                 commentsTableLayout.setWidget(rowIndex, columnIndex, deleteButton);
 435  0
                 columnIndex++;
 436  0
                 if (userId == null || !userId.equals(this.loggedInUserId)) {
 437  0
                     editButton.setVisible(false);
 438  0
                     deleteButton.setVisible(false);
 439  
                 }
 440  
                 
 441  0
                 rowIndex++;
 442  
                 
 443  0
                 commentCounter++;
 444  0
             }
 445  0
             setEditMode(EditMode.ADD_COMMENT);
 446  
         }
 447  0
     }
 448  
     
 449  
     public void setEditMode(EditMode editMode) {
 450  0
         this.editMode = editMode;
 451  0
         switch (editMode) {
 452  
             case UPDATE_COMMENT:
 453  0
                 cancelEditButton.setVisible(true);
 454  0
                 if (editControlsCallbacks != null) {
 455  0
                     for (Callback<EditMode> callback : editControlsCallbacks) {
 456  0
                         callback.exec(EditMode.UPDATE_COMMENT);
 457  
                     }
 458  
                 }
 459  
                 break;
 460  
             case ADD_COMMENT:
 461  0
                 cancelEditButton.setVisible(false);
 462  0
                 commentTextArea.setText("");
 463  0
                 if (editControlsCallbacks != null) {
 464  0
                     for (Callback<EditMode> callback : editControlsCallbacks) {
 465  0
                         callback.exec(EditMode.ADD_COMMENT);
 466  
                     }
 467  
                 }
 468  
                 break;
 469  
             case VIEW_COMMENT:
 470  0
                 htmlLabel.setVisible(false);
 471  0
                 leaveACommentTitle.setVisible(false);
 472  0
                 commentSectionPanel.setVisible(false);
 473  0
                 editButton.setVisible(false);
 474  0
                 deleteButton.setVisible(false);
 475  
                 break;
 476  
         }
 477  0
     }
 478  
     
 479  
     public void refreshComments(){
 480  
         //rpc call to get all current comments and populate into comment list
 481  
         try {
 482  0
             commentServiceAsync.getComments(referenceId, referenceTypeKey, new KSAsyncCallback<List<CommentInfo>>(){
 483  
 
 484  
                 @Override
 485  
                 public void handleFailure(Throwable caught) {
 486  0
                     GWT.log("getComments failed", caught);
 487  0
                 }
 488  
 
 489  
                 @Override
 490  
                 public void onSuccess(List<CommentInfo> result) {
 491  0
                     if (result != null && !result.isEmpty()) {
 492  0
                         Collections.sort(result, new Comparator<CommentInfo>(){
 493  
 
 494  
                             @Override
 495  
                             public int compare(CommentInfo comment1, CommentInfo comment2) {
 496  
 
 497  0
                                 if(comment1.getMetaInfo().getCreateTime().after(comment2.getMetaInfo().getCreateTime())){
 498  0
                                     return -1;
 499  
                                 }
 500  0
                                 else if(comment1.getMetaInfo().getCreateTime().before(comment2.getMetaInfo().getCreateTime())){
 501  0
                                     return 1;
 502  
                                 }
 503  
                                 else{
 504  
                                     //equal
 505  0
                                     return 0;
 506  
                                 }
 507  
 
 508  
                             }
 509  
                         });
 510  
                     }
 511  0
                     checkPermissionsAndRedrawTable(result);
 512  0
                 }
 513  
             });
 514  0
         } catch (Exception e) {
 515  0
             Window.alert("Failed to refresh Comments");
 516  0
             GWT.log("refresh Comments Failed",e);
 517  0
         }
 518  
 
 519  
 
 520  0
     }
 521  
 //    private void redrawCommentsTable(FlexTable tableLayout) {
 522  
 //        StringBuilder titleTextSb = new StringBuilder();
 523  
 //        titleTextSb.append("Comments (").append(docInfos.size()).append(")");
 524  
 //        SectionTitle uploadedFileSectionHeader = SectionTitle.generateH3Title(titleTextSb.toString());
 525  
 //        uploadedFileSectionHeader.getElement().getStyle().setProperty("borderBottom", "1px solid #D8D8D8");
 526  
 //        tableLayout.setWidget(rowIndex, columnIndex, uploadedFileSectionHeader);
 527  
 //        tableLayout.getFlexCellFormatter().setColSpan(rowIndex, columnIndex, 3);
 528  
 //    }
 529  
     
 530  
     @Override
 531  
     public String getReferenceId() {
 532  0
         return referenceId;
 533  
     }
 534  
 
 535  
     @Override
 536  
     public String getReferenceState() {
 537  0
         return referenceState;
 538  
     }
 539  
 
 540  
     @Override
 541  
     public String getReferenceType() {
 542  0
         return referenceType;
 543  
     }
 544  
 
 545  
     @Override
 546  
     public String getReferenceTypeKey() {
 547  0
         return referenceTypeKey;
 548  
     }
 549  
 
 550  
     @Override
 551  
     public void setReferenceId(String id) {
 552  0
         this.referenceId = id;
 553  0
     }
 554  
 
 555  
     @Override
 556  
     public void setReferenceState(String state) {
 557  0
         this.referenceState = state;
 558  0
     }
 559  
 
 560  
     @Override
 561  
     public void setReferenceType(String type) {
 562  0
         this.referenceType = type;
 563  0
     }
 564  
 
 565  
     @Override
 566  
     public void setReferenceTypeKey(String key) {
 567  0
         this.referenceTypeKey = key;
 568  0
     }
 569  
     
 570  
     public void setReferenceAttributes(Map<String, String> referenceAttributes) {
 571  0
         this.referenceAttributes = referenceAttributes;
 572  0
     }
 573  
     
 574  
     public void show() {
 575  0
         controller.requestModel(ReferenceModel.class, 
 576  0
                 new ModelRequestCallback<ReferenceModel>(){
 577  
             public void onModelReady(ReferenceModel model) {
 578  0
                 String proposalTitleString = null;
 579  0
                 setReferenceId(model.getReferenceId());
 580  0
                 setReferenceTypeKey(model.getReferenceTypeKey());
 581  0
                 setReferenceType(model.getReferenceType());
 582  0
                 setReferenceState(model.getReferenceState());
 583  0
                 setReferenceAttributes(model.getReferenceAttributes());
 584  0
                 proposalTitleString = (model.getReferenceAttributes() == null)? null : 
 585  
                     model.getReferenceAttributes().get("name");
 586  0
                 if (proposalTitleString != null && !proposalTitleString.trim().isEmpty()) {
 587  0
                     proposalTitle.setText(proposalTitleString);
 588  0
                     proposalTitle.setVisible(true);
 589  
                 } else {
 590  0
                     proposalTitle.setText("");
 591  0
                     proposalTitle.setVisible(false);
 592  
                 }
 593  0
                 refreshComments();
 594  0
                 commentLightBox.show();
 595  0
             }
 596  
 
 597  
             public void onRequestFail(Throwable cause) {
 598  0
                 Window.alert(cause.toString());
 599  0
             }
 600  
         });
 601  0
     }
 602  
 
 603  
 }