1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.mindcrimeilab.xsanalyzer.ui.panels;
19
20 import java.awt.BorderLayout;
21
22 import javax.swing.JPanel;
23 import javax.swing.JScrollPane;
24 import javax.swing.JTree;
25 import javax.swing.ScrollPaneConstants;
26 import javax.swing.tree.TreeModel;
27
28 import org.apache.xerces.xs.XSObject;
29
30 import de.mindcrimeilab.swing.util.JTreeHelper;
31 import de.mindcrimeilab.xsanalyzer.model.TypeHierarchyTreeModelAdapter;
32 import de.mindcrimeilab.xsanalyzer.ui.renderer.SchemaElementsRenderer;
33
34
35
36
37
38
39
40
41
42 public class TypeHierarchyPanel extends JPanel {
43
44
45
46
47 private static final long serialVersionUID = -131361261198571107L;
48
49
50
51
52 private JTree jtTypeHierarchy;
53
54
55
56
57 public TypeHierarchyPanel() {
58 super(new BorderLayout());
59 initializeGui();
60 }
61
62
63
64
65 private final void initializeGui() {
66 jtTypeHierarchy = new JTree();
67 jtTypeHierarchy.setCellRenderer(new SchemaElementsRenderer());
68 add(new JScrollPane(jtTypeHierarchy, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
69 }
70
71
72
73
74
75
76 public XSObject getType() {
77 final TreeModel model = jtTypeHierarchy.getModel();
78 Object node = null;
79 if (null != model) {
80 node = model.getRoot();
81 while (!model.isLeaf(node)) {
82 node = model.getChild(node, model.getChildCount(node) - 1);
83 }
84 }
85 return (XSObject) node;
86 }
87
88
89
90
91
92
93 public void setType(XSObject type) {
94 TreeModel model = jtTypeHierarchy.getModel();
95 model = null;
96 jtTypeHierarchy.setModel(new TypeHierarchyTreeModelAdapter(type));
97 JTreeHelper.expandToLast(jtTypeHierarchy);
98 }
99 }