1 19 package org.netbeans.modules.websvc.core.jaxws.nodes; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.List ; 25 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 26 import org.netbeans.modules.websvc.api.jaxws.project.config.Service; 27 import org.openide.filesystems.FileObject; 28 import org.openide.nodes.Children; 29 import org.openide.nodes.Node; 30 import java.beans.PropertyChangeListener ; 31 import org.openide.util.RequestProcessor; 32 33 34 35 public class JaxWsRootChildren extends Children.Keys { 36 JaxWsModel jaxWsModel; 37 Service[] services; 38 JaxWsListener listener; 39 FileObject[] srcRoots; 40 41 private RequestProcessor.Task updateNodeTask = RequestProcessor.getDefault().create(new Runnable () { 42 public void run() { 43 updateKeys(); 44 } 45 }); 46 47 public JaxWsRootChildren(JaxWsModel jaxWsModel, FileObject[] srcRoots) { 48 this.jaxWsModel = jaxWsModel; 49 this.srcRoots=srcRoots; 50 } 51 52 protected void addNotify() { 53 super.addNotify(); 54 listener = new JaxWsListener(); 55 jaxWsModel.addPropertyChangeListener(listener); 56 updateKeys(); 57 } 58 59 protected void removeNotify() { 60 setKeys(Collections.EMPTY_SET); 61 jaxWsModel.removePropertyChangeListener(listener); 62 super.removeNotify(); 63 } 64 65 private void updateKeys() { 66 List keys = new ArrayList (); 67 services = jaxWsModel.getServices(); 68 if (services != null) { 69 for (int i = 0; i < services.length; i++) { 70 keys.add(services[i]); 72 } 73 } 74 setKeys(keys); 75 } 76 77 protected Node[] createNodes(Object key) { 78 if(key instanceof Service) { 79 String implClass = ((Service)key).getImplementationClass(); 80 for (FileObject srcRoot:srcRoots) { 81 FileObject implClassFo = getImplementationClass(implClass, srcRoot); 82 if (implClassFo!=null) 83 return new Node[] {new JaxWsNode(jaxWsModel, (Service)key, srcRoot, implClassFo)}; 84 } 85 } 86 return new Node[0]; 87 } 88 89 class JaxWsListener implements PropertyChangeListener { 90 public void propertyChange(PropertyChangeEvent evt) { 91 updateNodeTask.schedule(2000); 92 } 93 } 94 95 private FileObject getImplementationClass(String implClass, FileObject srcRoot) { 96 if(implClass != null && srcRoot!=null) { 97 return srcRoot.getFileObject(implClass.replace('.','/')+".java"); 98 } 100 return null; 101 } 102 103 } 104 | Popular Tags |