KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > context > ContextDebugProvider


1 package org.columba.core.gui.context;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.util.Iterator JavaDoc;
5
6 import javax.swing.ImageIcon JavaDoc;
7 import javax.swing.JComponent JavaDoc;
8 import javax.swing.JPanel JavaDoc;
9 import javax.swing.JTree JavaDoc;
10 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
11 import javax.swing.tree.DefaultTreeModel JavaDoc;
12
13 import org.columba.api.gui.frame.IFrameMediator;
14 import org.columba.core.context.api.IContextProvider;
15 import org.columba.core.context.base.api.IName;
16 import org.columba.core.context.base.api.IStructureValue;
17 import org.columba.core.context.semantic.api.ISemanticContext;
18 import org.columba.core.resourceloader.IconKeys;
19 import org.columba.core.resourceloader.ImageLoader;
20
21 public class ContextDebugProvider extends JPanel JavaDoc implements IContextProvider {
22
23     private JTree JavaDoc tree;
24
25     private DefaultTreeModel JavaDoc treeModel;
26
27     public ContextDebugProvider() {
28         super();
29
30         setLayout(new BorderLayout JavaDoc());
31         tree = new JTree JavaDoc();
32         add(tree, BorderLayout.CENTER);
33 // JScrollPane scrollPane = new JScrollPane(tree);
34
// scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
35
//
36
// add(scrollPane, BorderLayout.CENTER);
37

38     }
39
40     public String JavaDoc getTechnicalName() {
41         return "context_debug_view";
42     }
43     
44     public String JavaDoc getName() {
45         return "Context Debug View";
46     }
47
48     public String JavaDoc getDescription() {
49         return "Context Debug View - only visible if Columba is in DEBUG mode";
50     }
51
52     public ImageIcon JavaDoc getIcon() {
53         return ImageLoader.getSmallIcon(IconKeys.COMPUTER);
54     }
55
56     public int getTotalResultCount() {
57         return 5;
58     }
59
60     public void search(ISemanticContext context, int startIndex, int resultCount) {
61         IStructureValue value = context.getValue();
62         if ( value == null ) return;
63         
64         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
65         buf.append(value.getName());
66         DefaultMutableTreeNode JavaDoc root = new DefaultMutableTreeNode JavaDoc(buf.toString());
67
68         createTree(root, value);
69         treeModel = new DefaultTreeModel JavaDoc(root);
70     }
71
72     private void createTree(DefaultMutableTreeNode JavaDoc parent, IStructureValue value) {
73         Iterator JavaDoc<IName> it = value.getAllAttributeNames();
74         while (it.hasNext()) {
75             IName name = it.next();
76             String JavaDoc str = value.getObject(name.getName(), name.getNamespace()).toString();
77             
78             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
79             buf.append(name.getName());
80             buf.append(":");
81             buf.append(str);
82             DefaultMutableTreeNode JavaDoc child = new DefaultMutableTreeNode JavaDoc(buf.toString());
83             parent.add(child);
84         }
85
86         Iterator JavaDoc<IName> it2 = value.getAllChildNames();
87         while (it2.hasNext()) {
88             IName name = it2.next();
89             Iterator JavaDoc<IStructureValue> childIt = value.getChildIterator(name
90                     .getName(), name.getNamespace());
91             while (childIt.hasNext()) {
92                 IStructureValue child = childIt.next();
93                 StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
94                 buf.append(child.getName());
95                 DefaultMutableTreeNode JavaDoc childNode = new DefaultMutableTreeNode JavaDoc(buf.toString());
96                 parent.add(childNode);
97                 createTree(childNode, child);
98             }
99         }
100     }
101
102     public JComponent JavaDoc getView() {
103         return this;
104     }
105
106     public void showResult() {
107         tree.setModel(treeModel);
108     }
109
110     public void clear() {
111         treeModel = new DefaultTreeModel JavaDoc(new DefaultMutableTreeNode JavaDoc());
112         tree.setModel(treeModel);
113     }
114
115     public boolean isEnabledShowMoreLink() {
116         return false;
117     }
118
119     public void showMoreResults(IFrameMediator mediator) {
120     }
121
122     
123
124 }
125
Popular Tags