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.tree.DefaultTreeModel;
20
21
22
23
24
25
26
27
28 public class AtlassianTreeModel extends DefaultTreeModel {
29
30 public AtlassianTreeModel(AtlassianTreeNode root) {
31 super(root);
32 }
33
34 public AtlassianTreeNode locateNode(NodeSearchAlgorithm alg) {
35 return AtlassianTreeModel.locateNode(getRoot(), alg);
36 }
37
38 public AtlassianTreeModel getFilteredModel(Filter filter) {
39 AtlassianTreeNode root = getRoot();
40 AtlassianTreeNode newRoot = root.filter(filter);
41 if (newRoot == null) {
42 newRoot = AtlassianTreeNode.EMPTY_NODE;
43 }
44 return new AtlassianTreeModel(newRoot);
45 }
46
47 @Override
48 public AtlassianTreeNode getRoot() {
49 return (AtlassianTreeNode) super.getRoot();
50 }
51
52
53 private static AtlassianTreeNode locateNode(AtlassianTreeNode startingNode, NodeSearchAlgorithm alg) {
54 if (alg.check(startingNode)) {
55 return startingNode;
56 }
57 for (int i = 0; i < startingNode.getChildCount(); i++) {
58 AtlassianTreeNode result = locateNode(startingNode.getChildAt(i), alg);
59 if (result != null) {
60 return result;
61 }
62 }
63 return null;
64 }
65
66
67 }