1 7 package org.ejtools.adwt; 8 9 import java.awt.Dimension ; 10 import java.beans.beancontext.BeanContext ; 11 import java.beans.beancontext.BeanContextChildComponentProxy ; 12 import java.beans.beancontext.BeanContextContainerProxy ; 13 14 import javax.swing.BorderFactory ; 15 import javax.swing.JLabel ; 16 import javax.swing.JPanel ; 17 import javax.swing.JScrollPane ; 18 import javax.swing.JSplitPane ; 19 import javax.swing.SwingUtilities ; 20 import javax.swing.event.TreeModelEvent ; 21 import javax.swing.event.TreeSelectionEvent ; 22 import javax.swing.event.TreeSelectionListener ; 23 import javax.swing.tree.TreePath ; 24 25 import org.apache.log4j.lf5.viewer.categoryexplorer.TreeModelAdapter; 26 import org.ejtools.adwt.util.ObjectIndexer; 27 import org.ejtools.adwt.util.ObjectRenderer; 28 import org.ejtools.adwt.util.ObjectSearcher; 29 30 37 public class BeanContextTreePanel extends JSplitPane implements ObjectSearcher 38 { 39 40 protected BeanContextTree tree; 41 42 43 48 public BeanContextTreePanel(BeanContext beancontext) 49 { 50 this(beancontext, null); 51 } 52 53 54 60 public BeanContextTreePanel(BeanContext beancontext, String title) 61 { 62 super(JSplitPane.HORIZONTAL_SPLIT); 63 if (title != null) 64 { 65 this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title)); 66 } 67 BeanContextTreeModel model = new BeanContextTreeModel(beancontext); 68 this.tree = new BeanContextTree(model); 69 70 JScrollPane jscrollpane = new JScrollPane (tree); 71 jscrollpane.setMinimumSize(new Dimension (200, 200)); 72 jscrollpane.setPreferredSize(new Dimension (300, 400)); 73 74 final JPanel dummyMsg = new JPanel (); 75 dummyMsg.add(new JLabel ("")); 76 77 this.setLeftComponent(jscrollpane); 78 this.setRightComponent(dummyMsg); 79 80 this.tree.addTreeSelectionListener( 81 new TreeSelectionListener () 82 { 83 public void valueChanged(TreeSelectionEvent treeselectionevent) 84 { 85 final TreePath selPath = treeselectionevent.getNewLeadSelectionPath(); 86 SwingUtilities.invokeLater( 87 new Runnable () 88 { 89 public void run() 90 { 91 try 92 { 93 Object obj = selPath.getLastPathComponent(); 94 if (obj instanceof BeanContextChildComponentProxy ) 95 { 96 BeanContextChildComponentProxy beancontextchildcomponentproxy = (BeanContextChildComponentProxy ) obj; 97 BeanContextTreePanel.this.setRightComponent(beancontextchildcomponentproxy.getComponent()); 98 } 99 else if (obj instanceof BeanContextContainerProxy ) 100 { 101 BeanContextContainerProxy beancontextcontainerproxy = (BeanContextContainerProxy ) obj; 102 BeanContextTreePanel.this.setRightComponent(beancontextcontainerproxy.getContainer()); 103 } 104 BeanContextTreePanel.this.validate(); 105 } 106 catch (Exception e) 107 { 108 } 110 } 111 }); 112 } 113 }); 114 115 this.tree.getModel().addTreeModelListener( 116 new TreeModelAdapter() 117 { 118 public void treeNodesRemoved(TreeModelEvent treemodelevent) 119 { 120 BeanContextTreePanel.this.selectRoot(); 121 } 122 }); 123 } 124 125 126 132 public Object find(Object o) 133 { 134 return this.tree.find(o); 135 } 136 137 138 139 public void selectRoot() 140 { 141 this.tree.selectRoot(); 142 } 143 144 145 150 public void setIndexer(ObjectIndexer indexer) 151 { 152 this.tree.setIndexer(indexer); 153 } 154 155 156 161 public void setRenderer(ObjectRenderer renderer) 162 { 163 this.tree.setRenderer(renderer); 164 } 165 } 166 | Popular Tags |