1 19 20 25 26 package org.netbeans.modules.websvc.customization.multiview; 27 28 import java.awt.Color ; 29 import java.awt.event.ActionEvent ; 30 import java.awt.event.ActionListener ; 31 import java.awt.event.ItemEvent ; 32 import java.awt.event.ItemListener ; 33 import java.util.List ; 34 import javax.swing.JComponent ; 35 import javax.swing.text.JTextComponent ; 36 import org.netbeans.modules.websvc.api.jaxws.project.config.Client; 37 import org.netbeans.modules.websvc.core.JaxWsUtils; 38 import org.netbeans.modules.websvc.customization.model.JavaMethod; 39 import org.netbeans.modules.websvc.customization.model.PortCustomization; 40 import org.netbeans.modules.websvc.customization.model.Provider; 41 import org.netbeans.modules.websvc.customization.model.impl.JAXWSQName; 42 import org.netbeans.modules.xml.multiview.ui.SectionView; 43 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme; 44 import org.netbeans.modules.xml.wsdl.model.Port; 45 import org.netbeans.modules.xml.wsdl.model.Service; 46 import org.netbeans.modules.xml.wsdl.model.WSDLComponentFactory; 47 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 48 import org.openide.DialogDisplayer; 49 import org.openide.NotifyDescriptor; 50 import org.openide.nodes.Node; 51 import org.openide.util.NbBundle; 52 import org.openide.util.WeakListeners; 53 import org.netbeans.modules.xml.multiview.Error; 54 55 59 public class PortPanel extends SaveableSectionInnerPanel { 60 private Port port; 61 private WSDLModel model; 62 private boolean wsdlDirty; 63 private DefaultItemListener defaultListener; 64 private ProviderActionListener providerActionListener; 65 private Node node; 66 67 68 public PortPanel(SectionView view, Port port, 69 Node node) { 70 super(view); 71 this.port = port; 72 this.model = this.port.getModel(); 73 this.node = node; 74 initComponents(); 75 serviceLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 76 serviceName.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 77 serviceName.setText(getParentOfPort(port)); 78 defaultMethodCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 79 portAccessMethodText.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 80 portAccessLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 81 82 sync(); 83 84 defaultListener = new DefaultItemListener(); 85 ItemListener itemListener = (ItemListener )WeakListeners.create(ItemListener .class, defaultListener, 86 defaultMethodCB); 87 defaultMethodCB.addItemListener(itemListener); 88 89 if(!isClient()){ 90 providerCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 91 providerActionListener = new ProviderActionListener(); 92 ActionListener providerListener = (ActionListener )WeakListeners.create(ActionListener .class, 93 providerActionListener, providerCB); 94 providerCB.addActionListener(providerListener); 95 } else{ 96 providerCB.setVisible(false); 97 } 98 99 addModifier(portAccessMethodText); 100 addModifier(defaultMethodCB); 101 addValidatee(portAccessMethodText); 102 } 103 104 class DefaultItemListener implements ItemListener { 105 public void itemStateChanged(ItemEvent e) { 106 if(defaultMethodCB.isSelected()){ 107 portAccessMethodText.setEnabled(false); 108 portAccessMethodText.setBackground(Color.LIGHT_GRAY); 109 } else{ 110 portAccessMethodText.setEnabled(true); 111 portAccessMethodText.setBackground(Color.WHITE); 112 portAccessMethodText.requestFocus(); 113 } 114 } 115 } 116 117 class ProviderActionListener implements ActionListener { 118 public void actionPerformed(ActionEvent e) { 119 if(e.getSource() == providerCB){ 120 if(providerCB.isSelected()){ 121 NotifyDescriptor.Confirmation notifyDesc = 122 new NotifyDescriptor.Confirmation(NbBundle.getMessage 123 (ExternalBindingTablePanel.class, "WARN_PROVIDER_INTERFACE"), 124 NotifyDescriptor.YES_NO_OPTION); 125 DialogDisplayer.getDefault().notify(notifyDesc); 126 if((notifyDesc.getValue() == NotifyDescriptor.NO_OPTION)){ 127 providerCB.setSelected(false); 128 return; 129 } 130 } 131 setValue(providerCB, null); 132 } 133 } 134 } 135 136 private boolean isClient(){ 137 Client client = (Client)node.getLookup().lookup(Client.class); 138 return client != null; 139 } 140 141 private String getParentOfPort(Port port){ 142 Service service = (Service)port.getParent(); 143 return service.getName(); 144 } 145 private void sync(){ 146 List <PortCustomization> ee = port.getExtensibilityElements(PortCustomization.class); 147 if(ee.size() == 1){ 148 PortCustomization pc = ee.get(0); 149 JavaMethod jm = pc.getJavaMethod(); 150 if(jm != null){ 151 setPortAccessMethod(jm.getName()); 152 } else{ 153 defaultMethodCB.setSelected(true); 154 portAccessMethodText.setEnabled(false); 155 portAccessMethodText.setBackground(Color.LIGHT_GRAY); 156 } 157 Provider provider = pc.getProvider(); 158 if(provider != null){ 159 if(provider.isEnabled()){ 160 providerCB.setSelected(true); 161 }else{ 162 providerCB.setSelected(false); 163 } 164 } else{ 165 providerCB.setSelected(false); 166 } 167 } else{ 168 providerCB.setSelected(false); 169 defaultMethodCB.setSelected(true); 170 portAccessMethodText.setEnabled(false); 171 portAccessMethodText.setBackground(Color.LIGHT_GRAY); 172 } 173 } 174 175 public void setPortAccessMethod(String name){ 176 portAccessMethodText.setText(name); 177 } 178 179 public String getPortAccessMethod(){ 180 return portAccessMethodText.getText(); 181 } 182 183 public void setProvider(boolean enable){ 184 providerCB.setSelected(enable); 185 } 186 187 public boolean isProvider(){ 188 return providerCB.isSelected(); 189 } 190 191 public JComponent getErrorComponent(String string) { 192 return new javax.swing.JButton ("error"); 193 } 194 195 public void linkButtonPressed(Object object, String string) { 196 } 197 198 public void setValue(JComponent jComponent, Object object) { 199 List <PortCustomization> ee = 200 port.getExtensibilityElements(PortCustomization.class); 201 if(jComponent == providerCB){ 202 if(ee.size() == 1){ PortCustomization pc = ee.get(0); 204 Provider provider = pc.getProvider(); 205 if(isProvider()){ if(provider == null){ try{ 208 provider = (Provider) model.getFactory().create(pc, JAXWSQName.PROVIDER.getQName()); 209 model.startTransaction(); 210 provider.setEnabled(true); 211 pc.setProvider(provider); 212 wsdlDirty = true; 213 } finally{ 214 model.endTransaction(); 215 } 216 } 217 } else{ if(provider != null){ 219 try{ 220 model.startTransaction(); 221 pc.removeProvider(provider); 222 if(pc.getChildren().size() == 0){ 224 port.removeExtensibilityElement(pc); 225 } 226 wsdlDirty = true; 227 } finally{ 228 model.endTransaction(); 229 } 230 } 231 } 232 } else{ if(isProvider()){ 235 WSDLComponentFactory factory = model.getFactory(); 236 PortCustomization pc = (PortCustomization) factory.create(port, 237 JAXWSQName.BINDINGS.getQName()); 238 Provider provider = (Provider) factory.create(pc, JAXWSQName.PROVIDER.getQName()); 239 try{ 240 model.startTransaction(); 241 provider.setEnabled(true); 242 pc.setProvider(provider); 243 port.addExtensibilityElement(pc); 244 wsdlDirty = true; 245 } finally{ 246 model.endTransaction(); 247 } 248 } 249 } 250 } else if(jComponent == portAccessMethodText 251 || jComponent == defaultMethodCB ){ 252 String text = portAccessMethodText.getText(); 253 if(text != null && !text.trim().equals("") 254 && !defaultMethodCB.isSelected()){ if(!JaxWsUtils.isJavaIdentifier(text)){ 256 return; 257 } 258 if(ee.size() == 1){ PortCustomization pc = ee.get(0); 260 JavaMethod jm = pc.getJavaMethod(); 261 if(jm == null){ try{ 263 jm = (JavaMethod) model.getFactory().create(pc, JAXWSQName.METHOD.getQName()); 264 model.startTransaction(); 265 jm.setName(text); pc.setJavaMethod(jm); 267 wsdlDirty = true; 268 } finally{ 269 model.endTransaction(); 270 } 271 } else{ try{ 274 model.startTransaction(); 275 jm.setName(text); 276 wsdlDirty = true; 277 }finally{ 278 model.endTransaction(); 279 } 280 } 281 }else{ WSDLComponentFactory factory = model.getFactory(); 284 PortCustomization pc = (PortCustomization) factory.create(port, 285 JAXWSQName.BINDINGS.getQName()); 286 JavaMethod jm = (JavaMethod) factory.create(pc, JAXWSQName.METHOD.getQName()); 287 try{ 288 model.startTransaction(); 289 jm.setName(text); 290 pc.setJavaMethod(jm); 291 port.addExtensibilityElement(pc); 292 293 wsdlDirty = true; 294 }finally{ 295 model.endTransaction(); 296 } 297 } 298 } else{ if(ee.size() == 1){ 300 PortCustomization pc = ee.get(0); 301 JavaMethod jm = pc.getJavaMethod(); 302 if(jm != null){ 303 try{ 304 model.startTransaction(); 305 pc.removeJavaMethod(jm); 306 if(pc.getChildren().size() == 0){ 308 port.removeExtensibilityElement(pc); 309 } 310 wsdlDirty = true; 311 }finally{ 312 model.endTransaction(); 313 } 314 } 315 } 316 } 317 } 318 } 319 320 public void documentChanged(JTextComponent comp, String val) { 321 if(comp == portAccessMethodText){ 322 if(!JaxWsUtils.isJavaIdentifier(val)){ 323 getSectionView().getErrorPanel(). 324 setError(new Error (Error.TYPE_FATAL, 325 Error.ERROR_MESSAGE, val, comp)); 326 return; 327 } 328 } 329 getSectionView().getErrorPanel().clearError(); 330 } 331 332 public void rollbackValue(JTextComponent source) { 333 if(source == portAccessMethodText){ 334 String methodName = ""; 335 List <PortCustomization> ee = 336 port.getExtensibilityElements(PortCustomization.class); 337 if(ee.size() == 1){ 338 PortCustomization pc = ee.get(0); 339 JavaMethod jm = pc.getJavaMethod(); 340 if(jm != null){ 341 methodName = jm.getName(); 342 } 343 } 344 portAccessMethodText.setText(methodName); 345 } 346 } 347 348 public boolean wsdlIsDirty() { 349 return wsdlDirty; 350 } 351 352 public void save() { 353 if(wsdlDirty){ 354 this.setModelDirty(model); 355 } 356 } 357 358 363 private void initComponents() { 365 portAccessLabel = new javax.swing.JLabel (); 366 portAccessMethodText = new javax.swing.JTextField (); 367 providerCB = new javax.swing.JCheckBox (); 368 defaultMethodCB = new javax.swing.JCheckBox (); 369 serviceLabel = new javax.swing.JLabel (); 370 serviceName = new javax.swing.JLabel (); 371 372 portAccessLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PORT_ACCESS_METHOD")); 373 portAccessLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PORT_ACCESS_METHOD")); 374 375 portAccessMethodText.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("TOOLTIP_GET_PORT")); 376 portAccessMethodText.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PORT_ACCESS_METHOD")); 377 portAccessMethodText.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PORT_ACCESS_METHOD")); 378 379 providerCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_USE_PROVIDER").charAt(0)); 380 providerCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_PROVIDER")); 381 providerCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 382 providerCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 383 providerCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_PROVIDER")); 384 providerCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_PROVIDER")); 385 386 defaultMethodCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_USE_DEFAULT").charAt(0)); 387 defaultMethodCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 388 defaultMethodCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 389 defaultMethodCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 390 defaultMethodCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 391 defaultMethodCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 392 393 serviceLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_SERVICE")); 394 serviceLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENCLOSING_SERVICE")); 395 396 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 397 this.setLayout(layout); 398 layout.setHorizontalGroup( 399 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 400 .add(layout.createSequentialGroup() 401 .addContainerGap() 402 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 403 .add(layout.createSequentialGroup() 404 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 405 .add(serviceLabel) 406 .add(portAccessLabel)) 407 .add(14, 14, 14) 408 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 409 .add(layout.createSequentialGroup() 410 .add(portAccessMethodText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 159, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 411 .add(20, 20, 20) 412 .add(defaultMethodCB)) 413 .add(serviceName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 182, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) 414 .add(providerCB)) 415 .addContainerGap(77, Short.MAX_VALUE)) 416 ); 417 layout.setVerticalGroup( 418 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 419 .add(layout.createSequentialGroup() 420 .addContainerGap() 421 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 422 .add(serviceLabel) 423 .add(serviceName)) 424 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 22, Short.MAX_VALUE) 425 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 426 .add(portAccessLabel) 427 .add(portAccessMethodText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 428 .add(defaultMethodCB)) 429 .add(21, 21, 21) 430 .add(providerCB) 431 .add(19, 19, 19)) 432 ); 433 } 435 436 private javax.swing.JCheckBox defaultMethodCB; 438 private javax.swing.JLabel portAccessLabel; 439 private javax.swing.JTextField portAccessMethodText; 440 private javax.swing.JCheckBox providerCB; 441 private javax.swing.JLabel serviceLabel; 442 private javax.swing.JLabel serviceName; 443 445 } 446 | Popular Tags |