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.JButton ; 35 import javax.swing.JComponent ; 36 import javax.swing.text.JTextComponent ; 37 import org.netbeans.modules.websvc.customization.model.DefinitionsCustomization; 38 import org.netbeans.modules.websvc.customization.model.EnableAsyncMapping; 39 import org.netbeans.modules.websvc.customization.model.EnableMIMEContent; 40 import org.netbeans.modules.websvc.customization.model.EnableWrapperStyle; 41 import org.netbeans.modules.websvc.customization.model.JavaPackage; 42 import org.netbeans.modules.websvc.api.jaxws.project.config.Client; 43 import org.netbeans.modules.xml.multiview.ui.SectionView; 44 import org.netbeans.modules.xml.multiview.ui.SectionVisualTheme; 45 import org.netbeans.modules.xml.wsdl.model.Definitions; 46 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 47 import org.openide.nodes.Node; 48 import org.netbeans.modules.xml.multiview.Error; 49 import org.netbeans.modules.websvc.customization.model.CustomizationComponentFactory; 50 import org.netbeans.modules.websvc.api.jaxws.project.config.Service; 51 import org.openide.util.NbBundle; 52 import org.openide.util.WeakListeners; 53 54 58 public class DefinitionsPanel extends SaveableSectionInnerPanel { 59 private Definitions definitions; 60 private WSDLModel model; 61 private Node node; 62 63 private boolean wsdlDirty; 64 private boolean packageNameDirty; 65 private DefinitionsActionListener listener; 66 private DefaultItemListener defaultListener; 67 68 69 public DefinitionsPanel(SectionView view, Definitions definitions, 70 Node node) { 71 super(view); 72 this.definitions = definitions; 73 this.model = this.definitions.getModel(); 74 this.node = node; 75 initComponents(); 76 if(!isClient(node)){ 77 enableAsyncMappingCB.setVisible(false); 78 } 79 this.enableAsyncMappingCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 80 this.enableMIMEContentCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 81 this.enableWrapperStyleCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 82 packageLabel.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 83 packageNameText.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 84 defaultPackageCB.setBackground(SectionVisualTheme.getDocumentBackgroundColor()); 85 86 enableAsyncMappingCB.setToolTipText(NbBundle.getMessage(DefinitionsPanel.class, "TOOLTIP_ENABLE_ASYNC")); 87 enableWrapperStyleCB.setToolTipText(NbBundle.getMessage(DefinitionsPanel.class, "TOOLTIP_ENABLE_WRAPPER")); 88 enableMIMEContentCB.setToolTipText(NbBundle.getMessage(DefinitionsPanel.class, "TOOLTIP_ENABLE_MIME")); 89 packageNameText.setToolTipText(NbBundle.getMessage(DefinitionsPanel.class, "TOOLTIP_PACKAGE")); 90 wsdlDirty = false; 91 packageNameDirty = false; 92 setInitialPackage(); 93 sync(); 94 95 defaultListener = new DefaultItemListener(); 96 ItemListener itemListener = (ItemListener )WeakListeners.create(ItemListener .class, defaultListener, 97 defaultPackageCB); 98 defaultPackageCB.addItemListener(itemListener); 99 100 addValidatee(packageNameText); 101 102 listener = new DefinitionsActionListener(); 103 addModifier(packageNameText); 104 addModifier(defaultPackageCB); 105 106 ActionListener eamListener = (ActionListener )WeakListeners.create(ActionListener .class, listener, enableAsyncMappingCB); 107 enableAsyncMappingCB.addActionListener(eamListener); 108 ActionListener emcListener = (ActionListener )WeakListeners.create(ActionListener .class, listener, enableMIMEContentCB); 109 enableMIMEContentCB.addActionListener(emcListener); 110 ActionListener ewsListener = (ActionListener )WeakListeners.create(ActionListener .class, listener, enableWrapperStyleCB); 111 enableWrapperStyleCB.addActionListener(ewsListener); 112 } 113 114 115 class DefinitionsActionListener implements ActionListener { 116 public void actionPerformed(ActionEvent e) { 117 setValue((JComponent )e.getSource(), null); 118 } 119 } 120 121 private void sync(){ 122 List <DefinitionsCustomization> ee = 123 definitions.getExtensibilityElements(DefinitionsCustomization.class); 124 if(ee.size() == 1){ 125 DefinitionsCustomization dc = ee.get(0); 126 EnableAsyncMapping eam = dc.getEnableAsyncMapping(); 127 if(eam != null){ 128 setEnableAsyncMapping(eam.isEnabled()); 129 } else{ setEnableAsyncMapping(false); 131 } 132 133 EnableWrapperStyle ews = dc.getEnableWrapperStyle(); 134 if(ews != null){ 135 setEnableWrapperStyle(ews.isEnabled()); 136 } else{ setEnableWrapperStyle(true); 138 } 139 EnableMIMEContent emc = dc.getEnableMIMEContent(); 140 if(emc != null){ 141 setEnableMIMEContent(emc.isEnabled()); 142 } else{ setEnableMIMEContent(false); 144 } 145 } else{ 146 setEnableAsyncMapping(false); 148 setEnableWrapperStyle(true); 149 setEnableMIMEContent(false); 150 } 151 } 152 153 private boolean useDefaultPackage(){ 154 return defaultPackageCB.isSelected(); 155 } 156 157 public void setEnableAsyncMapping(boolean enable){ 158 enableAsyncMappingCB.setSelected(enable); 159 } 160 161 public boolean getEnableAsyncMapping(){ 162 return enableAsyncMappingCB.isSelected(); 163 } 164 165 public void setEnableWrapperStyle(boolean enable){ 166 enableWrapperStyleCB.setSelected(enable); 167 } 168 169 public boolean getEnableWrapperStyle(){ 170 return enableWrapperStyleCB.isSelected(); 171 } 172 173 public void setEnableMIMEContent(boolean enable){ 174 enableMIMEContentCB.setSelected(enable); 175 } 176 177 public boolean getEnableMIMEContent(){ 178 return enableMIMEContentCB.isSelected(); 179 } 180 181 public void setPackageName(String name){ 182 packageNameText.setText(name); 183 } 184 185 public String getPackageName(){ 186 return packageNameText.getText(); 187 } 188 189 public JComponent getErrorComponent(String string) { 190 return new JButton (); 191 } 192 193 public void linkButtonPressed(Object object, String string) { 194 } 195 196 class DefaultItemListener implements ItemListener { 197 public void itemStateChanged(ItemEvent e) { 198 if(defaultPackageCB.isSelected()){ 199 packageNameText.setEnabled(false); 200 packageNameText.setBackground(Color.LIGHT_GRAY); 201 } else{ 202 packageNameText.setEnabled(true); 203 packageNameText.setBackground(Color.WHITE); 204 packageNameText.requestFocus(); 205 } 206 } 207 } 208 209 public void setValue(JComponent jComponent, Object object) { 210 List <DefinitionsCustomization> ee = 211 definitions.getExtensibilityElements(DefinitionsCustomization.class); 212 CustomizationComponentFactory factory = CustomizationComponentFactory.getDefault(); 213 if(jComponent == packageNameText || jComponent == defaultPackageCB){ 214 packageNameDirty = true; 215 } 216 else if(jComponent == enableWrapperStyleCB){ 218 if(ee.size() == 1){ DefinitionsCustomization dc = ee.get(0); 220 EnableWrapperStyle ews = dc.getEnableWrapperStyle(); 221 if(ews == null){ try{ 223 model.startTransaction(); 224 ews = factory.createEnableWrapperStyle(model); 225 ews.setEnabled(this.getEnableWrapperStyle()); 226 dc.setEnableWrapperStyle(ews); 227 wsdlDirty = true; 228 } finally{ 229 model.endTransaction(); 230 } 231 } else{ try{ 233 model.startTransaction(); 234 ews.setEnabled(this.getEnableWrapperStyle()); 235 wsdlDirty = true; 236 } finally{ 237 model.endTransaction(); 238 } 239 } 240 } else{ DefinitionsCustomization dc = factory.createDefinitionsCustomization(model); 243 EnableWrapperStyle ews = factory.createEnableWrapperStyle(model); 244 try{ 245 model.startTransaction(); 246 ews.setEnabled(this.getEnableWrapperStyle()); 247 dc.setEnableWrapperStyle(ews); 248 definitions.addExtensibilityElement(dc); 249 wsdlDirty = true; 250 } finally{ 251 model.endTransaction(); 252 } 253 } 254 } else if(jComponent == enableAsyncMappingCB){ if(ee.size() == 1){ DefinitionsCustomization dc = ee.get(0); 257 EnableAsyncMapping eam = dc.getEnableAsyncMapping(); 258 if(eam == null){ try{ 260 model.startTransaction(); 261 eam = factory.createEnableAsyncMapping(model); 262 eam.setEnabled(this.getEnableAsyncMapping()); 263 dc.setEnableAsyncMapping(eam); 264 wsdlDirty = true; 265 } finally{ 266 model.endTransaction(); 267 } 268 } else{ try{ 270 model.startTransaction(); 271 eam.setEnabled(this.getEnableAsyncMapping()); 272 wsdlDirty = true; 273 } finally{ 274 model.endTransaction(); 275 } 276 } 277 } else{ DefinitionsCustomization dc = factory.createDefinitionsCustomization(model); 280 EnableAsyncMapping eam = factory.createEnableAsyncMapping(model); 281 try{ 282 model.startTransaction(); 283 eam.setEnabled(this.getEnableAsyncMapping()); 284 dc.setEnableAsyncMapping(eam); 285 definitions.addExtensibilityElement(dc); 286 wsdlDirty = true; 287 } finally{ 288 model.endTransaction(); 289 } 290 } 291 } else if(jComponent == enableMIMEContentCB){ if(ee.size() == 1){ DefinitionsCustomization dc = ee.get(0); 294 EnableMIMEContent emc = dc.getEnableMIMEContent(); 295 if(emc == null){ try{ 297 model.startTransaction(); 298 emc = factory.createEnableMIMEContent(model); 299 emc.setEnabled(this.getEnableMIMEContent()); 300 dc.setEnableMIMEContent(emc); 301 wsdlDirty = true; 302 } finally{ 303 model.endTransaction(); 304 } 305 } else{ try{ 307 model.startTransaction(); 308 emc.setEnabled(this.getEnableMIMEContent()); 309 wsdlDirty = true; 310 } finally{ 311 model.endTransaction(); 312 } 313 } 314 } else{ DefinitionsCustomization dc = factory.createDefinitionsCustomization(model); 317 EnableMIMEContent emc = factory.createEnableMIMEContent(model); 318 try{ 319 model.startTransaction(); 320 emc.setEnabled(this.getEnableMIMEContent()); 321 dc.setEnableMIMEContent(emc); 322 definitions.addExtensibilityElement(dc); 323 324 wsdlDirty = true; 325 } finally{ 326 model.endTransaction(); 327 } 328 } 329 } 330 } 331 332 public void documentChanged(JTextComponent comp, String val) { 333 if(comp == packageNameText){ 334 if(!JavaUtilities.isValidPackageName(val)){ 335 getSectionView().getErrorPanel(). 336 setError(new Error (Error.TYPE_FATAL, 337 Error.ERROR_MESSAGE, val, comp)); 338 return; 339 } 340 } 341 getSectionView().getErrorPanel().clearError(); 342 } 343 344 public void rollbackValue(JTextComponent source) { 345 if(source == packageNameText){ 346 String pkg = ""; 347 Client c = (Client)node.getLookup().lookup(Client.class); 348 if(c != null){ 349 pkg = c.getPackageName(); 350 } else{ 351 Service s = (Service)node.getLookup().lookup(Service.class); 352 if(s != null){ 353 pkg = s.getPackageName(); 354 } 355 } 356 packageNameText.setText(pkg); 357 } 358 } 359 360 private void setInitialPackage(){ 361 Client c = (Client)node.getLookup().lookup(Client.class); 362 if(c != null){ 363 if(c.isPackageNameForceReplace()){ 364 packageNameText.setText(c.getPackageName()); 365 defaultPackageCB.setSelected(false); 366 } else{ 367 packageNameText.setEnabled(false); 368 packageNameText.setBackground(Color.LIGHT_GRAY); 369 defaultPackageCB.setSelected(true); 370 } 371 } else{ 372 Service s = (Service)node.getLookup().lookup(Service.class); 373 if(s != null){ 374 if(s.isPackageNameForceReplace()){ 375 packageNameText.setText(s.getPackageName()); 376 defaultPackageCB.setSelected(false); 377 } else{ 378 packageNameText.setEnabled(false); 379 packageNameText.setBackground(Color.LIGHT_GRAY); 380 defaultPackageCB.setSelected(true); 381 } 382 } 383 } 384 } 385 386 public boolean jaxwsIsDirty(){ 387 return packageNameDirty; 388 } 389 390 public boolean wsdlIsDirty() { 391 return wsdlDirty; 392 } 393 394 public void save() { 395 if(wsdlDirty){ 396 this.setModelDirty(model); 397 } 398 399 if(packageNameDirty){ 400 Client client = (Client)node.getLookup().lookup(Client.class); 401 Service service = (Service)node.getLookup().lookup(Service.class); 402 String packageName = getPackageName(); 403 if(useDefaultPackage() || packageName == null || 404 packageName.trim().equals("")){ 405 if(client != null){ 406 client.setPackageNameForceReplace(false); 407 }else{ 408 service.setPackageNameForceReplace(false); 409 } 410 }else{ 411 if(client != null){ 412 client.setPackageName(packageName); 413 client.setPackageNameForceReplace(true); 414 } else{ 415 service.setPackageName(packageName); 416 service.setPackageNameForceReplace(true); 417 } 418 } 419 } 420 } 421 422 427 private void initComponents() { 429 ewsButtonGroup = new javax.swing.ButtonGroup (); 430 eamButtonGroup = new javax.swing.ButtonGroup (); 431 emcButtonGroup = new javax.swing.ButtonGroup (); 432 packageLabel = new javax.swing.JLabel (); 433 packageNameText = new javax.swing.JTextField (); 434 enableWrapperStyleCB = new javax.swing.JCheckBox (); 435 enableAsyncMappingCB = new javax.swing.JCheckBox (); 436 enableMIMEContentCB = new javax.swing.JCheckBox (); 437 defaultPackageCB = new javax.swing.JCheckBox (); 438 439 packageLabel.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PACKAGE_NAME")); 440 packageLabel.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_PACKAGE_NAME")); 441 442 enableWrapperStyleCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_ENABLE_WRAPPER_STYLE").charAt(0)); 443 enableWrapperStyleCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_WRAPPER_STYLE")); 444 enableWrapperStyleCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 445 enableWrapperStyleCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 446 enableWrapperStyleCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_WRAPPER_STYLE")); 447 enableWrapperStyleCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_WRAPPER_STYLE")); 448 449 enableAsyncMappingCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_ENABLE_ASYNC_CLIENT").charAt(0)); 450 enableAsyncMappingCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_ASYNC_MAPPING")); 451 enableAsyncMappingCB.setActionCommand(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_ASYNC_MAPPING")); 452 enableAsyncMappingCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 453 enableAsyncMappingCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 454 enableAsyncMappingCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_ASYNC_MAPPING")); 455 enableAsyncMappingCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_ASYNC_MAPPING")); 456 457 enableMIMEContentCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_ENABLE_MIME_CONTENT").charAt(0)); 458 enableMIMEContentCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT")); 459 enableMIMEContentCB.setActionCommand(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT")); 460 enableMIMEContentCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 461 enableMIMEContentCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 462 enableMIMEContentCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT")); 463 enableMIMEContentCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_ENABLE_MIME_CONTENT")); 464 465 defaultPackageCB.setMnemonic(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("MNEMONIC_USE_DEFAULT").charAt(0)); 466 defaultPackageCB.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 467 defaultPackageCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0)); 468 defaultPackageCB.setMargin(new java.awt.Insets (0, 0, 0, 0)); 469 defaultPackageCB.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 470 defaultPackageCB.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/websvc/customization/multiview/Bundle").getString("LBL_USE_DEFAULT")); 471 472 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); 473 this.setLayout(layout); 474 layout.setHorizontalGroup( 475 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 476 .add(layout.createSequentialGroup() 477 .addContainerGap() 478 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 479 .add(layout.createSequentialGroup() 480 .add(packageLabel) 481 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) 482 .add(packageNameText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 173, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 483 .add(26, 26, 26) 484 .add(defaultPackageCB)) 485 .add(enableWrapperStyleCB) 486 .add(enableMIMEContentCB) 487 .add(enableAsyncMappingCB)) 488 .addContainerGap(80, Short.MAX_VALUE)) 489 ); 490 layout.setVerticalGroup( 491 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) 492 .add(layout.createSequentialGroup() 493 .addContainerGap() 494 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) 495 .add(packageLabel) 496 .add(packageNameText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) 497 .add(defaultPackageCB)) 498 .add(20, 20, 20) 499 .add(enableWrapperStyleCB) 500 .add(19, 19, 19) 501 .add(enableMIMEContentCB) 502 .add(19, 19, 19) 503 .add(enableAsyncMappingCB) 504 .addContainerGap(23, Short.MAX_VALUE)) 505 ); 506 } 508 509 private javax.swing.JCheckBox defaultPackageCB; 511 private javax.swing.ButtonGroup eamButtonGroup; 512 private javax.swing.ButtonGroup emcButtonGroup; 513 private javax.swing.JCheckBox enableAsyncMappingCB; 514 private javax.swing.JCheckBox enableMIMEContentCB; 515 private javax.swing.JCheckBox enableWrapperStyleCB; 516 private javax.swing.ButtonGroup ewsButtonGroup; 517 private javax.swing.JLabel packageLabel; 518 private javax.swing.JTextField packageNameText; 519 521 } 522 | Popular Tags |