1 19 package org.netbeans.modules.j2ee.sun.ide.sunresources.beans; 20 21 import java.beans.PropertyEditor ; 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 42 public class DataSourceBeanDataNode extends BaseResourceNode implements java.beans.PropertyChangeListener { 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"); setShortDescription (NbBundle.getMessage (DataSourceBeanDataNode.class, "DSC_DataSourceNode")); 51 key.addPropertyChangeListener(this); 52 53 Class clazz = key.getClass (); 54 try{ 55 createProperties(key, Utilities.getBeanInfo(clazz)); 56 } catch (Exception 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 evt) { 70 FileObject resFile = getDataSourceBeanDataNode().getDataObject().getPrimaryFile(); 71 ResourceUtils.saveNodeToXml(resFile, resource.getGraph()); 72 } 73 74 public HelpCtx getHelpCtx() { 75 return null; } 77 78 public Resources getBeanGraph(){ 79 return resource.getGraph(); 80 } 81 82 protected void createProperties(Object bean, java.beans.BeanInfo info) { 83 BeanNode.Descriptor d = BeanNode.computeProperties(bean, info); 84 Node.Property p = new PropertySupport.ReadWrite( 85 "extraParams", DataSourceBeanDataNode.class, NbBundle.getMessage(DataSourceBeanDataNode.class,"LBL_ExtParams"), NbBundle.getMessage(DataSourceBeanDataNode.class,"DSC_ExtParams") ) { 89 public Object getValue() { 90 return resource.getExtraParams(); 91 } 92 93 public void setValue(Object val){ 94 if (val instanceof Object []) 95 resource.setExtraParams((Object [])val); 96 } 97 98 public PropertyEditor 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 sets.put(pset); 109 } 110 111 } 112 | Popular Tags |