1 19 20 25 26 package org.netbeans.modules.j2ee.sun.share.config.ui; 27 28 import java.awt.Component ; 29 import java.awt.CardLayout ; 30 import java.util.HashMap ; 31 import java.util.Map ; 32 import java.beans.Customizer ; 33 34 import javax.swing.JPanel ; 35 36 import org.openide.explorer.propertysheet.PropertySheetView; 37 import org.openide.nodes.Children; 38 import org.openide.nodes.Node; 39 import org.openide.nodes.NodeAdapter; 40 import org.openide.nodes.NodeMemberEvent; 41 42 import org.netbeans.modules.j2ee.sun.share.config.Utils; 43 import org.openide.util.Mutex; 44 45 46 50 public class ConfigBeanPanelView extends PanelView { 51 52 private CardLayout deck = new CardLayout (); 53 private Map map = new HashMap (); 54 private JPanel blankPanel = new JPanel (); 55 private static String BLANK_PANEL = "ConfigBeanPanelView_blank_panel"; 56 57 58 public ConfigBeanPanelView(Node root) { 59 setRoot(root); 60 setActivatedNodes(new Node[] { root }); 61 initComponents(); 62 } 63 64 65 protected void initComponents() { 66 setLayout(deck); 67 blankPanel.setName(BLANK_PANEL); 69 add(BLANK_PANEL, blankPanel); 70 } 71 72 78 public void showSelection(Node[] nodes) { 79 if (nodes == null || nodes.length==0) 81 return; 82 83 setActivatedNodes(nodes); 85 Node selNode = (Node) nodes[0]; 86 Component nodePanel = getPanel(selNode); 87 if (nodePanel != null) { 88 if (nodePanel == blankPanel) { 89 deck.show(this,BLANK_PANEL); 90 } 91 else { 92 deck.show(this,String.valueOf(nodePanel.hashCode())); 93 } 94 } 95 } 96 97 public Component getPanel(final Node selNode){ 98 Component panel = null; 100 ConfigBeanNode node = null; 101 if (selNode instanceof ConfigBeanNode) { 102 node = (ConfigBeanNode) selNode; 103 } 104 else { 105 return blankPanel; } 107 panel = (Component )map.get(selNode); 108 if (panel!=null) { 110 if(panel instanceof Customizer ) 111 ((Customizer )panel).setObject(node.getBean()); 112 return panel; 113 } 114 115 node.addNodeListener(new NodeAdapter() { 117 public void childrenRemoved(final NodeMemberEvent ev) { 118 Mutex.EVENT.readAccess(new Runnable () { 119 public void run() { 120 Children children = selNode.getChildren(); 121 Node[] nodes = children.getNodes(); 122 showSelection(new Node[] {nodes.length > 0 ? nodes[0] : selNode}); 124 } 125 }); 126 } 127 }); 128 129 panel = node.getCustomizer(); 133 if (panel!=null) { 134 map.put(node,panel); 135 add(String.valueOf(panel.hashCode()),panel); 136 ((Customizer )panel).setObject(node.getBean()); 137 return panel; 138 } 139 else { 140 PropertySheetView propSheetView = new PropertySheetView(); 141 propSheetView.setNodes(new Node[] {node}); 142 map.put(node, propSheetView); 143 propSheetView.setName(node.getDisplayName()); 144 add(String.valueOf(propSheetView.hashCode()), propSheetView); 145 return propSheetView; 146 } 147 } 148 } 149 | Popular Tags |