1 package com.atlassian.theplugin.idea.ui.tree.file; 2 3 import com.atlassian.theplugin.commons.crucible.api.model.CrucibleFileInfo; 4 import com.atlassian.theplugin.commons.crucible.api.model.ReviewAdapter; 5 import com.atlassian.theplugin.commons.crucible.api.model.VersionedComment; 6 import com.atlassian.theplugin.commons.crucible.api.model.Comment; 7 import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode; 8 import com.atlassian.theplugin.idea.ui.tree.comment.VersionedCommentTreeNode; 9 10 import java.util.ArrayList; 11 import java.util.List; 12 import java.util.Map; 13 14 public class CrucibleLineCommentsNode extends CrucibleContainerNode { 15 16 private CrucibleFileInfo file; 17 18 public CrucibleLineCommentsNode(ReviewAdapter review, CrucibleFileInfo file, Map<String, FileNode> children) { 19 super(review); 20 this.file = file; 21 22 if (children != null) { 23 for (FileNode n : children.values()) { 24 addNode(n); 25 } 26 } else { 27 List<VersionedComment> comments = getLineVersionedComments(); 28 for (VersionedComment c : comments) { 29 if (!c.isDeleted()) { 30 VersionedCommentTreeNode commentNode = new VersionedCommentTreeNode(review, file, c, null); 31 addNode(commentNode); 32 33 for (Comment reply : c.getReplies()) { 34 commentNode.addNode(new VersionedCommentTreeNode(review, file, (VersionedComment) reply, null)); 35 } 36 } 37 } 38 } 39 } 40 41 protected String getText() { 42 return "Line Comments (" + getNumberOfLineComments() + ")"; 43 } 44 45 public AtlassianTreeNode getClone() { 46 return new CrucibleLineCommentsNode(getReview(), file, getChildren()); 47 } 48 49 private int getNumberOfLineComments() { 50 int n = 0; 51 52 List<VersionedComment> thisFileComments = getLineVersionedComments(); 53 54 for (VersionedComment c : thisFileComments) { 55 ++n; 56 n += c.getReplies().size(); 57 } 58 59 return n; 60 } 61 62 private List<VersionedComment> getLineVersionedComments() { 63 List<VersionedComment> list = new ArrayList<VersionedComment>(); 64 List<VersionedComment> thisFileComments = file.getVersionedComments(); 65 if (thisFileComments == null) { 66 return null; 67 } 68 for (VersionedComment c : thisFileComments) { 69 if (c.getFromStartLine() + c.getFromEndLine() + c.getToStartLine() + c.getToEndLine() != 0) { 70 if (!c.isReply()) { 71 list.add(c); 72 } 73 } 74 } 75 return list; 76 } 77 78 79 public boolean isCompactable() { 80 return false; 81 } 82 } 83