KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > config > ui > ConfigBeanPanelView


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * ConfigBeanPanelView.java
22  *
23  * Created on March 6, 2003, 2:13 PM
24  */

25
26 package org.netbeans.modules.j2ee.sun.share.config.ui;
27
28 import java.awt.Component JavaDoc;
29 import java.awt.CardLayout JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.beans.Customizer JavaDoc;
33
34 import javax.swing.JPanel JavaDoc;
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 /**
47  *
48  * @author Jeri Lockhart
49  */

50 public class ConfigBeanPanelView extends PanelView {
51
52     private CardLayout JavaDoc deck = new CardLayout JavaDoc();
53     private Map JavaDoc map = new HashMap JavaDoc();
54     private JPanel JavaDoc blankPanel = new JPanel JavaDoc();
55     private static String JavaDoc BLANK_PANEL = "ConfigBeanPanelView_blank_panel";
56
57     /** Creates a new instance of ConfigBeanPanelView */
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 // setPopupAllowed(true);
68
blankPanel.setName(BLANK_PANEL);
69         add(BLANK_PANEL, blankPanel);
70     }
71
72     /** Called when explorer manager has changed the current selection.
73      * The view should display the panel corresponding to the selected nodes
74      *
75      * @param nodes the nodes used to update the view
76      *
77      */

78     public void showSelection(Node[] nodes) {
79         // Sanity check
80
if (nodes == null || nodes.length==0)
81             return;
82
83         // lookup panel to show
84
setActivatedNodes(nodes);
85         Node selNode = (Node) nodes[0];
86         Component JavaDoc 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 JavaDoc getPanel(final Node selNode){
98         // Lookup panel from node
99
Component JavaDoc panel = null;
100         ConfigBeanNode node = null;
101         if (selNode instanceof ConfigBeanNode) {
102             node = (ConfigBeanNode) selNode;
103         }
104         else {
105             return blankPanel; // Show blank panel
106
}
107         panel = (Component JavaDoc)map.get(selNode);
108         // found a panel, return it
109
if (panel!=null) {
110             if(panel instanceof Customizer JavaDoc)
111                 ((Customizer JavaDoc)panel).setObject(node.getBean());
112             return panel;
113         }
114         
115         // nodeListener will clean up when the node goes away
116
node.addNodeListener(new NodeAdapter() {
117             public void childrenRemoved(final NodeMemberEvent ev) {
118                 Mutex.EVENT.readAccess(new Runnable JavaDoc() {
119                     public void run() {
120                         Children children = selNode.getChildren();
121                         Node[] nodes = children.getNodes();
122                         // display a sibling node if possible, parent node otherwise
123
showSelection(new Node[] {nodes.length > 0 ? nodes[0] : selNode});
124                     }
125                 });
126             }
127         });
128         
129         // no current panel, use the nodes customizer instead and cache it
130
// after milestone 2, this should change to reuse the same panel instead of 1 customizer per method
131
//
132
panel = node.getCustomizer();
133         if (panel!=null) {
134             map.put(node,panel);
135             add(String.valueOf(panel.hashCode()),panel);
136             ((Customizer JavaDoc)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