1 19 package org.netbeans.modules.websvc.jaxrpc.nodes; 20 21 import org.openide.nodes.Children; 22 import org.openide.nodes.Node; 23 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices; 24 import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription; 25 import java.util.Collections ; 26 import java.util.List ; 27 import java.util.ArrayList ; 28 import org.openide.filesystems.FileObject; 29 import org.netbeans.api.project.FileOwnerQuery; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; 32 import org.netbeans.modules.j2ee.dd.api.webservices.DDProvider; 33 import org.openide.filesystems.FileChangeListener; 34 import org.openide.filesystems.FileChangeAdapter; 35 import java.beans.PropertyChangeListener ; 36 37 public class WebServicesChildren extends Children.Keys implements PropertyChangeListener { 38 Webservices webServices; 39 WebServicesSupport wsSupport; 40 FileObject srcRoot; 41 DDProvider wsDDProvider; 42 FileObject ddFolder; 43 FileChangeListener ddFolderListener; 44 45 public WebServicesChildren(FileObject srcRoot) { 46 this.srcRoot = srcRoot; 47 Project project = FileOwnerQuery.getOwner(srcRoot); 48 this.wsSupport = WebServicesSupport. 49 getWebServicesSupport(project.getProjectDirectory()); 50 this.wsDDProvider = DDProvider.getDefault(); 51 ddFolderListener = new DDFolderFileChangeListener(); 52 } 53 54 protected void addNotify() { 55 super.addNotify(); 56 ddFolder = wsSupport.getWsDDFolder(); 57 if(ddFolder != null) { 61 ddFolder.addFileChangeListener(ddFolderListener); 62 FileObject wsDD = ddFolder.getFileObject("webservices", "xml"); 63 64 if(wsDD != null){ 65 try { 66 webServices = wsDDProvider.getDDRoot(wsSupport.getWebservicesDD()); 67 webServices.addPropertyChangeListener(this); 68 } 69 catch(java.io.IOException e) { 70 webServices = null; 71 } 74 } 75 76 updateKeys(); 77 } 78 } 79 80 protected void removeNotify() { 81 setKeys(Collections.EMPTY_SET); 82 if(ddFolder != null){ 83 ddFolder.removeFileChangeListener(ddFolderListener); 84 } 85 super.removeNotify(); 86 } 87 88 private void updateKeys() { 89 List keys = new ArrayList (); 90 try { 91 webServices = wsDDProvider.getDDRoot(wsSupport.getWebservicesDD()); 92 } 93 catch(java.io.IOException e) { 94 webServices = null; 95 } 98 if (webServices != null) { 99 WebserviceDescription[] webServiceDescriptions 100 = webServices.getWebserviceDescription(); 101 for (int i = 0; i < webServiceDescriptions.length; i++) { 102 WebserviceDescription webServiceDescription = webServiceDescriptions[i]; 103 WebServiceWrapper key = new WebServiceWrapper(webServiceDescription); 104 keys.add(key); 105 } 106 } 107 setKeys(keys); 108 } 109 110 static class WebServiceWrapper { 111 WebserviceDescription webServiceDescription; 112 113 public WebServiceWrapper(WebserviceDescription webServiceDescription) { 114 this.webServiceDescription = webServiceDescription; 115 } 116 public WebserviceDescription getWebServiceDescription() { 117 return webServiceDescription; 118 } 119 120 public boolean equals(Object obj) { 121 if(obj instanceof WebServiceWrapper) { 122 WebServiceWrapper otherObject = (WebServiceWrapper)obj; 123 return this.getWebServiceDescription().getWebserviceDescriptionName(). 124 equals(otherObject.getWebServiceDescription().getWebserviceDescriptionName()); 125 } 126 return false; 127 } 128 129 public int hashCode() { 130 return getWebServiceDescription().getWebserviceDescriptionName().hashCode(); 131 } 132 133 } 134 135 protected Node[] createNodes(Object key) { 136 if(key instanceof WebServiceWrapper) { 137 WebServiceWrapper wrapper = 138 (WebServiceWrapper)key; 139 return new Node[] {new WebServiceNode(webServices, wrapper.getWebServiceDescription(), srcRoot)}; 140 } 141 return new Node[0]; 142 } 143 144 public void propertyChange(java.beans.PropertyChangeEvent evt) { 145 updateKeys(); 146 } 147 148 class DDFolderFileChangeListener extends FileChangeAdapter{ 149 public void fileDataCreated(org.openide.filesystems.FileEvent fe) { 150 FileObject fo = fe.getFile(); 151 if(fo.getNameExt().equals("webservices.xml")){ 152 try { 153 webServices = wsDDProvider.getDDRoot(wsSupport.getWebservicesDD()); 154 webServices.addPropertyChangeListener(WebServicesChildren.this); 156 } 157 catch(java.io.IOException e) { 158 webServices = null; 159 } 162 163 } 164 } 165 } 166 167 } 168 | Popular Tags |