1 19 20 package org.netbeans.modules.websvc.jaxrpc.client.ui; 21 22 import java.io.File ; 23 import java.net.URL ; 24 import java.net.MalformedURLException ; 25 import java.awt.Color ; 26 27 import javax.swing.event.DocumentEvent ; 28 import javax.swing.event.DocumentListener ; 29 30 import org.openide.DialogDescriptor; 31 import org.openide.util.NbBundle; 32 import org.openide.filesystems.FileObject; 33 34 import org.netbeans.modules.websvc.api.webservices.WsCompileEditorSupport; 35 36 40 public class RefreshWsdlPanel extends javax.swing.JPanel { 41 42 public static final Color ErrorTextForegroundColor = new Color (89, 79, 191); 43 44 private DialogDescriptor descriptor; 45 private String wsdlSource; 46 private boolean hasMultipleServices; 47 private String [] serviceNames; 48 49 50 51 public RefreshWsdlPanel(String wsdlSource, String [] supportedServices) { 52 this.wsdlSource = wsdlSource; 53 this.hasMultipleServices = (supportedServices.length > 1); 54 this.serviceNames = supportedServices; 55 56 initComponents(); 57 initUserComponents(); 58 } 59 60 65 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 67 68 jLblDescription = new javax.swing.JLabel (); 69 jLblWsdlSource = new javax.swing.JLabel (); 70 jTxtWsdlSource = new javax.swing.JTextField (); 71 jLblMultipleServices = new javax.swing.JLabel (); 72 jLblError = new javax.swing.JLabel (); 73 74 setLayout(new java.awt.GridBagLayout ()); 75 76 jLblDescription.setText(NbBundle.getMessage(RefreshWsdlPanel.class, "LBL_Description")); 77 gridBagConstraints = new java.awt.GridBagConstraints (); 78 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 79 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 80 gridBagConstraints.insets = new java.awt.Insets (11, 11, 11, 11); 81 add(jLblDescription, gridBagConstraints); 82 83 jLblWsdlSource.setLabelFor(jTxtWsdlSource); 84 jLblWsdlSource.setText(NbBundle.getMessage(RefreshWsdlPanel.class, "LBL_WsdlSource")); 85 gridBagConstraints = new java.awt.GridBagConstraints (); 86 gridBagConstraints.insets = new java.awt.Insets (0, 11, 11, 0); 87 add(jLblWsdlSource, gridBagConstraints); 88 89 gridBagConstraints = new java.awt.GridBagConstraints (); 90 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 91 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 92 gridBagConstraints.weightx = 1.0; 93 gridBagConstraints.insets = new java.awt.Insets (0, 4, 11, 11); 94 add(jTxtWsdlSource, gridBagConstraints); 95 96 jLblMultipleServices.setText(" "); 97 gridBagConstraints = new java.awt.GridBagConstraints (); 98 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 99 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 100 gridBagConstraints.insets = new java.awt.Insets (0, 11, 0, 11); 101 add(jLblMultipleServices, gridBagConstraints); 102 103 jLblError.setText("xxx"); 104 gridBagConstraints = new java.awt.GridBagConstraints (); 105 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 106 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 107 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; 108 gridBagConstraints.weightx = 1.0; 109 gridBagConstraints.weighty = 1.0; 110 gridBagConstraints.insets = new java.awt.Insets (11, 11, 11, 11); 111 add(jLblError, gridBagConstraints); 112 113 } 115 116 private javax.swing.JLabel jLblDescription; 118 private javax.swing.JLabel jLblError; 119 private javax.swing.JLabel jLblMultipleServices; 120 private javax.swing.JLabel jLblWsdlSource; 121 private javax.swing.JTextField jTxtWsdlSource; 122 124 private void initUserComponents() { 125 jLblError.setForeground(ErrorTextForegroundColor); 126 jTxtWsdlSource.setText(wsdlSource); 127 128 jTxtWsdlSource.getDocument().addDocumentListener(new DocumentListener () { 129 public void removeUpdate(DocumentEvent e) { 130 updateWsdlSource(); 131 } 132 public void insertUpdate(DocumentEvent e) { 133 updateWsdlSource(); 134 } 135 public void changedUpdate(DocumentEvent e) { 136 updateWsdlSource(); 137 } 138 }); 139 140 if(hasMultipleServices) { 141 StringBuffer buf = new StringBuffer (16+16*serviceNames.length); 142 for(int i = 0; i < serviceNames.length; i++) { 143 if(i > 0) { 144 buf.append(", "); } 146 buf.append(serviceNames[i]); 147 } 148 jLblMultipleServices.setText(NbBundle.getMessage(RefreshWsdlPanel.class, 149 "LBL_MultipleServiceWarning", buf.toString())); } else { 151 jLblMultipleServices.setText(" "); } 153 } 154 155 public void addNotify() { 156 super.addNotify(); 157 158 checkSettings(); 159 } 160 161 private void updateWsdlSource() { 162 wsdlSource = jTxtWsdlSource.getText(); 163 checkSettings(); 164 } 165 166 public String getWsdlSource() { 167 return wsdlSource; 168 } 169 170 public void setDescriptor(DialogDescriptor descriptor) { 171 this.descriptor = descriptor; 172 } 173 174 private boolean checkSettings() { 175 String message = validateSettings(); 176 if(message != null) { 177 jLblError.setText(message); 178 } else { 179 jLblError.setText(" "); 180 } 181 182 boolean isValid = (message == null); 183 descriptor.setValid(isValid); 184 return isValid; 185 } 186 187 private String validateSettings() { 188 String message = null; 189 190 if(wsdlSource == null || wsdlSource.length() == 0) { 191 message = NbBundle.getMessage(RefreshWsdlPanel.class, "ERR_EnterSourceWsdlPath"); } else if(wsdlSource.indexOf("://") != -1) { try { 194 URL wsdlSourceUrl = new URL (wsdlSource); 195 } catch(MalformedURLException ex) { 196 message = NbBundle.getMessage(RefreshWsdlPanel.class, "ERR_InvalidURL", ex.getLocalizedMessage()); } 199 } else { 200 File wsdlSourceFile = new File (wsdlSource); 201 if(!wsdlSourceFile.exists()) { 202 message = NbBundle.getMessage(RefreshWsdlPanel.class, "ERR_FileDoesNotExist"); } 204 } 205 206 return message; 207 } 208 } 209 | Popular Tags |