Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.drools.guvnor.client.widgets;
 
 
 import java.util.Date;
 import java.util.List;

Does the discussion panel for artifacts.
 
 public class DiscussionWidget extends Composite {
 
     private static ConstantsCore constants        = GWT.createConstantsCore.class );
     private static ImagesCore images           = GWT.createImagesCore.class );
     private static AssetServiceAsync assetService = GWT.createAssetService.class );
 
     private VerticalPanel commentList = new VerticalPanel();
     private VerticalPanel newCommentLayout = new VerticalPanel();
     private Artifact artifact;
     private int lastCount = 0;
     private boolean readOnly;
 
     @Override
     protected void onUnload() {
         super.onUnload(); //To change body of overridden methods use File | Settings | File Templates.
         PushClient.instance().unsubscribe();
     }
 
     public DiscussionWidget(final Artifact artifactboolean readOnly) {
         this. = artifact;
         this. = readOnly;
 
         DecoratedDisclosurePanel discussionPanel = new DecoratedDisclosurePanel(.Discussion());
         discussionPanel.setWidth("100%");
 
         .setWidth("100%");
         VerticalPanel discussionLayout = new VerticalPanel();
         discussionLayout.setWidth("90%");
 
         .setWidth("100%");
         refreshDiscussion();
         showNewCommentButton();
 
         discussionLayout.add();
         discussionLayout.add();
         
         discussionPanel.setContent(discussionLayout);
 
          = new ServerPushNotification() {
             public void messageReceived(PushResponse response) {
                 if ("discussion".equals(response.messageType) && artifact.getUuid().equals(response.message)) {
                     ..println("Refreshing discussion...");
                     refreshDiscussion();
                 }
             }
         };
 
         PushClient.instance().subscribe();
 
         initWidget(discussionPanel);
     }

    
Hit up the server
 
     public void refreshDiscussion() {
                                                                      new GenericCallback<List<DiscussionRecord>>() {
                                                                          public void onSuccess(List<DiscussionRecordresult) {
                                                                              updateCommentListresult );
                                                                          }
                                                                      } );
    }
    private void updateCommentList(List<DiscussionRecordls) {
        if ( ls.size() ==  ) return//don't want to over do it boys...
        .clear();
         = ls.size();
        for ( int rcdCounter =  - 1; rcdCounter >= 0; rcdCounter-- ) {
            DiscussionRecord dr = ls.getrcdCounter );
            appendCommentdr );
        }
    }
    private Widget appendComment(DiscussionRecord r) {
        SmallLabel hrd = new SmallLabel(.smallCommentBy0On1Small(r.author,
                new Date(r.timestamp)));
        hrd.addStyleName("discussion-header");
        .add(hrd);
        String[] parts = r.note.split("\n");
        if (parts.length > 0) {
            StringBuilder txtBuilder = new StringBuilder();
            for (int i = 0; i < parts.lengthi++) {
                txtBuilder.append(parts[i]);
                if (i != parts.length - 1) {
                    txtBuilder.append("<br/>");
                }
            }
            HTML hth = new HTML(txtBuilder.toString());
            hth.setStyleName("form-field");
            .add(hth);
        } else {
            Label lbl = new Label(r.note);
            lbl.setStyleName("form-field");
            .add(lbl);
        }
        .add(new HTML("<br/>"));
        return hrd;
    }
    private void showNewCommentButton() {
        .clear();
        HorizontalPanel hp = new HorizontalPanel();
        Button createNewComment = new Button(.AddADiscussionComment());
        createNewComment.setEnabled(!this.);
        hp.add(createNewComment);
            Button adminClearAll = new Button(.EraseAllComments());
            adminClearAll.setEnabled(!);
            hp.add(adminClearAll);
            adminClearAll.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent sender) {
                    if ( Window.confirm.EraseAllCommentsWarning() ) ) {
                        .clearAllDiscussionsForAsset.getUuid(),
                                                                                           new GenericCallback<java.lang.Void>() {
                                                                                               public void onSuccess(Void v) {
                                                                                                   updateCommentListnew ArrayList<DiscussionRecord>() );
                                                                                               }
                                                                                           } );
                    }
                }
            });
        }
        final String feedURL = GWT.getModuleBaseURL() + "feed/discussion?package=" + ((Asset).getMetaData().getModuleName()
                + "&assetName=" + URL.encode(.getName()) + "&viewUrl=" + Util.getSelfURL();
        Image image = ..Feed();
        image.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent arg0) {
                Window.open(feedURL"_blank"null);
            }
        });
        hp.add(image);
        .add(hp);
                .);
        createNewComment.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent sender) {
                showAddNewComment();
            }
        });
    }
    private void showAddNewComment() {
        .clear();
        final TextArea comment = new TextArea();
        comment.setWidth("100%");
        .add(comment);
        Button ok = new Button(.OK());
        Button cancel = new Button(.Cancel());
        ok.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent sender) {
                sendNewComment(comment.getText());
            }
        });
        cancel.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent sender) {
                showNewCommentButton();
            }
        });
        HorizontalPanel hp = new HorizontalPanel();
        hp.add(ok);
        hp.add(cancel);
        .add(hp);
        comment.setFocus(true);
    }
    private void sendNewComment(String text) {
        .clear();
        .addnew Image.spinner() ) );
                                                                       text,
                                                                       new GenericCallback<List<DiscussionRecord>>() {
                                                                           public void onSuccess(List<DiscussionRecordresult) {
                                                                               showNewCommentButton();
                                                                               updateCommentListresult );
                                                                           }
                                                                       } );
    }
New to GrepCode? Check out our FAQ X