Coverage Report - org.kuali.student.common.ui.client.widgets.commenttool.CommentPanel
 
Classes in this File Line Coverage Branch Coverage Complexity
CommentPanel
0%
0/94
0%
0/10
1.773
CommentPanel$1
0%
0/6
0%
0/4
1.773
CommentPanel$2
0%
0/13
0%
0/2
1.773
CommentPanel$2$1
0%
0/11
0%
0/2
1.773
CommentPanel$3
0%
0/17
0%
0/4
1.773
CommentPanel$4
0%
0/3
N/A
1.773
CommentPanel$5
0%
0/13
0%
0/6
1.773
CommentPanel$6
0%
0/19
0%
0/6
1.773
CommentPanel$7
0%
0/19
0%
0/6
1.773
CommentPanel$8
0%
0/1
N/A
1.773
CommentPanel$Comment
0%
0/59
0%
0/8
1.773
CommentPanel$Comment$1
0%
0/12
N/A
1.773
CommentPanel$Comment$1$1
0%
0/14
0%
0/3
1.773
CommentPanel$Comment$1$1$1
0%
0/9
N/A
1.773
CommentPanel$Comment$2
0%
0/6
N/A
1.773
CommentPanel$Comment$2$1
0%
0/7
0%
0/2
1.773
 
 1  
 /**
 2  
  * Copyright 2010 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 package org.kuali.student.common.ui.client.widgets.commenttool;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collections;
 20  
 import java.util.Comparator;
 21  
 import java.util.List;
 22  
 
 23  
 import org.kuali.student.common.ui.client.application.Application;
 24  
 import org.kuali.student.common.ui.client.application.ApplicationContext;
 25  
 import org.kuali.student.common.ui.client.application.KSAsyncCallback;
 26  
 import org.kuali.student.common.ui.client.configurable.mvc.DelayedToolView;
 27  
 import org.kuali.student.common.ui.client.configurable.mvc.HasReferenceId;
 28  
 import org.kuali.student.common.ui.client.configurable.mvc.SectionTitle;
 29  
 import org.kuali.student.common.ui.client.configurable.mvc.sections.InfoMessage;
 30  
 import org.kuali.student.common.ui.client.mvc.Callback;
 31  
 import org.kuali.student.common.ui.client.service.CommentRpcService;
 32  
 import org.kuali.student.common.ui.client.service.CommentRpcServiceAsync;
 33  
 import org.kuali.student.common.ui.client.theme.Theme;
 34  
 import org.kuali.student.common.ui.client.widgets.KSDropDown;
 35  
 import org.kuali.student.common.ui.client.widgets.KSLabel;
 36  
 import org.kuali.student.common.ui.client.widgets.KSRichEditor;
 37  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ConfirmCancelGroup;
 38  
 import org.kuali.student.common.ui.client.widgets.buttongroups.OkGroup;
 39  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.ConfirmCancelEnum;
 40  
 import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.OkEnum;
 41  
 import org.kuali.student.common.ui.client.widgets.layout.HorizontalBlockFlowPanel;
 42  
 import org.kuali.student.common.ui.client.widgets.layout.VerticalFlowPanel;
 43  
 import org.kuali.student.common.ui.client.widgets.list.ListItems;
 44  
 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeEvent;
 45  
 import org.kuali.student.common.ui.client.widgets.list.SelectionChangeHandler;
 46  
 import org.kuali.student.core.comment.dto.CommentInfo;
 47  
 import org.kuali.student.core.dto.RichTextInfo;
 48  
 import org.kuali.student.core.dto.StatusInfo;
 49  
 
 50  
 import com.google.gwt.core.client.GWT;
 51  
 import com.google.gwt.event.dom.client.ClickEvent;
 52  
 import com.google.gwt.event.dom.client.ClickHandler;
 53  
 import com.google.gwt.i18n.client.DateTimeFormat;
 54  
 import com.google.gwt.user.client.Window;
 55  
 import com.google.gwt.user.client.ui.Composite;
 56  
 import com.google.gwt.user.client.ui.HTML;
 57  
 import com.google.gwt.user.client.ui.Image;
 58  
 import com.google.gwt.user.client.ui.SimplePanel;
 59  
 import com.google.gwt.user.client.ui.Widget;
 60  
 
 61  0
 public class CommentPanel extends DelayedToolView implements HasReferenceId {
 62  
 
 63  0
         final static ApplicationContext context = Application.getApplicationContext();
 64  
 
 65  
         private String referenceId;
 66  
         private String referenceTypeKey;
 67  
         private String referenceType;
 68  
         private String referenceState;
 69  
 
 70  0
         private CommentRpcServiceAsync commentServiceAsync = GWT.create(CommentRpcService.class);
 71  
         private static final String ALL = "All";
 72  0
     private VerticalFlowPanel layout = new VerticalFlowPanel();
 73  0
     private VerticalFlowPanel commentList = new VerticalFlowPanel();
 74  0
     private SectionTitle headerTitle = SectionTitle.generateH1Title("Proposal Comments");
 75  0
     private SectionTitle createTitle = SectionTitle.generateH2Title("Leave a Comment");
 76  0
     private VerticalFlowPanel createPanel = new VerticalFlowPanel();
 77  0
     private SimplePanel commentEditorPanel = new SimplePanel();
 78  0
     private KSRichEditor commentEditor = new KSRichEditor();
 79  0
     private List<Comment> comments = new ArrayList<Comment>();
 80  0
     private KSLabel loggedInAs = new KSLabel();
 81  0
     private HorizontalBlockFlowPanel commentTypesPanel = new HorizontalBlockFlowPanel();
 82  0
     private KSLabel seeComments = new KSLabel("See Comments from ");
 83  0
     private KSLabel loadingComments = new KSLabel("Loading Comments");
 84  0
     private KSDropDown commentTypes = new KSDropDown();
 85  0
     private InfoMessage saveWarning = new InfoMessage("The document must be saved before Comments can be added.", true);
 86  0
     private boolean showingEditButtons = true;
 87  0
     private List<String> types = new ArrayList<String>();
 88  
 
 89  0
     private Comparator<CommentInfo> commentInfoComparator = new Comparator<CommentInfo>(){
 90  
 
 91  
                 @Override
 92  
                 public int compare(CommentInfo comment1, CommentInfo comment2) {
 93  
 
 94  0
                         if(comment1.getMetaInfo().getCreateTime().after(comment2.getMetaInfo().getCreateTime())){
 95  0
                                 return -1;
 96  
                         }
 97  0
                         else if(comment1.getMetaInfo().getCreateTime().before(comment2.getMetaInfo().getCreateTime())){
 98  0
                                 return 1;
 99  
                         }
 100  
                         else{
 101  
                                 //equal
 102  0
                                 return 0;
 103  
                         }
 104  
 
 105  
                 }
 106  
     };
 107  
 
 108  0
     private static DateTimeFormat formatter = DateTimeFormat.getMediumDateTimeFormat();
 109  
 
 110  0
     private OkGroup buttonPanel = new OkGroup(new Callback<OkEnum>(){
 111  
 
 112  
         @Override
 113  
         public void exec(OkEnum result) {
 114  0
             if(result == OkEnum.Ok){
 115  0
                 CommentInfo newComment = new CommentInfo();
 116  
 
 117  0
                 RichTextInfo text = new RichTextInfo();
 118  0
                 text.setFormatted(commentEditor.getHTML());
 119  0
                 text.setPlain(commentEditor.getText());
 120  0
                 newComment.setCommentText(text);
 121  0
                 newComment.setType("commentType." + referenceType + "." + referenceState);
 122  
 
 123  
                 try {
 124  0
                                         commentServiceAsync.addComment(referenceId, referenceTypeKey, newComment, new KSAsyncCallback<CommentInfo>(){
 125  
 
 126  
                                                 @Override
 127  
                                                 public void handleFailure(Throwable caught) {
 128  0
                                                         GWT.log("Add Comment Failed", caught);
 129  0
                                                 }
 130  
 
 131  
                                                 @Override
 132  
                                                 public void onSuccess(CommentInfo result) {
 133  0
                                                         if(!(types.contains(result.getType()))){
 134  0
                                                                 types.add(result.getType());
 135  
                                                         }
 136  0
                                                         commentTypes.redraw();
 137  0
                                                         Comment comment = new Comment(result);
 138  0
                                                 comments.add(0, comment);
 139  0
                                                 commentList.insert(comment, 0);
 140  0
                                                 commentEditor.setHTML("");
 141  0
                                                 }
 142  
                                         });
 143  0
                                 } catch (Exception e) {
 144  0
                                         GWT.log("Add Comment Failed", e);
 145  0
                                 }
 146  
 
 147  
             }
 148  
 
 149  0
         }
 150  
     });
 151  
 
 152  
     public CommentPanel(Enum<?> viewEnum, String viewName) {
 153  0
                 super(viewEnum, viewName);
 154  0
         }
 155  
 
 156  
     @Override
 157  
     public void setReferenceId(String id) {
 158  0
         this.referenceId = id;
 159  0
     }
 160  
 
 161  
     @Override
 162  
     public String getReferenceId() {
 163  0
         return referenceId;
 164  
     }
 165  
 
 166  
     @Override
 167  
         public String getReferenceTypeKey() {
 168  0
                 return referenceTypeKey;
 169  
         }
 170  
 
 171  
     @Override
 172  
         public void setReferenceTypeKey(String referenceTypeKey) {
 173  0
                 this.referenceTypeKey = referenceTypeKey;
 174  0
         }
 175  
 
 176  
     @Override
 177  
         public String getReferenceType() {
 178  0
                 return referenceType;
 179  
         }
 180  
 
 181  
     @Override
 182  
         public void setReferenceType(String referenceType) {
 183  0
                 this.referenceType = referenceType;
 184  0
         }
 185  
 
 186  
     @Override
 187  
         public String getReferenceState() {
 188  0
                 return referenceState;
 189  
         }
 190  
 
 191  
     @Override
 192  
         public void setReferenceState(String referenceState) {
 193  0
                 this.referenceState = referenceState;
 194  0
         }
 195  
 
 196  
 
 197  
     @Override
 198  
     protected Widget createWidget() {
 199  0
             commentTypes.setBlankFirstItem(false);
 200  0
             commentTypes.setListItems(new ListItems(){
 201  
 
 202  
                         @Override
 203  
                         public List<String> getAttrKeys() {
 204  0
                                 List<String> keys = new ArrayList<String>();
 205  
                                 /*keys.add("desc");
 206  
                                 keys.add("name");*/
 207  0
                                 return keys;
 208  
                         }
 209  
 
 210  
                         @Override
 211  
                         public String getItemAttribute(String id, String attrkey) {
 212  
 
 213  0
                                 String result = id;
 214  
                                 /*String result = null;
 215  
                                 if(id.equals(ALL)){
 216  
                                         if(attrkey.equalsIgnoreCase("desc")){
 217  
                                                 result = ALL_DESC;
 218  
                                         }
 219  
                                         else if(attrkey.equalsIgnoreCase("name")){
 220  
                                                 result = ALL_NAME;
 221  
                                         }
 222  
                                 }
 223  
                                 else{
 224  
                                         CommentTypeInfo type = null;
 225  
                                         for(CommentTypeInfo i: types){
 226  
                                                 if(i.getId().equals(id)){
 227  
                                                         type = i;
 228  
                                                         break;
 229  
                                                 }
 230  
                                         }
 231  
 
 232  
                                         if(type != null){
 233  
                                                 if(attrkey.equalsIgnoreCase("desc")){
 234  
                                                         result = type.getDesc();
 235  
                                                 }
 236  
                                                 else if(attrkey.equalsIgnoreCase("name")){
 237  
                                                         result = type.getName();
 238  
                                                 }
 239  
                                         }
 240  
                                 }*/
 241  0
                                 return result;
 242  
                         }
 243  
 
 244  
                         @Override
 245  
                         public int getItemCount() {
 246  0
                                 return types.size();
 247  
                         }
 248  
 
 249  
                         @Override
 250  
                         public List<String> getItemIds() {
 251  0
                                 List<String> ids = new ArrayList<String>();
 252  0
                                 ids.add(ALL);
 253  0
                                 for(String i: types){
 254  0
                                         ids.add(i);
 255  
                                 }
 256  
 
 257  0
                                 return ids;
 258  
                         }
 259  
 
 260  
                         @Override
 261  
                         public String getItemText(String id) {
 262  0
                                 String result = null;
 263  0
                                 if(id.equals(ALL)){
 264  0
                                         result = context.getMessage("allComments");
 265  
                                 }
 266  
                                 else{
 267  0
                                         id = id.replace("commentType.", "");
 268  0
                                         result = context.getMessage(id);
 269  
                                 }
 270  0
                                 return result;
 271  
                         }
 272  
             });
 273  
 
 274  
 
 275  0
             commentTypes.selectItem(ALL);
 276  0
             commentTypes.addSelectionChangeHandler(new SelectionChangeHandler(){
 277  
 
 278  
                         @Override
 279  
                         public void onSelectionChange(SelectionChangeEvent event) {
 280  0
                                 refreshComments();
 281  0
                         }
 282  
             });
 283  
 
 284  0
         buttonPanel.setButtonText(OkEnum.Ok, "Submit");
 285  0
         loggedInAs.setText(Application.getApplicationContext().getUserId());
 286  
 
 287  0
         loggedInAs.addStyleName("KS-Comment-Login-User");
 288  0
         createPanel.addStyleName("KS-Comment-Create-Panel");
 289  0
         commentEditor.addStyleName("KS-Comment-Create-Editor");
 290  
 
 291  0
         layout.add(headerTitle);
 292  0
         layout.add(saveWarning);
 293  0
         saveWarning.setVisible(false);
 294  0
         createPanel.add(createTitle);
 295  0
         commentEditorPanel.setWidget(commentEditor);
 296  0
         createPanel.add(commentEditorPanel);
 297  0
         createPanel.add(loggedInAs);
 298  0
         createPanel.add(buttonPanel);
 299  
 
 300  0
         commentTypesPanel.add(seeComments);
 301  0
         commentTypesPanel.add(commentTypes);
 302  0
         createPanel.add(commentTypesPanel);
 303  
 
 304  0
         isAuthorizedAddComment();
 305  0
         layout.add(createPanel);
 306  0
         layout.add(commentList);
 307  0
         createPanel.setVisible(false);
 308  0
                 commentList.setVisible(false);
 309  
 
 310  0
         return layout;
 311  
     }
 312  
 
 313  
     private void isAuthorizedAddComment() {
 314  
         // check permission to see if user can comment
 315  0
         commentServiceAsync.isAuthorizedAddComment(referenceId, referenceTypeKey, new KSAsyncCallback<Boolean>() {
 316  
 
 317  
                         @Override
 318  
             public void onFailure(Throwable caught) {
 319  0
                                 GWT.log("Error checking permission for adding comments: ", caught);
 320  0
                                 throw new RuntimeException("Error checking Permissions: ", caught);
 321  
             }
 322  
 
 323  
                         @Override
 324  
             public void onSuccess(Boolean result) {
 325  0
                                 GWT.log("User is " + ((result) ? "" : "not ") + "authorized to add comment.", null);
 326  0
                                 if(referenceId != null && !(referenceId.isEmpty())){
 327  
                                         //buttonPanel.getButton(OkEnum.Ok).setEnabled(true);
 328  0
                                 saveWarning.setVisible(false);
 329  0
                                 createPanel.setVisible(result);
 330  0
                                         commentList.setVisible(true);
 331  0
                                         refreshComments();
 332  
                                 }
 333  
                                 else{
 334  0
                                         saveWarning.setVisible(true);
 335  0
                                         createPanel.setVisible(false);
 336  0
                                         commentList.setVisible(false);
 337  
                                         //buttonPanel.getButton(OkEnum.Ok).setEnabled(false);
 338  
                                 }
 339  0
             }
 340  
 
 341  
                 });
 342  0
     }
 343  
 
 344  
     private void isAuthorizedEditComment(final Comment comment) {
 345  
         // check permission to see if user can comment
 346  
 //        commentServiceAsync.isAuthorizedAddComment(referenceId, referenceTypeKey, new AsyncCallback<Boolean>() {
 347  
 //
 348  
 //                        @Override
 349  
 //            public void onFailure(Throwable caught) {
 350  
 //                                caught.printStackTrace();
 351  
 //                                GWT.log("Error checking permission for adding comments: ", caught);
 352  
 //                                throw new RuntimeException("Error checking Permissions: ", caught);
 353  
 //            }
 354  
 //
 355  
 //                        @Override
 356  
 //            public void onSuccess(Boolean result) {
 357  
 //                                GWT.log("User is " + ((result) ? "" : "not ") + "authorized to add comment.", null);
 358  
 //                                comment.showEditActions(result);
 359  
 //            }
 360  
 //
 361  
 //                });
 362  0
             comment.showEditActions(false);
 363  0
     }
 364  
 
 365  
     @Override
 366  
     public void setVisible(boolean visible) {
 367  0
         super.setVisible(visible);
 368  0
         isAuthorizedAddComment();
 369  
 
 370  0
     }
 371  
 
 372  
 /*   public void refreshCommentTypes(){
 373  
 
 374  
 
 375  
 
 376  
             try {
 377  
                         commentServiceAsync.getCommentTypesForReferenceType(referenceTypeKey,  new AsyncCallback<List<CommentTypeInfo>>(){
 378  
 
 379  
                                 @Override
 380  
                                 public void onFailure(Throwable caught) {
 381  
                                         caught.printStackTrace();
 382  
 
 383  
                                 }
 384  
 
 385  
                                 @Override
 386  
                                 public void onSuccess(List<CommentTypeInfo> result) {
 387  
                                         types = result;
 388  
                                         commentTypes.redraw();
 389  
                                 }
 390  
                         });
 391  
                 } catch (Exception e) {
 392  
                         e.printStackTrace();
 393  
                 }
 394  
     }*/
 395  
 
 396  
 
 397  
     public void refreshComments(){
 398  0
         commentList.clear();
 399  0
         commentList.add(loadingComments);
 400  
         //rpc call to get all current comments and populate into comment list
 401  
             try {
 402  0
                     if(commentTypes.getSelectedItem().equals(ALL)){
 403  0
                                 commentServiceAsync.getComments(referenceId, referenceTypeKey, new KSAsyncCallback<List<CommentInfo>>(){
 404  
 
 405  
                                                 @Override
 406  
                                                 public void handleFailure(Throwable caught) {
 407  0
                                                         GWT.log("getComments failed", caught);
 408  0
                                                         commentList.remove(loadingComments);
 409  0
                                                 }
 410  
 
 411  
                                                 @Override
 412  
                                                 public void onSuccess(List<CommentInfo> result) {
 413  0
                                                         if(result != null){
 414  0
                                                                 comments.clear();
 415  0
                                                                 commentList.clear();
 416  0
                                                                 types.clear();
 417  0
                                                                 Collections.sort(result, commentInfoComparator);
 418  0
                                                                 for(CommentInfo c: result){
 419  0
                                                                         if(!(types.contains(c.getType()))){
 420  0
                                                                                 types.add(c.getType());
 421  
                                                                         }
 422  
 
 423  0
                                                                         Comment commentWidget = new Comment(c);
 424  0
                                                                         comments.add(commentWidget);
 425  0
                                                                         commentList.add(commentWidget);
 426  0
                                                                 }
 427  0
                                                                 commentTypes.redraw();
 428  
                                                         }
 429  
 
 430  0
                                                         commentList.remove(loadingComments);
 431  
                                                         //refreshCommentTypes();
 432  0
                                                 }
 433  
                                         });
 434  
                             }
 435  
                     else{
 436  
                             //must be showing specific comment type
 437  0
                                 commentServiceAsync.getCommentsByType(referenceId, referenceTypeKey, commentTypes.getSelectedItem(), new KSAsyncCallback<List<CommentInfo>>(){
 438  
 
 439  
                                         @Override
 440  
                                         public void handleFailure(Throwable caught) {
 441  0
                                                 GWT.log("getCommentsByType Failed" ,caught);
 442  0
                                                 commentList.remove(loadingComments);
 443  0
                                         }
 444  
 
 445  
                                         @Override
 446  
                                         public void onSuccess(List<CommentInfo> result) {
 447  0
                                                 if(result != null){
 448  0
                                                         comments.clear();
 449  0
                                                         commentList.clear();
 450  0
                                                         types.clear();
 451  0
                                                         Collections.sort(result, commentInfoComparator);
 452  0
                                                         for(CommentInfo c: result){
 453  0
                                                                 if(!(types.contains(c.getType()))){
 454  0
                                                                         types.add(c.getType());
 455  
                                                                 }
 456  
 
 457  0
                                                                 Comment commentWidget = new Comment(c);
 458  0
                                                                 comments.add(commentWidget);
 459  0
                                                                 commentList.add(commentWidget);
 460  0
                                                         }
 461  0
                                                         commentTypes.redraw();
 462  
                                                 }
 463  
 
 464  0
                                                 commentList.remove(loadingComments);
 465  
                                                 //refreshCommentTypes();
 466  0
                                         }
 467  
                                 });
 468  
 
 469  
                     }
 470  0
                 } catch (Exception e) {
 471  0
                         GWT.log("refresh Comments Failed",e);
 472  0
                 }
 473  
 
 474  
 
 475  0
     }
 476  
 
 477  
     private void turnCommentEditingOn() {
 478  
                 //FIXME do a check to see if the current person can edit for each comment in the list then show the actions, else
 479  
                 //dont show them
 480  0
                 if(!showingEditButtons){
 481  
                         // check permission for adding a comment to determine createPanel visibility
 482  0
                         isAuthorizedAddComment();
 483  0
                     commentEditorPanel.setWidget(commentEditor);
 484  0
                     for(Comment c: comments){
 485  0
                             isAuthorizedEditComment(c);
 486  
                 }
 487  0
                     showingEditButtons = true;
 488  
                 }
 489  0
     }
 490  
 
 491  
     private void turnCommentEditingOff() {
 492  0
                 if(showingEditButtons){
 493  
                         // permissions don't matter as we need to hide create panel by force
 494  0
                     createPanel.setVisible(false);
 495  0
                     commentEditorPanel.remove(commentEditor);
 496  
 
 497  0
                     for(Comment c: comments){
 498  
                             // permissions don't matter as we need to hide edit actions by force
 499  0
                         c.showEditActions(false);
 500  
                 }
 501  0
                     showingEditButtons = false;
 502  
                 }
 503  0
     }
 504  
 
 505  0
     private KSRichEditor editor = new KSRichEditor();
 506  
 
 507  0
     private class Comment extends Composite{
 508  
 
 509  0
         private SimplePanel content = new SimplePanel();
 510  0
         private VerticalFlowPanel editLayout = new VerticalFlowPanel();
 511  0
         private VerticalFlowPanel viewLayout = new VerticalFlowPanel();
 512  0
         private HorizontalBlockFlowPanel header = new HorizontalBlockFlowPanel();
 513  0
         private HorizontalBlockFlowPanel headerTextContainer = new HorizontalBlockFlowPanel();
 514  0
         private HorizontalBlockFlowPanel footer = new HorizontalBlockFlowPanel();
 515  0
         private HorizontalBlockFlowPanel editActions = new HorizontalBlockFlowPanel();
 516  
 
 517  0
         Image edit = Theme.INSTANCE.getCommonImages().getEditCommentIcon();
 518  0
         Image delete = Theme.INSTANCE.getCommonImages().getDeleteCommentIcon();
 519  
 
 520  0
         private KSLabel name = new KSLabel();
 521  0
         private HTML commentText = new HTML();
 522  0
         private KSLabel datePosted = new KSLabel();
 523  0
         private KSLabel dateModified = new KSLabel();
 524  
 
 525  
         private CommentInfo info;
 526  
 
 527  0
         public Comment(CommentInfo info){
 528  0
             this.info = info;
 529  0
             edit.addClickHandler(new ClickHandler(){
 530  
                 @Override
 531  
                 public void onClick(ClickEvent event) {
 532  0
                         editLayout.clear();
 533  
                     //editActions.setVisible(false);
 534  0
                         turnCommentEditingOff();
 535  0
                     content.addStyleName("KS-Comment-Container-InUse");
 536  0
                     editor.setHTML(Comment.this.info.getCommentText().getFormatted());
 537  
 
 538  0
                     ConfirmCancelGroup buttonPanel = new ConfirmCancelGroup(new Callback<ConfirmCancelEnum>(){
 539  
                         @Override
 540  
                         public void exec(ConfirmCancelEnum result) {
 541  0
                             switch(result){
 542  
                                 case CONFIRM:
 543  
 
 544  0
                                     Comment.this.info.getCommentText().setFormatted(CommentPanel.this.editor.getHTML());
 545  0
                                     Comment.this.info.getCommentText().setPlain(CommentPanel.this.editor.getText());
 546  
 
 547  
                                         try {
 548  0
                                                                                 commentServiceAsync.updateComment(referenceId, referenceTypeKey, Comment.this.info, new KSAsyncCallback<CommentInfo>(){
 549  
 
 550  
                                                                                         @Override
 551  
                                                                                         public void handleFailure(Throwable caught) {
 552  0
                                                                                                 GWT.log("updateComment failed", caught);
 553  0
                                                                                         }
 554  
 
 555  
                                                                                         @Override
 556  
                                                                                         public void onSuccess(CommentInfo result) {
 557  0
                                                                                                 Comment.this.info = result;
 558  0
                                                                                                 content.removeStyleName("KS-Comment-Container-InUse");
 559  0
                                                                                                 editor.setText("");
 560  0
                                                                                                 editor.removeFromParent();
 561  0
                                                             setupViewLayout();
 562  0
                                                                                         }
 563  
 
 564  
                                                                                 });
 565  0
                                                                         } catch (Exception e) {
 566  0
                                                                                 GWT.log("updateComment failed", e);
 567  0
                                                                         }
 568  
 
 569  0
                                     break;
 570  
                                 case CANCEL:
 571  0
                                         content.removeStyleName("KS-Comment-Container-InUse");
 572  0
                                         editor.setText("");
 573  0
                                         editor.removeFromParent();
 574  0
                                     setupViewLayout();
 575  
                                     break;
 576  
                             }
 577  
 
 578  0
                         }
 579  
                     });
 580  
 
 581  0
                     buttonPanel.addStyleName("KS-Comment-Inline-Edit-Panel");
 582  0
                     buttonPanel.setContent(editor);
 583  0
                     editLayout.add(header);
 584  0
                     editLayout.add(buttonPanel);
 585  0
                     content.setWidget(editLayout);
 586  0
                 }
 587  
             });
 588  
 
 589  0
             delete.addClickHandler(new ClickHandler(){
 590  
                 @Override
 591  
                 public void onClick(ClickEvent event) {
 592  
                         try {
 593  0
                                                 commentServiceAsync.removeComment(Comment.this.info.getId(), referenceId, referenceTypeKey, new KSAsyncCallback<StatusInfo>(){
 594  
 
 595  
                                                         @Override
 596  
                                                         public void handleFailure(Throwable caught) {
 597  0
                                                                 GWT.log("remove Comment Failed", caught);
 598  0
                                                         }
 599  
 
 600  
                                                         @Override
 601  
                                                         public void onSuccess(StatusInfo result) {
 602  0
                                                                 if(result.getSuccess()){
 603  0
                                                                         Window.alert("Your comment was deleted successfully");
 604  
                                                                 }
 605  0
                                                                 refreshComments();
 606  0
                                                         }
 607  
 
 608  
                                                 });
 609  0
                                         } catch (Exception e) {
 610  0
                                                 GWT.log("remove Comment Failed", e);
 611  0
                                         }
 612  0
                 }
 613  
             });
 614  
 
 615  0
             setupDefaultStyles();
 616  0
             headerTextContainer.add(name);
 617  0
             headerTextContainer.add(datePosted);
 618  0
             editActions.add(edit);
 619  0
             editActions.add(delete);
 620  0
             header.add(headerTextContainer);
 621  0
             isAuthorizedEditComment(this);
 622  0
             header.add(editActions);
 623  0
             footer.add(dateModified);
 624  0
             setupViewLayout();
 625  
 
 626  0
             this.initWidget(content);
 627  0
         }
 628  
 
 629  
         private void setupDefaultStyles(){
 630  0
                 content.addStyleName("KS-Comment-Container");
 631  0
                 header.addStyleName("KS-Comment-Header");
 632  0
                 headerTextContainer.addStyleName("KS-Comment-Header-Left");
 633  0
                 footer.addStyleName("KS-Comment-Footer");
 634  0
                 edit.addStyleName("KS-Comment-Image-Button");
 635  0
                 delete.addStyleName("KS-Comment-Image-Button");
 636  0
                 editActions.addStyleName("KS-Comment-Image-Button-Panel");
 637  0
                 name.addStyleName("KS-Comment-Name");
 638  0
                 commentText.addStyleName("KS-Comment-Text");
 639  0
                 datePosted.addStyleName("KS-Comment-Date-Created");
 640  0
                 dateModified.addStyleName("KS-Comment-Date-Modified");
 641  0
                 editor.setStyleName("KS-Comment-Inline-Edit-Editor");
 642  0
         }
 643  
 
 644  
         private void setupViewLayout(){
 645  
 
 646  0
             viewLayout.clear();
 647  0
             viewLayout.add(header);
 648  0
             viewLayout.add(commentText);
 649  0
             viewLayout.add(footer);
 650  
 
 651  
             //FIXME: this will actually call the person service to get person info
 652  0
             name.setText(info.getMetaInfo().getCreateId());
 653  
 
 654  0
             if(info.getCommentText() != null){
 655  0
                 commentText.setHTML(info.getCommentText().getFormatted());
 656  
             }
 657  0
             if(info.getMetaInfo().getCreateTime() != null){
 658  0
                 datePosted.setText(" " + formatter.format(info.getMetaInfo().getCreateTime()));
 659  
             }
 660  0
             if(info.getMetaInfo().getUpdateTime() != null && !(info.getMetaInfo().getUpdateTime().equals(info.getMetaInfo().getCreateTime()))){
 661  0
                 dateModified.setText("Last Modified: " + formatter.format(info.getMetaInfo().getUpdateTime()));
 662  
             }
 663  
 
 664  0
             content.setWidget(viewLayout);
 665  
 
 666  
 
 667  0
             turnCommentEditingOn();
 668  0
         }
 669  
 
 670  
         public void showEditActions(boolean show){
 671  0
                 editActions.setVisible(show);
 672  0
         }
 673  
 
 674  
     }
 675  
 
 676  
         @Override
 677  
         public Image getImage() {
 678  0
                 return Theme.INSTANCE.getCommonImages().getCommentIcon();
 679  
         }
 680  
 }