KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConfigBeanNode.java
22  *
23  * Created on August 15, 2001, 4:29 PM
24  */

25
26 package org.netbeans.modules.j2ee.sun.share.config.ui;
27
28 import java.util.*;
29 import java.beans.*;
30 import java.awt.Image JavaDoc;
31 import java.awt.Component JavaDoc;
32
33 import javax.enterprise.deploy.spi.DConfigBean JavaDoc;
34 import javax.swing.SwingUtilities JavaDoc;
35
36 import org.openide.ErrorManager;
37 import org.openide.cookies.SaveCookie;
38 import org.openide.loaders.DataObject;
39 import org.openide.nodes.*;
40 import org.openide.util.HelpCtx;
41 import org.openide.util.WeakListeners;
42
43 import org.netbeans.modules.j2ee.sun.share.config.ConfigurationStorage;
44 import org.netbeans.modules.j2ee.sun.share.config.ConfigBeanStorage;
45 import org.netbeans.modules.j2ee.sun.share.configbean.Base;
46 import org.netbeans.modules.j2ee.sun.share.configbean.DConfigBeanProperties;
47
48
49 /**
50  *
51  * @author gfink
52  * @author Jeri Lockhart
53  * @version
54  */

55 public class ConfigBeanNode extends AbstractNode implements PropertyChangeListener {
56     
57     final ConfigBeanStorage bean;
58     final BeanInfo info;
59     final DConfigBeanProperties extraProps;
60     
61     public ConfigBeanNode(ConfigBeanStorage bean) {
62         super(new ConfigChildren(bean));
63         this.bean = bean;
64         info = ConfigUtils.createBeanInfo(bean.getConfigBean());
65
66 // extraProps = bean.getStorage().getServer().getDConfigBeanProperties(bean.getConfigBean());
67
DConfigBean JavaDoc dcb = bean.getConfigBean();
68         if(dcb instanceof Base) {
69             extraProps = ((Base) dcb).getUICustomization(dcb);
70         } else {
71             extraProps = null;
72         }
73         
74         ConfigurationStorage storage = bean.getStorage();
75         storage.addPropertyChangeListener(WeakListeners.propertyChange(this, storage));
76     }
77     
78     public String JavaDoc getDisplayName() {
79         if(extraProps != null) return extraProps.getDisplayName();
80         if(info == null) return bean.getClass().toString();
81         return info.getBeanDescriptor().getDisplayName();
82     }
83     
84     public Node.Cookie getCookie(Class JavaDoc type) {
85         if (SaveCookie.class.isAssignableFrom(type)) {
86             return bean.getStorage().getPrimaryDataObject().getCookie(type);
87         }
88         return super.getCookie(type);
89     }
90     
91     private static final javax.swing.Action JavaDoc[] EMPTY_ACTIONS = new javax.swing.Action JavaDoc[0];
92     public javax.swing.Action JavaDoc[] getActions(boolean context) {
93         return EMPTY_ACTIONS;
94     }
95     
96     public HelpCtx getHelpCtx() {
97         if(extraProps != null) {
98             String JavaDoc helpId = extraProps.getHelpId();
99             if(helpId != null) return new HelpCtx(helpId);
100         }
101         return HelpCtx.DEFAULT_HELP;
102     }
103     
104     public Image JavaDoc getIcon(int type) {
105         if(info != null) {
106             Image JavaDoc icon = info.getIcon(type);
107             if(icon != null) return icon;
108         }
109         return super.getIcon(type);
110     }
111     
112     public Image JavaDoc getOpenedIcon(int type) {
113         if(info != null) {
114             Image JavaDoc icon = info.getIcon(type);
115             if(icon != null) return icon;
116         }
117         return super.getOpenedIcon(type);
118     }
119     
120     public Sheet createSheet() {
121         Sheet ret = new Sheet();
122         Sheet.Set set = ConfigUtils.createSheet(bean);
123         set.setName(getDisplayName());
124         ret.put(set);
125         return ret;
126     }
127     
128     public DConfigBean JavaDoc getBean() {
129         return bean.getConfigBean();
130     }
131     
132     /** Get the customizer.
133      * @return <code>null</code> in the default implementation
134      *
135      */

136     public Component JavaDoc getCustomizer() {
137         Component JavaDoc comp = null;
138         if (!hasCustomizer()) {
139             return null;
140         }
141         try {
142             // If there isn't such a customizer, try the default constructor
143
return (java.awt.Component JavaDoc) info.getBeanDescriptor().getCustomizerClass().newInstance();
144         }catch (Exception JavaDoc e) {
145             ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
146         }
147         return comp;
148     }
149     
150     /** Does this node have a customizer?
151      * @return <CODE>false</CODE>
152      *
153      */

154     public boolean hasCustomizer() {
155         return info.getBeanDescriptor().getCustomizerClass() != null;
156     }
157
158     public void propertyChange(PropertyChangeEvent evt) {
159         if(DataObject.PROP_COOKIE.equals(evt.getPropertyName())) {
160             fireCookieChange();
161         }
162     }
163     
164     public static class ConfigChildren extends Children.Keys implements ConfigBeanStorage.ChildrenChangeListener {
165         ConfigBeanStorage bean;
166         ConfigChildren(ConfigBeanStorage bean) {
167             this.bean = bean;
168         }
169
170         protected void addNotify() {
171             updateKeys();
172             bean.addChildrenChangeListener(this);
173         }
174          
175         protected void removeNotify() {
176             setKeys(Collections.EMPTY_SET);
177             bean.removeChildrenChangeListener(this);
178         }
179
180         void updateKeys() {
181             setKeys(bean.getChildMap().keySet());
182         }
183         
184         void updateKey(Object JavaDoc key) {
185             refreshKey(key);
186         }
187         
188         protected Node[] createNodes(Object JavaDoc key) {
189             Collection nodeSet = (Collection) bean.getChildMap().get(key);
190             ArrayList ret = new ArrayList();
191             Iterator i = nodeSet.iterator();
192             for(int c = 0; i.hasNext(); c++) {
193                 ConfigBeanStorage cbs = (ConfigBeanStorage) i.next();
194                 Node node = cbs.getNode();
195                 if (node != null) {
196                     ret.add(node);
197                 }
198             }
199             return (Node[]) ret.toArray(new Node[ret.size()]);
200         }
201         
202         public void childBeanAdded(final ConfigBeanStorage childStorage) {
203             SwingUtilities.invokeLater(new Runnable JavaDoc() {
204                 public void run() {
205                     updateKeys();
206                     refreshKey(childStorage.getConfigBean().getDDBean().getXpath());
207                 }
208             });
209         }
210         
211         public void childBeanRemoved(final ConfigBeanStorage childStorage) {
212             SwingUtilities.invokeLater(new Runnable JavaDoc() {
213                 public void run() {
214                     updateKey(childStorage.getConfigBean().getDDBean().getXpath());
215                 }
216             });
217         }
218     }
219 }
220
Popular Tags