1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.idea.ui.tree.comment;
18
19 import com.atlassian.theplugin.commons.crucible.api.model.GeneralComment;
20 import com.atlassian.theplugin.idea.crucible.ReviewData;
21 import com.atlassian.theplugin.idea.ui.tree.AtlassianClickAction;
22 import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode;
23 import com.atlassian.theplugin.util.CommentPanelBuilder;
24
25 import javax.swing.*;
26 import javax.swing.tree.TreeCellRenderer;
27 import java.awt.*;
28
29 public class GeneralCommentTreeNode extends CommentTreeNode {
30 private GeneralComment comment;
31 private static final TreeCellRenderer MY_RENDERER = new MyRenderer();
32
33 public GeneralCommentTreeNode(ReviewData review, GeneralComment comment, AtlassianClickAction action) {
34 super(action);
35 this.review = review;
36 this.comment = comment;
37 }
38
39 public GeneralCommentTreeNode(final GeneralCommentTreeNode node) {
40 super(node.getAtlassianClickAction());
41 this.review = node.review;
42 this.comment = node.comment;
43 }
44
45 public GeneralComment getComment() {
46 return comment;
47 }
48
49 public TreeCellRenderer getTreeCellRenderer() {
50 return MY_RENDERER;
51 }
52
53 public AtlassianTreeNode getClone() {
54 return new GeneralCommentTreeNode(this);
55 }
56
57 private static class MyRenderer implements TreeCellRenderer {
58 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded,
59 boolean leaf, int row, boolean hasFocus) {
60 GeneralCommentTreeNode node = (GeneralCommentTreeNode) value;
61 JPanel panel;
62 if (node.isEditable()) {
63 panel = CommentPanelBuilder.createEditPanelOfGeneralComment(
64 node.getReview(), node.getComment());
65 } else {
66 panel = CommentPanelBuilder.createViewPanelOfGeneralComment(
67 node.getReview(), node.getComment());
68 }
69 panel.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder")
70 : BorderFactory.createEmptyBorder(1, 1, 1, 1));
71 return panel;
72
73 }
74 }
75 }