001: package org.columba.core.gui.context;
002:
003: import java.awt.BorderLayout;
004: import java.util.Iterator;
005:
006: import javax.swing.ImageIcon;
007: import javax.swing.JComponent;
008: import javax.swing.JPanel;
009: import javax.swing.JTree;
010: import javax.swing.tree.DefaultMutableTreeNode;
011: import javax.swing.tree.DefaultTreeModel;
012:
013: import org.columba.api.gui.frame.IFrameMediator;
014: import org.columba.core.context.api.IContextProvider;
015: import org.columba.core.context.base.api.IName;
016: import org.columba.core.context.base.api.IStructureValue;
017: import org.columba.core.context.semantic.api.ISemanticContext;
018: import org.columba.core.resourceloader.IconKeys;
019: import org.columba.core.resourceloader.ImageLoader;
020:
021: public class ContextDebugProvider extends JPanel implements
022: IContextProvider {
023:
024: private JTree tree;
025:
026: private DefaultTreeModel treeModel;
027:
028: public ContextDebugProvider() {
029: super ();
030:
031: setLayout(new BorderLayout());
032: tree = new JTree();
033: add(tree, BorderLayout.CENTER);
034: // JScrollPane scrollPane = new JScrollPane(tree);
035: // scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
036: //
037: // add(scrollPane, BorderLayout.CENTER);
038:
039: }
040:
041: public String getTechnicalName() {
042: return "context_debug_view";
043: }
044:
045: public String getName() {
046: return "Context Debug View";
047: }
048:
049: public String getDescription() {
050: return "Context Debug View - only visible if Columba is in DEBUG mode";
051: }
052:
053: public ImageIcon getIcon() {
054: return ImageLoader.getSmallIcon(IconKeys.COMPUTER);
055: }
056:
057: public int getTotalResultCount() {
058: return 5;
059: }
060:
061: public void search(ISemanticContext context, int startIndex,
062: int resultCount) {
063: IStructureValue value = context.getValue();
064: if (value == null)
065: return;
066:
067: StringBuffer buf = new StringBuffer();
068: buf.append(value.getName());
069: DefaultMutableTreeNode root = new DefaultMutableTreeNode(buf
070: .toString());
071:
072: createTree(root, value);
073: treeModel = new DefaultTreeModel(root);
074: }
075:
076: private void createTree(DefaultMutableTreeNode parent,
077: IStructureValue value) {
078: Iterator<IName> it = value.getAllAttributeNames();
079: while (it.hasNext()) {
080: IName name = it.next();
081: String str = value.getObject(name.getName(),
082: name.getNamespace()).toString();
083:
084: StringBuffer buf = new StringBuffer();
085: buf.append(name.getName());
086: buf.append(":");
087: buf.append(str);
088: DefaultMutableTreeNode child = new DefaultMutableTreeNode(
089: buf.toString());
090: parent.add(child);
091: }
092:
093: Iterator<IName> it2 = value.getAllChildNames();
094: while (it2.hasNext()) {
095: IName name = it2.next();
096: Iterator<IStructureValue> childIt = value.getChildIterator(
097: name.getName(), name.getNamespace());
098: while (childIt.hasNext()) {
099: IStructureValue child = childIt.next();
100: StringBuffer buf = new StringBuffer();
101: buf.append(child.getName());
102: DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(
103: buf.toString());
104: parent.add(childNode);
105: createTree(childNode, child);
106: }
107: }
108: }
109:
110: public JComponent getView() {
111: return this ;
112: }
113:
114: public void showResult() {
115: tree.setModel(treeModel);
116: }
117:
118: public void clear() {
119: treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
120: tree.setModel(treeModel);
121: }
122:
123: public boolean isEnabledShowMoreLink() {
124: return false;
125: }
126:
127: public void showMoreResults(IFrameMediator mediator) {
128: }
129:
130: }
|