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.idea.ui.tree.AtlassianClickAction;
20 import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode;
21 import com.atlassian.theplugin.idea.ui.tree.Filter;
22 import com.intellij.ui.ColoredTreeCellRenderer;
23 import com.intellij.ui.SimpleTextAttributes;
24 import com.intellij.util.Icons;
25
26 import javax.swing.*;
27 import javax.swing.tree.TreeCellRenderer;
28
29
30
31
32
33
34
35
36 public class FolderNode extends FileNode {
37 private static final ColoredTreeCellRenderer MY_RENDERER = new FileNodeRenderer();
38
39 public FolderNode(String fullName, AtlassianClickAction action) {
40 super(fullName, action);
41 }
42
43 public FolderNode(final FileNode node) {
44 super(node);
45 }
46
47 public FolderNode(final String name) {
48 this(name, AtlassianClickAction.EMPTY_ACTION);
49 }
50
51 public AtlassianTreeNode getClone() {
52 return new FolderNode(this);
53 }
54
55 public AtlassianTreeNode filter(final Filter filter) {
56 AtlassianTreeNode result = null;
57 if (filter.isValid(this)) {
58 result = getClone();
59 for (int i = 0; i < getChildCount(); i++) {
60 AtlassianTreeNode child = getChildAt(i).filter(filter);
61 if (child != null) {
62 result.addNode(child);
63 }
64 }
65 if (result.getChildCount() <= 0) {
66 result = null;
67 }
68
69 }
70 return result;
71 }
72
73 public TreeCellRenderer getTreeCellRenderer() {
74 return MY_RENDERER;
75 }
76
77 private static class FileNodeRenderer extends ColoredTreeCellRenderer {
78 public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded,
79 boolean leaf, int row, boolean hasFocus) {
80 FileNode node = (FileNode) value;
81 append(node.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
82
83 setIcon(expanded ? Icons.DIRECTORY_OPEN_ICON : Icons.DIRECTORY_CLOSED_ICON);
84 }
85 }
86 }