KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > sunresources > beans > DataSourceBeanDataNode


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 package org.netbeans.modules.j2ee.sun.ide.sunresources.beans;
20
21 import java.beans.PropertyEditor JavaDoc;
22
23 import org.openide.util.Utilities;
24 import org.openide.util.HelpCtx;
25 import org.openide.util.NbBundle;
26
27 import org.openide.nodes.Node;
28 import org.openide.nodes.Sheet;
29 import org.openide.nodes.BeanNode;
30 import org.openide.nodes.PropertySupport;
31
32 import org.openide.filesystems.FileObject;
33
34 import org.netbeans.modules.j2ee.sun.ide.editors.NameValuePairsPropertyEditor;
35 import org.netbeans.modules.j2ee.sun.ide.sunresources.resourcesloader.SunResourceDataObject;
36 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources;
37
38 /** A node to represent this object.
39  *
40  * @author nityad
41  */

42 public class DataSourceBeanDataNode extends BaseResourceNode implements java.beans.PropertyChangeListener JavaDoc{
43     private DataSourceBean resource = null;
44     
45     public DataSourceBeanDataNode(SunResourceDataObject obj, DataSourceBean key) {
46         super(obj);
47         resource = key;
48         setIconBaseWithExtension("org/netbeans/modules/j2ee/sun/ide/resources/ResNodeNodeIcon.gif"); //NOI18N
49
setShortDescription (NbBundle.getMessage (DataSourceBeanDataNode.class, "DSC_DataSourceNode"));//NOI18N
50

51         key.addPropertyChangeListener(this);
52         
53         Class JavaDoc clazz = key.getClass ();
54         try{
55             createProperties(key, Utilities.getBeanInfo(clazz));
56         } catch (Exception JavaDoc e){
57             e.printStackTrace();
58         }
59     }
60     
61     protected DataSourceBeanDataNode getDataSourceBeanDataNode(){
62         return this;
63     }
64     
65     protected DataSourceBean getDataSourceBean(){
66         return resource;
67     }
68     
69     public void propertyChange(java.beans.PropertyChangeEvent JavaDoc evt) {
70         FileObject resFile = getDataSourceBeanDataNode().getDataObject().getPrimaryFile();
71         ResourceUtils.saveNodeToXml(resFile, resource.getGraph());
72     }
73     
74     public HelpCtx getHelpCtx() {
75         return null; // new HelpCtx ("AS_Res_DataSource");//NOI18N
76
}
77     
78     public Resources getBeanGraph(){
79         return resource.getGraph();
80     }
81     
82     protected void createProperties(Object JavaDoc bean, java.beans.BeanInfo JavaDoc info) {
83         BeanNode.Descriptor d = BeanNode.computeProperties(bean, info);
84         Node.Property p = new PropertySupport.ReadWrite(
85                 "extraParams", DataSourceBeanDataNode.class, //NOI18N
86
NbBundle.getMessage(DataSourceBeanDataNode.class,"LBL_ExtParams"), //NOI18N
87
NbBundle.getMessage(DataSourceBeanDataNode.class,"DSC_ExtParams") //NOI18N
88
) {
89             public Object JavaDoc getValue() {
90                 return resource.getExtraParams();
91             }
92             
93             public void setValue(Object JavaDoc val){
94                 if (val instanceof Object JavaDoc[])
95                     resource.setExtraParams((Object JavaDoc[])val);
96             }
97             
98             public PropertyEditor JavaDoc getPropertyEditor(){
99                 return new NameValuePairsPropertyEditor(resource.getExtraParams());
100             }
101         };
102         
103         Sheet sets = getSheet();
104         Sheet.Set pset = Sheet.createPropertiesSet();
105         pset.put(d.property);
106         pset.put(p);
107         //pset.setValue("propertiesHelpID", "AS_Res_DataSource_Props"); //NOI18N
108
sets.put(pset);
109     }
110     
111 }
112
Popular Tags