Package org.damour.base.client.objects

Examples of org.damour.base.client.objects.Comment


    file.setName("comment file");
    file.setOwner(user);
    session.save(file);

    for (int i = 0; i < 100; i++) {
      Comment comment = new Comment();
      comment.setComment("comment " + i);
      comment.setOwner(file.getOwner());
      comment.setAuthor(user);
      comment.setParent(file);
      session.save(comment);
    }
    tx.commit();
    session.close();

    for (int testCount = 0; testCount < 10; testCount++) {
      session = HibernateUtil.getInstance().getSession();
      GenericPage<Comment> pageController = new GenericPage<Comment>(session, Comment.class, null, 0, 10);
      long pageCount = pageController.getPageCount();
      for (int pageNumber = 0; pageNumber < pageCount; pageNumber++) {
        List<Comment> comments = pageController.getList();
        for (Comment comment : comments) {
          System.out.print(comment.getComment());
        }
        System.out.println();
        pageController = pageController.next();
      }
      session.close();
View Full Code Here


      if (!flatten) {
        sortedComments = sortComments(sortedComments);
      }

      for (PermissibleObject obj : sortedComments) {
        final Comment comment = (Comment) obj;
        int commentDepth = getCommentDepth(comment);

        int maxDepth = Integer.parseInt(maxCommentDepthListBox.getValue(maxCommentDepthListBox.getSelectedIndex()));
        if (commentDepth >= maxDepth) {
          continue;
        }

        boolean userIsAuthorOfComment = AuthenticationHandler.getInstance().getUser() != null && comment.getAuthor() != null
            && comment.getAuthor().equals(AuthenticationHandler.getInstance().getUser());

        if (userCanManage || userIsAuthorOfComment || comment.isApproved()) {

          FlexTable commentHeaderPanel = new FlexTable();
          commentHeaderPanel.setCellPadding(0);
          commentHeaderPanel.setCellSpacing(0);
          commentHeaderPanel.setStyleName("commentHeader");
          commentHeaderPanel.setWidth("100%");

          String authorLabelString = comment.getAuthor() == null ? comment.getEmail() : comment.getAuthor().getUsername();
          if (comment.getAuthor() != null && comment.getAuthor().getFirstname() != null && !"".equals(comment.getAuthor().getFirstname())) {
            authorLabelString += " (" + comment.getAuthor().getFirstname();
            if (comment.getAuthor() != null && comment.getAuthor().getLastname() != null && !"".equals(comment.getAuthor().getLastname())) {
              authorLabelString += " " + comment.getAuthor().getLastname() + ")";
            } else {
              authorLabelString += ")";
            }
          }

          Image replyCommentImage = new Image();
          replyCommentImage.setResource(BaseImageBundle.images.reply());
          replyCommentImage.setStyleName("commentActionButton");
          replyCommentImage.setTitle("Reply to this comment");
          replyCommentImage.addClickHandler(new ClickHandler() {

            public void onClick(ClickEvent event) {
              replyToComment(comment);
            }
          });
          int columnIndex = 0;
          commentHeaderPanel.setWidget(0, columnIndex, replyCommentImage);
          commentHeaderPanel.getFlexCellFormatter().setHorizontalAlignment(0, columnIndex, HasHorizontalAlignment.ALIGN_LEFT);
          columnIndex++;

          Label authorLabel = new Label(authorLabelString, false);
          commentHeaderPanel.setWidget(0, columnIndex, authorLabel);
          commentHeaderPanel.getFlexCellFormatter().setHorizontalAlignment(0, columnIndex, HasHorizontalAlignment.ALIGN_LEFT);
          columnIndex++;
          commentHeaderPanel.setWidget(0, columnIndex, new Label());
          commentHeaderPanel.getFlexCellFormatter().setWidth(0, columnIndex, "100%");
          commentHeaderPanel.getFlexCellFormatter().setHorizontalAlignment(0, columnIndex, HasHorizontalAlignment.ALIGN_RIGHT);
          columnIndex++;
          Label dateLabel = new Label(new Date(comment.getCommentDate()).toLocaleString(), false);
          commentHeaderPanel.setWidget(0, columnIndex, dateLabel);
          if (!userCanManage && !userIsAuthorOfComment) {
            DOM.setStyleAttribute(dateLabel.getElement(), "padding", "0 5px 0 0");
          }
          commentHeaderPanel.getFlexCellFormatter().setHorizontalAlignment(0, columnIndex, HasHorizontalAlignment.ALIGN_RIGHT);

          columnIndex++;
          if (userCanManage || userIsAuthorOfComment) {
            if (userCanManage && !comment.isApproved()) {
              final Image approveCommentImage = new Image();
              approveCommentImage.setResource(BaseImageBundle.images.approve());
              approveCommentImage.setStyleName("commentActionButton");
              approveCommentImage.setTitle("Approve comment");
              approveCommentImage.addClickHandler(new ClickHandler() {

                public void onClick(ClickEvent event) {
                  workingOnComment = comment;
                  approveComment(comment);
                }
              });
              commentHeaderPanel.setWidget(0, columnIndex, approveCommentImage);
              commentHeaderPanel.getFlexCellFormatter().setHorizontalAlignment(0, columnIndex, HasHorizontalAlignment.ALIGN_RIGHT);
              columnIndex++;
            } else {
              // put 16x16 spacer here for alignment
              final Image approveSpacerImage = new Image();
              approveSpacerImage.setResource(BaseImageBundle.images.empty16x16());
              approveSpacerImage.setStyleName("commentActionButton");
              commentHeaderPanel.setWidget(0, columnIndex, approveSpacerImage);
              commentHeaderPanel.getFlexCellFormatter().setHorizontalAlignment(0, columnIndex, HasHorizontalAlignment.ALIGN_RIGHT);
              columnIndex++;
            }
            Image deleteCommentImage = new Image();
            deleteCommentImage.setResource(BaseImageBundle.images.delete());
            deleteCommentImage.setStyleName("commentActionButton");
            deleteCommentImage.setTitle("Remove comment");
            deleteCommentImage.addClickHandler(new ClickHandler() {

              public void onClick(ClickEvent event) {
                IDialogCallback callback = new IDialogCallback() {

                  public void cancelPressed() {
                  }

                  public void okPressed() {
                    deleteComment(comment);
                  }
                };
                PromptDialogBox dialogBox = new PromptDialogBox("Question", "Yes", null, "No", false, true);
                dialogBox.setContent(new Label("Delete comment by " + (comment.getAuthor() == null ? comment.getEmail() : comment.getAuthor().getUsername())
                    + "?"));
                dialogBox.setCallback(callback);
                dialogBox.center();
              }
            });
            commentHeaderPanel.setWidget(0, columnIndex, deleteCommentImage);
            commentHeaderPanel.getFlexCellFormatter().setHorizontalAlignment(0, columnIndex, HasHorizontalAlignment.ALIGN_RIGHT);
            columnIndex++;
          }

          if (commentDepth > 0) {
            HorizontalPanel commentHeaderPanelWrapper = new HorizontalPanel();
            commentHeaderPanelWrapper.setWidth("100%");
            Label spacerLabel = new Label();
            commentHeaderPanelWrapper.add(spacerLabel);
            if (!flatten) {
              commentHeaderPanelWrapper.setCellWidth(spacerLabel, (commentDepth * 20) + "px");
            }
            commentHeaderPanelWrapper.add(commentHeaderPanel);
            commentsPanel.add(commentHeaderPanelWrapper);
          } else {
            commentsPanel.add(commentHeaderPanel);
          }

          // Label commentLabel = new Label(comment.getId() + " " + comment.getComment(), true);
          Label commentLabel = new Label(comment.getComment(), true);
          if (comment.isApproved()) {
            commentLabel.setStyleName("comment");
          } else if (userCanManage || userIsAuthorOfComment) {
            commentLabel.setStyleName("commentAwaitingApproval");
          }

View Full Code Here

      public void onClick(ClickEvent event) {
        String commentStr = commentTextArea.getText();
        if (commentStr == null || "".equals(commentStr.trim())) {
          return;
        }
        Comment comment = new Comment();
        comment.setGlobalRead(true);
        comment.setOwner(permissibleObject.getOwner());
        comment.setAuthor(AuthenticationHandler.getInstance().getUser());
        comment.setComment(commentStr);
        comment.setParent(permissibleObject);
        comment.setEmail(emailTextField.getText());
        submitButton.setEnabled(false);
        submitComment(comment);
      }
    });
    final Button clearButton = new Button("Clear");
View Full Code Here

        return true;
      }
    });
    dialog.setCallback(new IDialogCallback() {
      public void okPressed() {
        Comment newComment = new Comment();
        newComment.setGlobalRead(true);
        newComment.setOwner(permissibleObject.getOwner());
        newComment.setAuthor(AuthenticationHandler.getInstance().getUser());
        newComment.setComment(textArea.getText());
        newComment.setParent(permissibleObject);
        newComment.setParentComment(parentComment);
        newComment.setEmail(emailTextBox.getText());
        submitComment(newComment);
      }

      public void cancelPressed() {
      }
View Full Code Here

  private List<PermissibleObject> sortComments(List<PermissibleObject> comments) {
    List<Comment> commentSet = new ArrayList<Comment>();

    for (PermissibleObject obj : comments) {
      Comment comment = (Comment) obj;
      commentSet.add(comment);
      Comment parent = comment.getParentComment();
      do {
        if (parent != null) {
          if (!commentSet.contains(parent)) {
            commentSet.add(parent);
          }
          parent = parent.getParentComment();
        }
      } while (parent != null);
    }

    // create bare nodes for each element
    PermissibleObjectTreeNode rootNode = new PermissibleObjectTreeNode();

    for (Comment comment : commentSet) {
      PermissibleObjectTreeNode node = new PermissibleObjectTreeNode();
      node.setObject(comment);
      if (comment.getParentComment() == null) {
        if (!rootNode.getChildren().containsKey(comment)) {
          rootNode.getChildren().put(comment, node);
        }
      } else {
        // try to find parent in rootNode tree
        PermissibleObjectTreeNode parent = findParentCommentNode(rootNode, node);
        if (parent == null) {
          // this nodes parent cannot be found, let's add all of his parents
          List<Comment> parentComments = new ArrayList<Comment>();
          Comment parentComment = comment.getParentComment();
          do {
            if (parentComment != null) {
              parentComments.add(parentComment);
              parentComment = parentComment.getParentComment();
            }
          } while (parent != null);
          if (parentComments.size() == 0) {
            rootNode.getChildren().put(comment, node);
          } else {
View Full Code Here

    return null;
  }

  private int getCommentDepth(Comment comment) {
    int depth = 0;
    Comment parent = comment.getParentComment();
    while (parent != null) {
      depth++;
      parent = parent.getParentComment();
    }
    return depth;
  }
View Full Code Here

TOP

Related Classes of org.damour.base.client.objects.Comment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.