1 19 20 package org.netbeans.modules.websvc.core.jaxws; 21 22 import java.awt.Image ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import javax.swing.JPanel ; 26 import java.beans.PropertyChangeEvent ; 27 import java.beans.PropertyChangeListener ; 28 import javax.swing.border.EtchedBorder ; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.api.project.ui.OpenProjects; 31 import org.netbeans.modules.websvc.core.jaxws.nodes.JaxWsNode; 34 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; 36 import org.netbeans.modules.websvc.jaxws.api.JAXWSView; 37 import org.netbeans.modules.websvc.jaxws.api.JaxWsWsdlCookie; 38 import org.netbeans.spi.project.ui.LogicalViewProvider; 39 40 import org.openide.DialogDescriptor; 41 import org.openide.explorer.ExplorerManager; 42 import org.openide.explorer.view.BeanTreeView; 43 import org.openide.filesystems.FileObject; 44 import org.openide.nodes.AbstractNode; 45 import org.openide.nodes.Children; 46 import org.openide.nodes.Node; 47 import org.openide.nodes.FilterNode; 48 import org.openide.util.NbBundle; 49 50 54 public class JaxWsExplorerPanel extends JPanel implements ExplorerManager.Provider, PropertyChangeListener { 55 56 private DialogDescriptor descriptor; 57 private ExplorerManager manager; 58 private BeanTreeView treeView; 59 private Node selectedServiceNode; 60 61 public JaxWsExplorerPanel() { 62 manager = new ExplorerManager(); 63 selectedServiceNode = null; 64 65 initComponents(); 66 initUserComponents(); 67 } 68 69 74 private void initComponents() { 76 java.awt.GridBagConstraints gridBagConstraints; 77 78 jLblTreeView = new javax.swing.JLabel (); 79 80 setLayout(new java.awt.GridBagLayout ()); 81 82 jLblTreeView.setText(NbBundle.getMessage(JaxWsExplorerPanel.class, "LBL_AvailableWebServices")); 83 gridBagConstraints = new java.awt.GridBagConstraints (); 84 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 85 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 86 gridBagConstraints.weightx = 1.0; 87 gridBagConstraints.insets = new java.awt.Insets (11, 11, 0, 11); 88 add(jLblTreeView, gridBagConstraints); 89 90 } 92 93 private javax.swing.JLabel jLblTreeView; 95 97 private void initUserComponents() { 98 treeView = new BeanTreeView(); 99 treeView.setRootVisible(false); 100 treeView.setPopupAllowed(false); 101 treeView.setBorder(new EtchedBorder ()); 102 103 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 104 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 105 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 106 gridBagConstraints.insets = new java.awt.Insets (11, 11, 0, 11); 107 gridBagConstraints.weightx = 1.0; 108 gridBagConstraints.weighty = 1.0; 109 add(treeView, gridBagConstraints); 110 jLblTreeView.setLabelFor(treeView); 111 } 112 113 public ExplorerManager getExplorerManager() { 114 return manager; 115 } 116 117 public void addNotify() { 118 super.addNotify(); 119 manager.addPropertyChangeListener(this); 120 Project[] projects = OpenProjects.getDefault().getOpenProjects(); 121 Children rootChildren = new Children.Array(); 122 AbstractNode explorerClientRoot = new AbstractNode(rootChildren); 123 List <Node> projectNodeList = new ArrayList <Node>(); 124 for (int i=0;i<projects.length;i++) { 125 LogicalViewProvider logicalProvider = (LogicalViewProvider)projects[i].getLookup().lookup(LogicalViewProvider.class); 126 if (logicalProvider!=null) { 127 Node rootNode = logicalProvider.createLogicalView(); 128 JAXWSSupport jaxWsSupport = JAXWSSupport.getJAXWSSupport(projects[i].getProjectDirectory()); 129 if (jaxWsSupport!=null && jaxWsSupport.getServices().size()>0) { 130 Node servicesNode = JAXWSView.getJAXWSView().createJAXWSView(projects[i]); 131 132 if (servicesNode!=null) { 133 Children children = new Children.Array(); 134 Node[] nodes= servicesNode.getChildren().getNodes(); 135 if (nodes!=null && nodes.length>0) { 136 Node[] serviceNodes = new Node[nodes.length]; 137 for (int j=0;j<nodes.length;j++) { 138 serviceNodes[j] = new ServiceNode((JaxWsNode)nodes[j]); 139 } 140 children.add(serviceNodes); 141 projectNodeList.add(new ProjectNode(children, rootNode)); 142 } 143 } 144 } 161 } 162 } 163 Node[] projectNodes = new Node[projectNodeList.size()]; 164 projectNodeList.<Node>toArray(projectNodes); 165 rootChildren.add(projectNodes); 166 manager.setRootContext(explorerClientRoot); 167 168 descriptor.setValid(false); 170 } 171 172 public void removeNotify() { 173 manager.removePropertyChangeListener(this); 174 super.removeNotify(); 175 } 176 177 public void setDescriptor(DialogDescriptor descriptor) { 178 this.descriptor = descriptor; 179 } 180 181 public Node getSelectedService() { 182 return selectedServiceNode; 183 } 184 185 public void propertyChange(PropertyChangeEvent evt) { 186 if(evt.getSource() == manager) { 187 if(ExplorerManager.PROP_SELECTED_NODES.equals(evt.getPropertyName())) { 188 Node nodes[] = manager.getSelectedNodes(); 189 if(nodes != null && nodes.length > 0 ) { 190 Node node = nodes[0]; 191 if(node.getCookie(JaxWsWsdlCookie.class)!=null) { 192 selectedServiceNode = node; 194 descriptor.setValid(true); 195 } else { 196 selectedServiceNode = null; 198 descriptor.setValid(false); 199 } 200 } 201 } 202 } 203 } 204 205 private class ProjectNode extends AbstractNode { 206 private Node rootNode; 207 208 ProjectNode(Children children, Node rootNode) { 209 super(children); 210 this.rootNode=rootNode; 211 setName(rootNode.getDisplayName()); 212 } 213 214 public Image getIcon(int type) { 215 return rootNode.getIcon(type); 216 } 217 218 public Image getOpenedIcon(int type) { 219 return rootNode.getOpenedIcon(type); 220 } 221 } 222 223 private class ServiceNode extends AbstractNode implements JaxWsWsdlCookie{ 224 225 private JaxWsNode serviceNode; 226 227 ServiceNode(JaxWsNode serviceNode) { 228 super(Children.LEAF); 229 this.serviceNode=serviceNode; 230 setName(serviceNode.getDisplayName()); 231 getCookieSet().add(this); 232 } 233 234 public Image getIcon(int type) { 235 return serviceNode.getIcon(type); 236 } 237 238 public Image getOpenedIcon(int type) { 239 return serviceNode.getOpenedIcon(type); 240 } 241 242 public String getWsdlURL() { 243 return serviceNode.getWsdlURL(); 244 } 245 246 } 247 } 248 | Popular Tags |