1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.atlassian.theplugin.idea.ui.tree;
18
19 import javax.swing.*;
20 import javax.swing.tree.DefaultMutableTreeNode;
21 import javax.swing.tree.TreeCellRenderer;
22 import java.awt.*;
23
24 public abstract class AtlassianTreeNode extends DefaultMutableTreeNode implements Comparable {
25 private AtlassianClickAction action;
26
27 protected AtlassianTreeNode(AtlassianClickAction action) {
28 this.action = action;
29 }
30
31 public void addNode(AtlassianTreeNode newChild) {
32 super.add(newChild);
33 }
34
35 @Override
36 public AtlassianTreeNode getChildAt(final int i) {
37 return (AtlassianTreeNode) super.getChildAt(i);
38 }
39
40 public abstract TreeCellRenderer getTreeCellRenderer();
41
42 public AtlassianClickAction getAtlassianClickAction() {
43 return action;
44 }
45
46 public abstract AtlassianTreeNode getClone();
47
48 public AtlassianTreeNode filter(final Filter filter) {
49 AtlassianTreeNode result = null;
50 if (filter.isValid(this)) {
51 AtlassianTreeNode tempResult = getClone();
52 boolean foundValidChild = false;
53 for (int i = 0; i < getChildCount(); i++) {
54 AtlassianTreeNode child = getChildAt(i).filter(filter);
55 if (child != null) {
56 foundValidChild = true;
57 tempResult.addNode(child);
58 }
59 }
60 if (foundValidChild || getChildCount() == 0) {
61 result = tempResult;
62 }
63 }
64 return result;
65 }
66
67 public static final AtlassianTreeNode EMPTY_NODE = new AtlassianTreeNode(AtlassianClickAction.EMPTY_ACTION) {
68 @Override
69 public TreeCellRenderer getTreeCellRenderer() {
70 return new TreeCellRenderer() {
71 public Component getTreeCellRendererComponent(final JTree jTree, final Object o, final boolean b,
72 final boolean b1, final boolean b2, final int i, final boolean b3) {
73 return new JLabel("<Empty>");
74 }
75 };
76 }
77
78 @Override
79 public AtlassianTreeNode getClone() {
80 return AtlassianTreeNode.EMPTY_NODE;
81 }
82
83 public int compareTo(Object o) {
84
85 return -1;
86 }
87 };
88
89 }