1 19 20 package org.netbeans.modules.websvc.core.jaxws.nodes; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import javax.swing.SwingUtilities ; 28 import javax.swing.event.ChangeEvent ; 29 import javax.swing.event.ChangeListener ; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientSupport; 32 import org.netbeans.modules.websvc.api.jaxws.client.JAXWSClientView; 33 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 34 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; 35 import org.netbeans.modules.websvc.jaxws.api.JAXWSView; 36 import org.netbeans.spi.project.ui.support.NodeFactory; 37 import org.netbeans.spi.project.ui.support.NodeList; 38 import org.openide.filesystems.FileObject; 39 import org.openide.nodes.Node; 40 41 45 public class WebServicesNodeFactory implements NodeFactory { 46 47 48 public WebServicesNodeFactory() { 49 } 50 51 public NodeList createNodes(Project p) { 52 assert p != null; 53 return new WsNodeList(p); 54 } 55 56 private static class WsNodeList implements NodeList<String > { 57 private static final String KEY_SERVICES = "web_services"; private static final String KEY_SERVICE_REFS = "serviceRefs"; 62 private Project project; 63 64 private List <ChangeListener > listeners = new ArrayList <ChangeListener >(); 65 private final JaxWsChangeListener jaxWsListener; 66 67 public WsNodeList(Project proj) { 68 project = proj; 69 this.jaxWsListener = new JaxWsChangeListener(); 70 } 71 72 public List <String > keys() { 73 List <String > result = new ArrayList <String >(); 74 JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class); 75 FileObject projectDir = project.getProjectDirectory(); 76 JAXWSSupport jaxwsSupport = JAXWSSupport.getJAXWSSupport(projectDir); 77 JAXWSClientSupport jaxwsClientSupport = JAXWSClientSupport.getJaxWsClientSupport(projectDir); 78 if (jaxWsModel != null) { 79 if ( jaxwsSupport != null && jaxWsModel.getServices().length>0) { 80 result.add(KEY_SERVICES); 81 } 82 if ( jaxwsClientSupport != null && jaxWsModel.getClients().length>0) { 83 result.add(KEY_SERVICE_REFS); 84 } 85 } 86 return result; 87 } 88 89 public synchronized void addChangeListener(ChangeListener l) { 90 listeners.add(l); 91 } 92 93 public synchronized void removeChangeListener(ChangeListener l) { 94 listeners.remove(l); 95 } 96 97 private void fireChange() { 98 ArrayList <ChangeListener > list = new ArrayList <ChangeListener >(); 99 synchronized (this) { 100 list.addAll(listeners); 101 } 102 Iterator <ChangeListener > it = list.iterator(); 103 while (it.hasNext()) { 104 ChangeListener elem = it.next(); 105 elem.stateChanged(new ChangeEvent ( this )); 106 } 107 } 108 109 public Node node(String key) { 110 if (KEY_SERVICES.equals(key)) { 111 JAXWSView view = JAXWSView.getJAXWSView(); 112 return view.createJAXWSView(project); 113 } else if (KEY_SERVICE_REFS.equals(key)) { 114 JAXWSClientView view = JAXWSClientView.getJAXWSClientView(); 115 return view.createJAXWSClientView(project); 116 } 117 return null; 118 } 119 120 public void addNotify() { 121 JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class); 122 if (jaxWsModel!=null) jaxWsModel.addPropertyChangeListener(jaxWsListener); 123 } 124 125 public void removeNotify() { 126 JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class); 127 if (jaxWsModel!=null) jaxWsModel.removePropertyChangeListener(jaxWsListener); 128 } 129 130 131 private final class JaxWsChangeListener implements PropertyChangeListener { 132 public void propertyChange(PropertyChangeEvent evt) { 133 SwingUtilities.invokeLater(new Runnable () { 134 public void run() { 135 fireChange(); 136 } 137 }); 138 } 139 } 140 } 141 142 } 143 | Popular Tags |