1 19 20 25 26 package org.netbeans.modules.xml.wsdl.ui.view; 27 28 import javax.swing.event.DocumentEvent ; 29 import javax.swing.event.DocumentListener ; 30 import javax.swing.text.Document ; 31 import org.netbeans.modules.xml.wsdl.model.Binding; 32 33 import org.netbeans.modules.xml.wsdl.model.Service; 34 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 35 import org.netbeans.modules.xml.wsdl.ui.actions.NameGenerator; 36 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplate; 37 import org.netbeans.modules.xml.wsdl.ui.view.wizard.localized.LocalizedTemplateGroup; 38 39 43 public class BindingConfigurationDialogPanel extends javax.swing.JPanel { 44 45 private String mErrorMessage = null; 46 47 public static final String APPLY_CHANGE = "APPLY_CHANGE"; 48 49 public BindingConfigurationDialogPanel(WSDLModel model) { 50 mModel = model; 51 initComponents(); 52 initGUI(); 53 } 54 55 60 private void initComponents() { 62 bindingConfigurationPanel1 = new org.netbeans.modules.xml.wsdl.ui.view.BindingConfigurationPanel(); 63 commonMessagePanel1 = new org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel(); 64 65 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 66 this.setLayout(layout); 67 layout.setHorizontalGroup( 68 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 69 .add(bindingConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 420, Short.MAX_VALUE) 70 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() 71 .addContainerGap() 72 .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 301, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 73 .add(10, 10, 10)) 74 ); 75 layout.setVerticalGroup( 76 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 77 .add(layout.createSequentialGroup() 78 .add(bindingConfigurationPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE) 79 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 80 .add(commonMessagePanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 81 .addContainerGap()) 82 ); 83 } 85 private void initGUI() { 86 DocumentListener bindingNameListener = new BindingNameChangeListener(); 87 DocumentListener serviceNameListener = new ServiceNameChangeListener(); 88 DocumentListener servicePortNameListener = new ServicePortNameChangeListener(); 89 90 this.bindingConfigurationPanel1.getBindingNameTextField().getDocument().addDocumentListener(bindingNameListener); 91 this.bindingConfigurationPanel1.getServiceNameTextField().getDocument().addDocumentListener(serviceNameListener); 92 this.bindingConfigurationPanel1.getServicePortTextField().getDocument().addDocumentListener(servicePortNameListener); 93 } 94 95 96 public String getBindingName() { 97 return bindingConfigurationPanel1.getBindingName(); 98 } 99 100 public void setBindingName(String bindingName) { 101 bindingConfigurationPanel1.setBindingName(bindingName); 102 103 } 104 105 public void setServiceName(String svcName) { 106 bindingConfigurationPanel1.setServiceName(svcName); 107 108 } 109 110 public void setServicePortName(String string) { 111 bindingConfigurationPanel1.setServicePortName(string); 112 113 } 114 115 public LocalizedTemplateGroup getBindingType() { 116 return bindingConfigurationPanel1.getBindingType(); 117 } 118 119 public LocalizedTemplate getBindingSubType() { 120 return bindingConfigurationPanel1.getBindingSubType(); 121 } 122 123 public String getServiceName() { 124 return bindingConfigurationPanel1.getServiceName(); 125 } 126 127 public String getServicePortName() { 128 return bindingConfigurationPanel1.getServicePortName(); 129 } 130 131 132 private boolean isValidName(String text) { 133 try { 134 boolean isValid = org.netbeans.modules.xml.xam.dom.Utils.isValidNCName(text); 135 if(!isValid) { 136 mErrorMessage = "Name \"" + text + "\" is not a valid NCName"; 137 } else { 138 mErrorMessage = null; 139 } 140 141 } catch(Exception ex) { 142 ex.printStackTrace(); 143 } 144 145 return mErrorMessage == null; 146 } 147 148 private void validateAll() { 149 boolean validBinding = isValidName(this.bindingConfigurationPanel1.getBindingName()); 150 if(!validBinding) { 151 updateMessagePanel(); 152 return; 153 } 154 155 156 boolean isBindingExist = isBindingExists(); 157 if(isBindingExist) { 158 updateMessagePanel(); 159 return; 160 } 161 162 boolean validService = isValidName(this.bindingConfigurationPanel1.getServiceName()); 163 if(!validService) { 164 updateMessagePanel(); 165 return; 166 } 167 168 169 boolean validPort = isValidName(this.bindingConfigurationPanel1.getServicePortName()); 170 if(!validPort) { 171 updateMessagePanel(); 172 return; 173 } 174 175 176 String serviceName = this.bindingConfigurationPanel1.getServiceName(); 177 String portName = this.bindingConfigurationPanel1.getServicePortName(); 178 179 boolean isServicePortExist = isServicePortExists(serviceName, portName); 180 if(isServicePortExist) { 181 updateMessagePanel(); 182 return; 183 } 184 185 186 this.mErrorMessage = null; 187 updateMessagePanel(); 188 189 } 190 191 private boolean isBindingExists() { 192 boolean exist = false; 193 194 String text = this.bindingConfigurationPanel1.getBindingName(); 195 Binding b = mModel.findComponentByName(text, Binding.class); 196 197 if(b != null) { 198 this.mErrorMessage = "Binding \"" + text + "\" already exists."; 199 exist = true; 200 } 201 202 return exist; 203 } 204 205 206 207 public boolean isServicePortExists(String serviceName, String portName) { 208 boolean exist = false; 209 if(serviceName != null && portName != null) { 210 Service service = mModel.findComponentByName(serviceName, Service.class); 211 if(service != null) { 212 exist = NameGenerator.getInstance().isServicePortExists(getServicePortName(), service); 213 if (exist) { 214 this.mErrorMessage = "Service port" + getServicePortName() + " already exists."; 215 } 216 } 217 } 218 return exist; 219 } 220 221 private void updateMessagePanel() { 222 if(this.mErrorMessage != null) { 223 commonMessagePanel1.setErrorMessage(mErrorMessage); 224 firePropertyChange(APPLY_CHANGE, !commonMessagePanel1.isStateValid(), commonMessagePanel1.isStateValid()); 225 } else { 226 commonMessagePanel1.setMessage(""); 227 firePropertyChange(APPLY_CHANGE, !commonMessagePanel1.isStateValid(), commonMessagePanel1.isStateValid()); 228 } 229 } 230 231 private void isValidName(DocumentEvent e) { 232 Document doc = e.getDocument(); 233 try { 234 String text = doc.getText(0, doc.getLength()); 235 boolean isValid = org.netbeans.modules.xml.xam.dom.Utils.isValidNCName(text); 236 if(!isValid) { 237 commonMessagePanel1.setErrorMessage("Name \"" + text + "\" is not a valid NCName"); 238 } else { 239 commonMessagePanel1.setMessage(""); 240 } 241 firePropertyChange(APPLY_CHANGE, !commonMessagePanel1.isStateValid(), commonMessagePanel1.isStateValid()); 242 } catch(Exception ex) { 243 ex.printStackTrace(); 244 } 245 } 246 247 248 class BindingNameChangeListener implements DocumentListener { 249 250 public void changedUpdate(DocumentEvent e) { 251 validateAll(); 252 } 253 254 public void insertUpdate(DocumentEvent e) { 255 validateAll(); 256 } 257 258 public void removeUpdate(DocumentEvent e) { 259 validateAll(); 260 } 261 } 262 263 class ServiceNameChangeListener implements DocumentListener { 264 265 public void changedUpdate(DocumentEvent e) { 266 validateAll(); 267 } 268 269 public void insertUpdate(DocumentEvent e) { 270 validateAll(); 271 } 272 273 public void removeUpdate(DocumentEvent e) { 274 validateAll(); 275 } 276 } 277 class ServicePortNameChangeListener implements DocumentListener { 278 279 public void changedUpdate(DocumentEvent e) { 280 validateAll(); 281 } 282 283 public void insertUpdate(DocumentEvent e) { 284 validateAll(); 285 } 286 287 public void removeUpdate(DocumentEvent e) { 288 validateAll(); 289 } 290 } 291 private org.netbeans.modules.xml.wsdl.ui.view.BindingConfigurationPanel bindingConfigurationPanel1; 293 private org.netbeans.modules.xml.wsdl.ui.view.common.CommonMessagePanel commonMessagePanel1; 294 private WSDLModel mModel; 296 297 } 320 | Popular Tags |