1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 /******************************************************************************
25 * TypeTreeModel.java
26 *
27 * The underlying model for the Fact Hierarchy tree
28 *****************************************************************************/
29
30 package zeus.ontology;
31
32 import java.util.*;
33 import javax.swing.*;
34 import javax.swing.event.*;
35 import javax.swing.tree.*;
36 import zeus.concepts.*;
37 import zeus.ontology.*;
38
39
40 public class TypeTreeModel extends DefaultTreeModel {
41 public static final int FACT = 0;
42 public static final int RESTRICTION = 1;
43
44 protected static final String DEFAULT_ROOT = "#DefaultRoot#";
45 protected static final String BASIC_TYPES = "Basic Types";
46 protected static final String RESTRICTIONS = "Restrictions";
47 protected static final String FACTS = "Facts";
48 protected static final String SETS = "Set of ...";
49
50 protected OntologyDb model;
51 protected int mode;
52
53 public TypeTreeModel(OntologyDb model, int mode) {
54 super(new DefaultMutableTreeNode(DEFAULT_ROOT));
55 this.model = model;
56 this.mode = mode;
57 refresh();
58 }
59
60 void refresh() {
61 root = new DefaultMutableTreeNode(DEFAULT_ROOT);
62
63 DefaultMutableTreeNode basic, restrictions, facts, base, sets;
64 base = (DefaultMutableTreeNode)root;
65 basic = new DefaultMutableTreeNode(BASIC_TYPES);
66 restrictions = new DefaultMutableTreeNode(RESTRICTIONS);
67 facts = new DefaultMutableTreeNode(FACTS);
68
69
70
71 base.add(basic);
72 base.add(restrictions);
73
74 for(int i = 0; i < OntologyDb.BASIC_TYPES.length; i++ )
75 basic.add(new DefaultMutableTreeNode(OntologyDb.BASIC_TYPES[i]));
76
77 String[] names = model.getAllRestrictionNames();
78 for(int i = 0; i < names.length; i++ )
79 restrictions.add(new DefaultMutableTreeNode(names[i]));
80
81 if ( mode == FACT ) {
82 base.add(facts);
83 basic.add(new DefaultMutableTreeNode(OntologyDb.OBJECT_TYPE));
84
85 DefaultMutableTreeNode node;
86 node = new DefaultMutableTreeNode(model.getRoot());
87 facts.add(node);
88 createTree(node,model.getRoot());
89 }
90 reload();
91 }
92
93 protected void createTree(DefaultMutableTreeNode m_node,
94 zeus.util.TreeNode a_node) {
95
96
97
98 Vector children = a_node.getChildren();
99 zeus.util.TreeNode b_node;
100 DefaultMutableTreeNode n_node;
101
102 for(int i = 0; i < children.size(); i++ ) {
103 b_node = (zeus.util.TreeNode)children.elementAt(i);
104 n_node = new DefaultMutableTreeNode(b_node);
105 m_node.add(n_node);
106 createTree(n_node,b_node);
107 }
108 }
109 }