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.CrucibleFileInfo;
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.intellij.ui.SimpleColoredComponent;
24 import com.intellij.ui.SimpleTextAttributes;
25 import com.jgoodies.forms.layout.CellConstraints;
26 import com.jgoodies.forms.layout.FormLayout;
27
28 import javax.swing.*;
29 import javax.swing.tree.TreeCellRenderer;
30 import java.awt.*;
31
32 public class FileNameNode extends AtlassianTreeNode {
33 private ReviewData review;
34 private CrucibleFileInfo file;
35 private static final TreeCellRenderer MY_RENDERER = new MyRenderer();
36
37 public FileNameNode(ReviewData review, CrucibleFileInfo file, AtlassianClickAction action) {
38 super(action);
39 this.review = review;
40 this.file = file;
41 }
42
43 public FileNameNode(final FileNameNode node) {
44 super(node.getAtlassianClickAction());
45 this.review = node.review;
46 this.file = node.file;
47 }
48
49 public CrucibleFileInfo getFile() {
50 return file;
51 }
52
53 public ReviewData getReview() {
54 return review;
55 }
56
57 public TreeCellRenderer getTreeCellRenderer() {
58 return MY_RENDERER;
59 }
60
61 public AtlassianTreeNode getClone() {
62 return new FileNameNode(this);
63 }
64
65 private static class MyRenderer implements TreeCellRenderer {
66
67 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded,
68 boolean leaf, int row, boolean hasFocus) {
69 JPanel panel = new JPanel(new FormLayout("2dlu, left:pref:grow, 2dlu", "2dlu, pref:grow, 2dlu"));
70 SimpleColoredComponent component = new SimpleColoredComponent();
71 FileNameNode node = (FileNameNode) value;
72 CrucibleFileInfo file = node.getFile();
73 component.append(file.getFileDescriptor().getUrl(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
74
75 StringBuilder txt = new StringBuilder();
76 txt.append(" (rev: ");
77 txt.append(file.getOldFileDescriptor().getRevision());
78 txt.append("-");
79 txt.append(file.getFileDescriptor().getRevision());
80 txt.append(")");
81 component.append(txt.toString(), SimpleTextAttributes.GRAY_ITALIC_ATTRIBUTES);
82 panel.add(component, new CellConstraints(2, 2));
83
84
85 panel.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder")
86 : BorderFactory.createEmptyBorder(1, 1, 1, 1));
87 return panel;
88
89 }
90 }
91 }