KickJava   Java API By Example, From Geeks To Geeks.

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


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.JList JavaDoc;
17 import javax.swing.JPanel JavaDoc;
18 import javax.swing.JScrollPane JavaDoc;
19 import javax.swing.JSplitPane JavaDoc;
20 import javax.swing.ListModel JavaDoc;
21 import javax.swing.SwingUtilities JavaDoc;
22 import javax.swing.event.ListDataEvent JavaDoc;
23 import javax.swing.event.ListDataListener JavaDoc;
24 import javax.swing.event.ListSelectionEvent JavaDoc;
25 import javax.swing.event.ListSelectionListener JavaDoc;
26
27 /**
28  * Description of the Class
29  *
30  * @author Laurent Etiemble
31  * @version $Revision: 1.5 $
32  */

33 public class BeanContextListPanel extends JSplitPane JavaDoc
34 {
35    /** Description of the Field */
36    protected JList JavaDoc list;
37
38
39    /**
40     * Constructor for the BeanContextListPanel object
41     *
42     * @param beancontext Description of Parameter
43     */

44    public BeanContextListPanel(BeanContext JavaDoc beancontext)
45    {
46       this(beancontext, null);
47    }
48
49
50    /**
51     * Constructor for the BeanContextListPanel object
52     *
53     * @param beancontext Description of Parameter
54     * @param s Description of Parameter
55     */

56    public BeanContextListPanel(BeanContext JavaDoc beancontext, String JavaDoc s)
57    {
58       super(1);
59       if (s != null)
60       {
61          setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), s));
62       }
63       list = new BeanContextListView(beancontext);
64       JScrollPane JavaDoc jscrollpane = new JScrollPane JavaDoc(list);
65       jscrollpane.setMinimumSize(new Dimension JavaDoc(200, 300));
66       jscrollpane.setPreferredSize(new Dimension JavaDoc(200, 300));
67       final JPanel JavaDoc dummyMsg = new JPanel JavaDoc();
68       dummyMsg.add(new JLabel JavaDoc("", 0));
69       setLeftComponent(jscrollpane);
70       setRightComponent(dummyMsg);
71       list.addListSelectionListener(
72          new ListSelectionListener JavaDoc()
73          {
74
75             public void valueChanged(ListSelectionEvent JavaDoc e)
76             {
77                if (e.getValueIsAdjusting())
78                {
79                   return;
80                }
81                final int index = list.getSelectedIndex();
82                final ListModel JavaDoc model = list.getModel();
83                SwingUtilities.invokeLater(
84                   new Runnable JavaDoc()
85                   {
86
87                      public void run()
88                      {
89                         try
90                         {
91                            Object JavaDoc obj = ((BeanContextListView.ContextElement) model.getElementAt(index)).getUserObject();
92                            if (obj instanceof BeanContextChildComponentProxy JavaDoc)
93                            {
94                               BeanContextChildComponentProxy JavaDoc beancontextchildcomponentproxy = (BeanContextChildComponentProxy JavaDoc) obj;
95                               setRightComponent(beancontextchildcomponentproxy.getComponent());
96                            }
97                            else
98                               if (obj instanceof BeanContextContainerProxy JavaDoc)
99                            {
100                               BeanContextContainerProxy JavaDoc beancontextcontainerproxy = (BeanContextContainerProxy JavaDoc) obj;
101                               setRightComponent(beancontextcontainerproxy.getContainer());
102                            }
103                            validate();
104                         }
105                         catch (Exception JavaDoc _ex)
106                         {
107                         }
108                      }
109
110                   });
111             }
112
113          });
114       list.getModel().addListDataListener(
115          new ListDataListener JavaDoc()
116          {
117
118             public void contentsChanged(ListDataEvent JavaDoc e)
119             {
120                list.clearSelection();
121                setRightComponent(dummyMsg);
122                validate();
123             }
124
125
126             public void intervalAdded(ListDataEvent JavaDoc e)
127             {
128                list.clearSelection();
129                setRightComponent(dummyMsg);
130                validate();
131             }
132
133
134             public void intervalRemoved(ListDataEvent JavaDoc e)
135             {
136                list.clearSelection();
137                setRightComponent(dummyMsg);
138                validate();
139             }
140          });
141    }
142 }
143
144
Popular Tags