1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.idea.ui.tree.file;
18
19 import com.atlassian.theplugin.commons.crucible.ValueNotYetInitialized;
20 import com.atlassian.theplugin.commons.crucible.api.model.GeneralComment;
21 import com.atlassian.theplugin.idea.crucible.ReviewData;
22 import com.atlassian.theplugin.idea.ui.tree.AtlassianClickAction;
23 import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode;
24 import com.intellij.ui.ColoredTreeCellRenderer;
25 import com.intellij.ui.SimpleTextAttributes;
26 import static com.intellij.ui.SimpleTextAttributes.STYLE_ITALIC;
27 import com.intellij.util.Icons;
28
29 import javax.swing.*;
30 import javax.swing.tree.TreeCellRenderer;
31 import java.awt.*;
32 import java.util.List;
33
34
35
36
37
38
39
40
41 public class CrucibleChangeSetTitleNode extends FileNode {
42 private ReviewData review;
43 private static final TreeCellRenderer MY_RENDERER = new CrucibleChangeSetTitleNodeRenderer();
44
45 public CrucibleChangeSetTitleNode(ReviewData review, AtlassianClickAction action) {
46 super(review.getName(), action);
47 this.review = review;
48 }
49
50 public CrucibleChangeSetTitleNode(final CrucibleChangeSetTitleNode node) {
51 super(node.getReview().getName(), node.getAtlassianClickAction());
52 this.review = node.review;
53 }
54
55 @Override
56 public TreeCellRenderer getTreeCellRenderer() {
57 return MY_RENDERER;
58 }
59
60 public ReviewData getReview() {
61 return review;
62 }
63
64 private static class CrucibleChangeSetTitleNodeRenderer extends ColoredTreeCellRenderer {
65 private static final SimpleTextAttributes TEXT_ITALIC = new SimpleTextAttributes(STYLE_ITALIC, null);
66 private static final SimpleTextAttributes RED_ITALIC = new SimpleTextAttributes(STYLE_ITALIC, Color.red);
67
68 public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded,
69 boolean leaf, int row, boolean hasFocus) {
70 StringBuilder sb = new StringBuilder();
71 CrucibleChangeSetTitleNode node = (CrucibleChangeSetTitleNode) value;
72 append(node.getReview().getPermId().getId(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD,
73 Color.red));
74 append(" ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
75 append(node.getReview().getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
76 try {
77 List<GeneralComment> generalComments = node.getReview().getGeneralComments();
78 if (generalComments.size() > 0) {
79 int noOfDefects = 0;
80 for (GeneralComment comment : generalComments) {
81 if (comment.isDefectRaised()) {
82 noOfDefects++;
83 }
84 }
85 append(" ",
86 TEXT_ITALIC);
87 append(String.valueOf(generalComments.size()),
88 TEXT_ITALIC);
89 append(" comment", TEXT_ITALIC);
90 if (generalComments.size() != 1) {
91 append("s", TEXT_ITALIC);
92 }
93 if (noOfDefects > 0) {
94 append(" (", TEXT_ITALIC);
95 append(String.valueOf(noOfDefects),
96 RED_ITALIC);
97 append(" defect", RED_ITALIC);
98 if (noOfDefects != 1) {
99 append("s", RED_ITALIC);
100 }
101 append(")", TEXT_ITALIC);
102 }
103 }
104 } catch (ValueNotYetInitialized valueNotYetInitialized) {
105
106 }
107 setIcon(expanded ? Icons.DIRECTORY_OPEN_ICON : Icons.DIRECTORY_CLOSED_ICON);
108 }
109 }
110
111 public AtlassianTreeNode getClone() {
112 return new CrucibleChangeSetTitleNode(this);
113 }
114 }