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.JList ; 17 import javax.swing.JPanel ; 18 import javax.swing.JScrollPane ; 19 import javax.swing.JSplitPane ; 20 import javax.swing.ListModel ; 21 import javax.swing.SwingUtilities ; 22 import javax.swing.event.ListDataEvent ; 23 import javax.swing.event.ListDataListener ; 24 import javax.swing.event.ListSelectionEvent ; 25 import javax.swing.event.ListSelectionListener ; 26 27 33 public class BeanContextListPanel extends JSplitPane 34 { 35 36 protected JList list; 37 38 39 44 public BeanContextListPanel(BeanContext beancontext) 45 { 46 this(beancontext, null); 47 } 48 49 50 56 public BeanContextListPanel(BeanContext beancontext, String 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 jscrollpane = new JScrollPane (list); 65 jscrollpane.setMinimumSize(new Dimension (200, 300)); 66 jscrollpane.setPreferredSize(new Dimension (200, 300)); 67 final JPanel dummyMsg = new JPanel (); 68 dummyMsg.add(new JLabel ("", 0)); 69 setLeftComponent(jscrollpane); 70 setRightComponent(dummyMsg); 71 list.addListSelectionListener( 72 new ListSelectionListener () 73 { 74 75 public void valueChanged(ListSelectionEvent e) 76 { 77 if (e.getValueIsAdjusting()) 78 { 79 return; 80 } 81 final int index = list.getSelectedIndex(); 82 final ListModel model = list.getModel(); 83 SwingUtilities.invokeLater( 84 new Runnable () 85 { 86 87 public void run() 88 { 89 try 90 { 91 Object obj = ((BeanContextListView.ContextElement) model.getElementAt(index)).getUserObject(); 92 if (obj instanceof BeanContextChildComponentProxy ) 93 { 94 BeanContextChildComponentProxy beancontextchildcomponentproxy = (BeanContextChildComponentProxy ) obj; 95 setRightComponent(beancontextchildcomponentproxy.getComponent()); 96 } 97 else 98 if (obj instanceof BeanContextContainerProxy ) 99 { 100 BeanContextContainerProxy beancontextcontainerproxy = (BeanContextContainerProxy ) obj; 101 setRightComponent(beancontextcontainerproxy.getContainer()); 102 } 103 validate(); 104 } 105 catch (Exception _ex) 106 { 107 } 108 } 109 110 }); 111 } 112 113 }); 114 list.getModel().addListDataListener( 115 new ListDataListener () 116 { 117 118 public void contentsChanged(ListDataEvent e) 119 { 120 list.clearSelection(); 121 setRightComponent(dummyMsg); 122 validate(); 123 } 124 125 126 public void intervalAdded(ListDataEvent e) 127 { 128 list.clearSelection(); 129 setRightComponent(dummyMsg); 130 validate(); 131 } 132 133 134 public void intervalRemoved(ListDataEvent e) 135 { 136 list.clearSelection(); 137 setRightComponent(dummyMsg); 138 validate(); 139 } 140 }); 141 } 142 } 143 144 | Popular Tags |