1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.jadira.dependencynavigator.gui;
19
20 import org.jadira.dependencynavigator.model.Artifact;
21
22 import javax.swing.event.TreeModelListener;
23 import javax.swing.tree.TreeModel;
24 import javax.swing.tree.TreePath;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 public class DependencyTreeModel implements TreeModel {
29 private Artifact root;
30 private List<TreeModelListener> listeners;
31
32 public DependencyTreeModel(Artifact root) {
33 this.root = root;
34 listeners = new ArrayList<TreeModelListener>();
35 }
36
37 public Artifact getRoot() {
38 return root;
39 }
40
41 public int getChildCount(Object parent) {
42 Artifact parentArtifact = (Artifact) parent;
43 if (parentArtifact.isLeaf()) {
44 return 0;
45 }
46 return parentArtifact.getDependencies().size();
47 }
48
49 public boolean isLeaf(Object node) {
50 Artifact nodeArtifact = (Artifact) node;
51 return nodeArtifact.isLeaf();
52 }
53
54 public void addTreeModelListener(TreeModelListener l) {
55 listeners.add(l);
56 }
57
58 public void removeTreeModelListener(TreeModelListener l) {
59 listeners.remove(l);
60 }
61
62 public Object getChild(Object parent, int index) {
63 Artifact parentArtifact = (Artifact) parent;
64 return parentArtifact.getDependencies().get(index);
65 }
66
67 public int getIndexOfChild(Object parent, Object child) {
68 Artifact parentArtifact = (Artifact) parent;
69 return parentArtifact.getDependencies().indexOf(child);
70 }
71
72 public void valueForPathChanged(TreePath path, Object newValue) {
73 throw new UnsupportedOperationException();
74 }
75 }