KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > adwt > BeanContextTreePanel


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.adwt;
8
9 import java.awt.Dimension JavaDoc;
10 import java.beans.beancontext.BeanContext JavaDoc;
11 import java.beans.beancontext.BeanContextChildComponentProxy JavaDoc;
12 import java.beans.beancontext.BeanContextContainerProxy JavaDoc;
13
14 import javax.swing.BorderFactory JavaDoc;
15 import javax.swing.JLabel JavaDoc;
16 import javax.swing.JPanel JavaDoc;
17 import javax.swing.JScrollPane JavaDoc;
18 import javax.swing.JSplitPane JavaDoc;
19 import javax.swing.SwingUtilities JavaDoc;
20 import javax.swing.event.TreeModelEvent JavaDoc;
21 import javax.swing.event.TreeSelectionEvent JavaDoc;
22 import javax.swing.event.TreeSelectionListener JavaDoc;
23 import javax.swing.tree.TreePath JavaDoc;
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 /**
31  * Description of the Class
32  *
33  * @author Laurent Etiemble
34  * @version $Revision: 1.9 $
35  * @todo Javadoc to complete
36  */

37 public class BeanContextTreePanel extends JSplitPane JavaDoc implements ObjectSearcher
38 {
39    /** Description of the Field */
40    protected BeanContextTree tree;
41
42
43    /**
44     * Constructor for the BeanContextPanel object
45     *
46     * @param beancontext Description of Parameter
47     */

48    public BeanContextTreePanel(BeanContext JavaDoc beancontext)
49    {
50       this(beancontext, null);
51    }
52
53
54    /**
55     * Constructor for the BeanContextPanel object
56     *
57     * @param beancontext Description of Parameter
58     * @param title Description of the Parameter
59     */

60    public BeanContextTreePanel(BeanContext JavaDoc beancontext, String JavaDoc 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 JavaDoc jscrollpane = new JScrollPane JavaDoc(tree);
71       jscrollpane.setMinimumSize(new Dimension JavaDoc(200, 200));
72       jscrollpane.setPreferredSize(new Dimension JavaDoc(300, 400));
73
74       final JPanel JavaDoc dummyMsg = new JPanel JavaDoc();
75       dummyMsg.add(new JLabel JavaDoc(""));
76
77       this.setLeftComponent(jscrollpane);
78       this.setRightComponent(dummyMsg);
79
80       this.tree.addTreeSelectionListener(
81          new TreeSelectionListener JavaDoc()
82          {
83             public void valueChanged(TreeSelectionEvent JavaDoc treeselectionevent)
84             {
85                final TreePath JavaDoc selPath = treeselectionevent.getNewLeadSelectionPath();
86                SwingUtilities.invokeLater(
87                   new Runnable JavaDoc()
88                   {
89                      public void run()
90                      {
91                         try
92                         {
93                            Object JavaDoc obj = selPath.getLastPathComponent();
94                            if (obj instanceof BeanContextChildComponentProxy JavaDoc)
95                            {
96                               BeanContextChildComponentProxy JavaDoc beancontextchildcomponentproxy = (BeanContextChildComponentProxy JavaDoc) obj;
97                               BeanContextTreePanel.this.setRightComponent(beancontextchildcomponentproxy.getComponent());
98                            }
99                            else if (obj instanceof BeanContextContainerProxy JavaDoc)
100                            {
101                               BeanContextContainerProxy JavaDoc beancontextcontainerproxy = (BeanContextContainerProxy JavaDoc) obj;
102                               BeanContextTreePanel.this.setRightComponent(beancontextcontainerproxy.getContainer());
103                            }
104                            BeanContextTreePanel.this.validate();
105                         }
106                         catch (Exception JavaDoc e)
107                         {
108                            // Ignore it
109
}
110                      }
111                   });
112             }
113          });
114
115       this.tree.getModel().addTreeModelListener(
116          new TreeModelAdapter()
117          {
118             public void treeNodesRemoved(TreeModelEvent JavaDoc treemodelevent)
119             {
120                BeanContextTreePanel.this.selectRoot();
121             }
122          });
123    }
124
125
126    /**
127     * Description of the Method
128     *
129     * @param o Description of the Parameter
130     * @return Description of the Return Value
131     */

132    public Object JavaDoc find(Object JavaDoc o)
133    {
134       return this.tree.find(o);
135    }
136
137
138    /** Description of the Method */
139    public void selectRoot()
140    {
141       this.tree.selectRoot();
142    }
143
144
145    /**
146     * Sets the indexer attribute of the BeanContextTreePanel2 object
147     *
148     * @param indexer The new indexer value
149     */

150    public void setIndexer(ObjectIndexer indexer)
151    {
152       this.tree.setIndexer(indexer);
153    }
154
155
156    /**
157     * Sets the renderer attribute of the BeanContextTreePanel object
158     *
159     * @param renderer The new renderer value
160     */

161    public void setRenderer(ObjectRenderer renderer)
162    {
163       this.tree.setRenderer(renderer);
164    }
165 }
166
Popular Tags