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.ReviewAdapter;
21 import com.atlassian.theplugin.idea.ui.tree.AtlassianClickAction;
22 import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode;
23 import com.intellij.ui.ColoredTreeCellRenderer;
24 import com.intellij.ui.SimpleTextAttributes;
25 import static com.intellij.ui.SimpleTextAttributes.STYLE_ITALIC;
26 import com.intellij.util.Icons;
27
28 import javax.swing.*;
29 import javax.swing.tree.TreeCellRenderer;
30 import java.awt.*;
31
32
33
34
35
36
37
38
39 public class CrucibleChangeSetTitleNode extends FileNode {
40 private ReviewAdapter review;
41 private static final TreeCellRenderer MY_RENDERER = new CrucibleChangeSetTitleNodeRenderer();
42
43 public CrucibleChangeSetTitleNode(ReviewAdapter review, AtlassianClickAction action) {
44 super(review.getName(), action);
45 this.review = review;
46 }
47
48 public CrucibleChangeSetTitleNode(final CrucibleChangeSetTitleNode node) {
49 super(node.getReview().getName(), node.getAtlassianClickAction());
50 this.review = node.review;
51 }
52
53 @Override
54 public TreeCellRenderer getTreeCellRenderer() {
55 return MY_RENDERER;
56 }
57
58 public ReviewAdapter getReview() {
59 return review;
60 }
61
62 public void setReview(ReviewAdapter review) {
63 this.review = review;
64 }
65
66 private static class CrucibleChangeSetTitleNodeRenderer extends ColoredTreeCellRenderer {
67 private static final SimpleTextAttributes TEXT_ITALIC = new SimpleTextAttributes(STYLE_ITALIC, null);
68 private static final SimpleTextAttributes RED_ITALIC = new SimpleTextAttributes(STYLE_ITALIC, Color.red);
69
70 public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded,
71 boolean leaf, int row, boolean hasFocus) {
72 CrucibleChangeSetTitleNode node = (CrucibleChangeSetTitleNode) value;
73 append(node.getReview().getPermId().getId(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD,
74 Color.GRAY));
75 append(" ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
76 append(node.getReview().getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
77 try {
78 int noOfDefects = node.getReview().getNumberOfVersionedCommentsDefects()
79 + node.getReview().getNumberOfGeneralCommentsDefects();
80
81 int noOfComments = node.getReview().getNumberOfGeneralComments()
82 + node.getReview().getNumberOfVersionedComments();
83
84
85
86
87
88
89
90
91
92
93
94
95 append(" ", TEXT_ITALIC);
96 append(String.valueOf(noOfComments), TEXT_ITALIC);
97 append(" comment", TEXT_ITALIC);
98 if (noOfComments != 1) {
99 append("s", TEXT_ITALIC);
100 }
101 if (noOfDefects > 0) {
102 append(" (", TEXT_ITALIC);
103 append(String.valueOf(noOfDefects), RED_ITALIC);
104 append(" defect", RED_ITALIC);
105 if (noOfDefects != 1) {
106 append("s", RED_ITALIC);
107 }
108 append(")", TEXT_ITALIC);
109 }
110 } catch (ValueNotYetInitialized valueNotYetInitialized) {
111
112 }
113 setIcon(expanded ? Icons.DIRECTORY_OPEN_ICON : Icons.DIRECTORY_CLOSED_ICON);
114 }
115 }
116
117 public AtlassianTreeNode getClone() {
118 return new CrucibleChangeSetTitleNode(this);
119 }
120
121 public int compareTo(Object o) {
122 if (o instanceof CrucibleChangeSetTitleNode) {
123 return 0;
124 }
125
126 return -1;
127 }
128 }