1 19 20 package org.netbeans.modules.websvc.dev.wizard; 21 22 23 import java.awt.Component ; 24 import java.util.Iterator ; 25 import java.util.Vector ; 26 import javax.swing.JComboBox ; 27 import org.netbeans.api.project.SourceGroup; 28 import org.netbeans.modules.j2ee.common.Util; 29 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 30 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 31 import org.netbeans.modules.websvc.spi.webservices.WebServicesConstants; 32 import org.openide.*; 33 import javax.swing.JComponent ; 34 import javax.swing.event.ChangeListener ; 35 import org.openide.util.HelpCtx; 36 import org.netbeans.api.project.Project; 37 import org.netbeans.spi.project.ui.templates.support.Templates; 38 import java.awt.event.ActionEvent ; 39 import java.awt.event.ActionListener ; 40 import javax.swing.ButtonGroup ; 41 import javax.swing.JPanel ; 42 import javax.swing.JRadioButton ; 43 import javax.swing.JCheckBox ; 44 import javax.swing.JButton ; 45 import javax.swing.event.ChangeEvent ; 46 import org.openide.util.NbBundle; 47 import java.awt.GridBagConstraints ; 48 import java.awt.GridBagLayout ; 49 import javax.swing.border.TitledBorder ; 50 import javax.swing.JLabel ; 51 import javax.swing.JTextField ; 52 import java.awt.Insets ; 53 import java.io.File ; 54 import javax.swing.event.DocumentListener ; 55 import javax.swing.event.DocumentEvent ; 56 import javax.swing.JFileChooser ; 57 import javax.swing.filechooser.FileFilter ; 58 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar; 59 import org.netbeans.modules.j2ee.dd.api.web.WebApp; 60 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 61 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 62 import org.openide.filesystems.FileUtil; 63 import org.openide.filesystems.FileObject; 64 65 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; 66 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices; 67 import org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription; 68 import org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans; 69 import org.netbeans.modules.j2ee.dd.api.ejb.Ejb; 70 import org.netbeans.modules.j2ee.dd.api.web.Servlet; 71 72 73 79 public class WebServiceWizardDescriptor implements WizardDescriptor.FinishablePanel { 80 83 private WizardDescriptor wizardDescriptor; 84 private WebServiceWizardPanel panel; 85 private WebServiceWizardHelper helper; 86 private ChangeListener listener; 87 private static String previousDirectory = ""; 88 89 private JTextField nameField; 95 private Project namespaceProject; 96 private java.util.Map webServiceNamespace; 97 98 private WizardDescriptor.Panel firstPanel; 99 100 101 public WebServiceWizardDescriptor(WizardDescriptor wizardDescriptor, WebServiceWizardHelper helper) { 102 this.wizardDescriptor = wizardDescriptor; 103 this.helper = helper; 104 105 this.nameField = null; 106 this.webServiceNamespace = null; 107 } 108 109 public void setTargetChooserPanel(WizardDescriptor.Panel panel) { 110 this.firstPanel = panel; 111 } 112 113 public boolean isFinishPanel(){ 114 return false; 115 } 116 117 public void addChangeListener(ChangeListener l) { 118 listener = l; 119 } 120 121 public void removeChangeListener(ChangeListener l) { 122 if(listener == l) { 123 listener = null; 124 } 125 } 126 127 public Component getComponent() { 128 if(panel == null){ 129 panel = new WebServiceWizardPanel(helper); 130 } 131 return panel; 132 } 133 134 public HelpCtx getHelp() { 135 return new HelpCtx(WebServiceWizardDescriptor.class); 136 } 137 138 private String validateWebServiceName(String name, java.util.Map namespace) { 139 String message = null; 140 141 if(name == null || name.length() == 0) { 142 message = NbBundle.getMessage(WebServiceWizardDescriptor.class, "MSG_EnterWebServiceName"); } else if(namespace.containsKey(name)) { 146 String messageId = (String ) namespace.get(name); 147 String servletName = "WSServlet_" + name; message = NbBundle.getMessage(WebServiceWizardDescriptor.class, messageId, name, servletName); 149 } 150 151 return message; 152 } 153 154 private java.util.Map getWSNameSpace(Project p) { 155 long start = System.currentTimeMillis(); 156 java.util.Map namespace = new java.util.HashMap (); 157 WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(p.getProjectDirectory()); 158 159 if(wsSupport != null) { 161 org.netbeans.modules.j2ee.dd.api.webservices.DDProvider wsDDProvider = 162 org.netbeans.modules.j2ee.dd.api.webservices.DDProvider.getDefault(); 163 try { 164 Webservices webServices = wsDDProvider.getDDRoot(wsSupport.getWebservicesDD()); 165 if(webServices != null) { 166 WebserviceDescription [] descriptions = webServices.getWebserviceDescription(); 167 if(descriptions != null) { 168 for(int i = 0; i < descriptions.length; i++) { 169 String wsname = descriptions[i].getWebserviceDescriptionName(); 170 if(wsname != null && wsname.length() > 0) { 171 namespace.put(wsname, "ERR_WebServiceExists"); } 173 } 174 } 175 } 176 } catch(java.io.IOException ex) { 177 } 179 180 183 J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) p.getLookup ().lookup (J2eeModuleProvider.class); 188 Object moduleType = j2eeModuleProvider.getJ2eeModule().getModuleType(); 189 if(J2eeModule.WAR.equals(moduleType)) { 190 FileObject ddFO = org.netbeans.modules.web.api.webmodule.WebModule.getWebModule(p.getProjectDirectory()).getDeploymentDescriptor(); 191 if(ddFO != null) { 192 try { 193 WebApp webApp = org.netbeans.modules.j2ee.dd.api.web.DDProvider.getDefault().getDDRoot(ddFO); 194 Servlet [] servlets = webApp.getServlet(); 195 if(servlets != null) { 196 for(int i = 0; i < servlets.length; i++) { 197 String servletName = servlets[i].getServletName(); 200 if(servletName != null && servletName.length() > 10 && servletName.startsWith("WSServlet_")) { String wsRootName = servletName.substring(10); 202 if(!namespace.containsKey(wsRootName)) { 203 namespace.put(wsRootName, "ERR_WS_ServletExists"); } 205 } 206 } 207 } 208 } catch(java.io.IOException ex) { 209 } 211 } 212 } else if(J2eeModule.EJB.equals(moduleType)) { 213 org.netbeans.modules.j2ee.api.ejbjar.EjbJar ejbjarModule = org.netbeans.modules.j2ee.api.ejbjar.EjbJar.getEjbJar(p.getProjectDirectory()); 214 try { 216 EjbJar ejbJar = org.netbeans.modules.j2ee.dd.api.ejb.DDProvider.getDefault().getMergedDDRoot(ejbjarModule.getMetadataUnit()); 217 218 EnterpriseBeans eb = ejbJar.getEnterpriseBeans(); 219 if(eb != null) { 220 Ejb [] ejbs = eb.getEjbs(); 221 if(ejbs != null) { 222 for(int i = 0; i < ejbs.length; i++) { 223 String ejbName = ejbs[i].getEjbName(); 226 if(ejbName != null && ejbName.length() > 0 && !namespace.containsKey(ejbName)) { 227 namespace.put(ejbName, "ERR_WS_EjbExists"); } 229 } 230 } 231 } 232 } catch(java.io.IOException ex) { 233 } 235 } 237 } 238 239 return namespace; 240 } 241 242 private static JComboBox findCombo(JComponent comp) { 243 Vector allComponents = new Vector (); 244 Util.getAllComponents(comp.getComponents(), allComponents); 245 Iterator iterator = allComponents.iterator(); 246 while(iterator.hasNext()) { 247 Component c = (Component )iterator.next(); 248 if(c instanceof JComboBox ) { 249 JComboBox combo = (JComboBox )c; 250 if (combo.getSelectedItem() instanceof SourceGroup) { 251 return combo; 252 } 253 } 254 } 255 return null; 256 } 257 258 public boolean isValid() { 259 Project p = Templates.getProject(wizardDescriptor); 260 261 if(!isWsCompileSupported(p)) { 263 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceWizardDescriptor.class, "ERR_WsCompileNotSupportedByTargetServer")); return false; 265 } 266 267 J2eeModuleProvider j2eeModuleProvider = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class); 268 String j2eeVersion = j2eeModuleProvider.getJ2eeModule().getModuleVersion(); 269 Object moduleType = j2eeModuleProvider.getJ2eeModule().getModuleType(); 270 if ((J2eeModule.WAR.equals(moduleType) && !WebApp.VERSION_2_4.equals(j2eeVersion)) || 271 (J2eeModule.EJB.equals(moduleType) && !EjbJar.VERSION_2_1.equals(j2eeVersion))) { 272 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceWizardDescriptor.class, "ERR_ProjectDoesNotSupportJ2EE14")); return false; 275 } 276 277 if (firstPanel != null) { 279 JComponent targetChooserGUI = (JComponent )firstPanel.getComponent(); 280 if (targetChooserGUI != null) { 281 JComboBox rootFolderCombo = findCombo(targetChooserGUI); 282 if (rootFolderCombo != null) { 283 if (rootFolderCombo.isVisible()) { 284 FileObject fo = ((SourceGroup) rootFolderCombo.getSelectedItem()).getRootFolder(); 285 if (fo != null) { 286 WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(fo); 287 if (wsSupport == null) { 288 String msg = NbBundle.getMessage(WebServiceWizard.class, "ERR_NoTargetFolder"); wizardDescriptor.putProperty("WizardPanel_errorMessage", msg); return false; 291 } 292 } 293 } else { 294 String msg = NbBundle.getMessage(WebServiceWizard.class, "ERR_NoTargetFolder"); wizardDescriptor.putProperty("WizardPanel_errorMessage", msg); return false; 297 } 298 } 299 } 300 } 301 302 if (panel != null) { 303 if(nameField != null) { 305 String wsname = nameField.getText().trim(); 306 if(webServiceNamespace == null || namespaceProject != p) { 307 webServiceNamespace = getWSNameSpace(p); 308 namespaceProject = p; 309 } 310 String message = validateWebServiceName(wsname, webServiceNamespace); 311 if(message != null) { wizardDescriptor.putProperty("WizardPanel_errorMessage", message); return false; } 315 } 316 317 if(panel.getFromWSDLButton().isSelected()) { 318 String wsdlFilePath = panel.getWSDLFilePath().trim(); 319 320 if(wsdlFilePath == null || wsdlFilePath.length() == 0) { 321 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceWizardDescriptor.class, "MSG_EnterWsdlName")); return false; } 325 326 File f = new File (wsdlFilePath); 327 String wsdlFileText = f.getAbsolutePath(); 328 f = getCanonicalFile(f); 329 if(f == null) { 330 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceWizardDescriptor.class, "ERR_WsdlInvalid")); return false; } 334 335 if(!f.exists()) { 336 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceWizardDescriptor.class, "ERR_WsdlDoesNotExist")); return false; } 340 } 341 else if(panel.getFromWSDLUrlButton().isSelected()) { 342 String wsdlUrl = panel.getWSDLUrl().trim(); 343 if(wsdlUrl == null || wsdlUrl.length() == 0) { 344 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(WebServiceWizardDescriptor.class, "MSG_EnterWsdlUrl")); return false; } 348 } 349 } 350 351 return true; 352 } 353 354 private boolean isWsCompileSupported(Project p) { 355 boolean result = true; 359 360 J2eeModuleProvider provider = (J2eeModuleProvider) p.getLookup().lookup(J2eeModuleProvider.class); 361 if(provider != null) { 362 String serverInstanceID = provider.getServerInstanceID(); 363 if(serverInstanceID != null && serverInstanceID.length() > 0) { 364 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstanceID); 365 if ((j2eePlatform == null) || (!j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE))) { 366 result = false; 367 } 368 } 369 } 370 371 return result; 372 } 373 374 379 public static File getCanonicalFile(File f) { 380 File f1; 381 try { 382 f1 = f.getCanonicalFile(); 383 } catch (java.io.IOException e) { 384 f1 = null; 385 } 386 return f1; 387 } 388 389 390 public void readSettings(Object settings) { 391 if(settings instanceof WizardDescriptor) { 392 panel.readSettings((WizardDescriptor) settings); 393 394 Project p = Templates.getProject((WizardDescriptor) settings); 395 if(p != null) { 396 if(namespaceProject != p) { 397 webServiceNamespace = getWSNameSpace(p); 398 namespaceProject = p; 399 } 400 } else { 401 webServiceNamespace = null; 402 namespaceProject = null; 403 } 404 } 405 } 406 407 public void storeSettings(Object settings) { 408 WebServiceWizardHelper helper = panel.getWizardHelper(); 409 410 if(settings instanceof WebServiceWizardHelper) { 412 helper = (WebServiceWizardHelper)settings; 413 } 414 415 if(helper != null) { 416 if(panel.isFromScratch()) { 417 helper.setCreateFrom(WebServiceWizardHelper.CREATE_FROM_SCRATCH); 418 } 419 else if(panel.isFromExistingCode()) { 420 helper.setCreateFrom(WebServiceWizardHelper.CREATE_FROM_EXISTING_CODE); 421 } 422 else if(panel.isFromWSDL()) { 423 helper.setCreateFrom(WebServiceWizardHelper.CREATE_FROM_WSDL_FILE); 424 } 425 else if(panel.isFromWSDLUrl()) { 426 helper.setCreateFrom(WebServiceWizardHelper.CREATE_FROM_WSDL_URL); 427 } 428 } 429 430 if(settings instanceof WizardDescriptor) { 431 panel.storeSettings((WizardDescriptor)settings); 432 } 433 } 434 435 class WebServiceWizardPanel extends JPanel implements DocumentListener { 436 WebServiceWizardHelper helper; 437 private final FileFilter WSDL_FILE_FILTER = new WsdlFileFilter(); 438 439 public WebServiceWizardPanel(WebServiceWizardHelper helper) { 440 this.helper = helper; 441 initComponents(); 442 addListeners(); 443 } 444 445 private void initComponents() { 446 java.awt.GridBagConstraints gridBagConstraints; 447 448 typeButtons = new ButtonGroup (); 449 450 fromScratchButton = new JRadioButton (NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromScratch")); fromScratchButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromScratch")); 452 fromScratchButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromScratch_mnem").charAt(0)); 453 454 fromWSDLButton = new JRadioButton (NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromWSDL")); fromWSDLButton.getAccessibleContext().setAccessibleDescription(fromWSDLButton.getText()); 456 fromWSDLButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromWSDL_mnem").charAt(0)); 457 458 fromWSDLUrlButton = new JRadioButton (NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromWSDLUrl")); fromWSDLUrlButton.getAccessibleContext().setAccessibleDescription(fromWSDLUrlButton.getText()); 460 fromWSDLUrlButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromWSDLUrl_mnem").charAt(0)); 461 462 fromExistingCodeButton = new JCheckBox (NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromExistingCode")); fromExistingCodeButton.getAccessibleContext().setAccessibleDescription(fromExistingCodeButton.getText()); 464 fromExistingCodeButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_FromExistingCode_mnem").charAt(0)); 465 466 wsdlFileTextField = new JTextField (); 467 wsdlFileTextField.getDocument().addDocumentListener(this); 468 wsdlFileTextField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WebServiceWizardPanel.class, "A11Y_WSDL_TF")); 469 470 browseButton = new JButton (NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_Browse")); browseButton.getAccessibleContext().setAccessibleDescription(browseButton.getText()); 472 browseButton.setMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_Browse_mnem").charAt(0)); 473 474 urlLabel = new JLabel (NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_UrlLabel")); urlLabel.setDisplayedMnemonic(NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_UrlLabel_mnem").charAt(0)); 476 477 urlTextField = new JTextField (); 478 urlLabel.setLabelFor(urlTextField); 479 urlTextField.getDocument().addDocumentListener(this); 480 urlTextField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WebServiceWizardPanel.class, "A11Y_WSDL_URL_TF")); 481 482 setLayout(new GridBagLayout ()); 483 setBorder(new TitledBorder (NbBundle.getMessage(WebServiceWizardPanel.class, "LBL_WebService_Type"))); 485 typeButtons.add(fromScratchButton); 486 typeButtons.add(fromWSDLButton); 487 typeButtons.add(fromWSDLUrlButton); 488 fromScratchButton.setSelected(true); 489 browseButton.setEnabled(false); 490 urlTextField.setEnabled(false); 491 wsdlFileTextField.setEnabled(false); 492 493 wsdlFilePanel = new JPanel (); 494 wsdlFilePanel.setLayout(new GridBagLayout ()); 495 gridBagConstraints = new GridBagConstraints (); 496 gridBagConstraints.insets = new Insets (0, 0, 0, 0); 497 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 498 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 499 gridBagConstraints.weightx = 4.0; 500 gridBagConstraints.weighty = 1.0; 501 gridBagConstraints.gridx = 0; 502 gridBagConstraints.gridy = 0; 503 wsdlFilePanel.add(wsdlFileTextField, gridBagConstraints); 504 505 gridBagConstraints.gridx = 1; 506 gridBagConstraints.weightx = 1.0; 507 gridBagConstraints.insets = new Insets (0, 10, 0, 24); 508 wsdlFilePanel.add(browseButton, gridBagConstraints); 509 510 urlPanel = new JPanel (); 511 urlPanel.setLayout(new GridBagLayout ()); 512 gridBagConstraints = new GridBagConstraints (); 513 gridBagConstraints.insets = new Insets (0, 0, 0, 0); 514 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 515 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 516 gridBagConstraints.weightx = 0.0; 517 gridBagConstraints.weighty = 1.0; 518 gridBagConstraints.gridx = 0; 519 gridBagConstraints.gridy = 0; 520 urlPanel.add(urlLabel, gridBagConstraints); 521 522 gridBagConstraints.weightx = 1.0; 523 gridBagConstraints.gridx = 1; 524 urlPanel.add(urlTextField, gridBagConstraints); 525 526 gridBagConstraints = new GridBagConstraints (); 527 gridBagConstraints.insets = new Insets (0, 0, 0, 0); 528 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 529 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 530 gridBagConstraints.weightx = 0.0; 531 gridBagConstraints.weighty = 1.0; 532 gridBagConstraints.gridx = 0; 533 gridBagConstraints.gridy = 0; 534 add(fromScratchButton, gridBagConstraints); 535 gridBagConstraints.gridx = 1; 536 gridBagConstraints.weightx = 2.0; 537 add(fromExistingCodeButton, gridBagConstraints); 538 gridBagConstraints.gridx = 0; 539 gridBagConstraints.gridy = 1; 540 gridBagConstraints.weightx = 0.0; 541 add(fromWSDLButton, gridBagConstraints); 542 gridBagConstraints.gridx = 1; 543 gridBagConstraints.insets = new Insets (0, 0, 0, 24); 544 add(wsdlFilePanel, gridBagConstraints); 545 gridBagConstraints.gridx = 0; 546 gridBagConstraints.gridy = 2; 547 add(fromWSDLUrlButton, gridBagConstraints); 548 gridBagConstraints.gridx = 1; 549 gridBagConstraints.insets = new Insets (0, 0, 0, 50); 550 add(urlPanel, gridBagConstraints); 551 552 } 553 554 public void addNotify() { 555 super.addNotify(); 556 557 nameField = null; 559 java.awt.Container holderPanel = getParent(); 560 if(holderPanel != null) { 561 java.awt.Container guiPanel = holderPanel.getParent(); 562 if(guiPanel != null) { 563 nameField = getFirstTextField(guiPanel); 564 } 565 } 566 567 } 570 571 private JTextField getFirstTextField(java.awt.Container top) { 572 JTextField result = null; 575 java.awt.Component [] components = top.getComponents(); 576 for(int i = 0; i < components.length && result == null; i++) { 577 if(components[i] instanceof JTextField ) { 578 result = (JTextField ) components[i]; 579 } else if(components[i] instanceof java.awt.Container ) { 580 result = getFirstTextField((java.awt.Container ) components[i]); 581 } 582 } 583 return result; 584 } 585 586 public JRadioButton getFromWSDLButton() { 587 return fromWSDLButton; 588 } 589 590 public JRadioButton getFromWSDLUrlButton() { 591 return fromWSDLUrlButton; 592 } 593 594 public boolean isFromScratch(){ 595 return fromScratchButton.isSelected() && !fromExistingCodeButton.isSelected(); 596 } 597 598 public boolean isFromWSDL(){ 599 return fromWSDLButton.isSelected(); 600 } 601 602 public boolean isFromWSDLUrl() { 603 return fromWSDLUrlButton.isSelected(); 604 } 605 606 public boolean isFromExistingCode(){ 607 return fromScratchButton.isSelected() && fromExistingCodeButton.isSelected(); 608 } 609 610 611 public WebServiceWizardHelper getWizardHelper() { 612 return helper; 613 } 614 615 private void addListeners() { 616 final WebServiceWizard wiz = helper.getWizard(); 617 fromScratchButton.addActionListener(new ActionListener () { 618 public void actionPerformed(ActionEvent evt) { 619 if(!fromExistingCodeButton.isEnabled()) { 620 fromExistingCodeButton.setEnabled(true); 621 } 622 if(browseButton.isEnabled()){ 623 browseButton.setEnabled(false); 624 } 625 if(wsdlFileTextField.isEnabled()){ 626 wsdlFileTextField.setEnabled(false); 627 } 628 if(urlTextField.isEnabled()){ 629 urlTextField.setEnabled(false); 630 } 631 if(!fromExistingCodeButton.isSelected()) { 632 wiz.setPanelsAndSteps( 633 WebServiceWizard.PATH_CREATE_FROM_SCRATCH); 634 } 635 else { 636 wiz.setPanelsAndSteps( 637 WebServiceWizard.PATH_CREATE_FROM_EXISTING_CODE); 638 } 639 640 fireStateChanged(); 641 } 642 }); 643 fromExistingCodeButton.addActionListener(new ActionListener () { 644 public void actionPerformed(ActionEvent evt) { 645 if(fromExistingCodeButton.isSelected()) { 646 wiz.setPanelsAndSteps( 647 WebServiceWizard.PATH_CREATE_FROM_EXISTING_CODE); 648 } 649 else { 650 wiz.setPanelsAndSteps( 651 WebServiceWizard.PATH_CREATE_FROM_SCRATCH); 652 } 653 fireStateChanged(); 654 } 655 }); 656 fromWSDLButton.addActionListener(new ActionListener () { 657 public void actionPerformed(ActionEvent evt) { 658 if(!wsdlFileTextField.isEnabled()){ 659 wsdlFileTextField.setEnabled(true); 660 } 661 if(!browseButton.isEnabled()){ 662 browseButton.setEnabled(true); 663 } 664 if(urlTextField.isEnabled()){ 665 urlTextField.setEnabled(false); 666 } 667 ((WebServiceWizard)(helper.getWizard())).setPanelsAndSteps( 668 WebServiceWizard.PATH_CREATE_FROM_WSDL_FILE); 669 if(fromExistingCodeButton.isSelected()) { 670 fromExistingCodeButton.setSelected(false); 671 } 672 fromExistingCodeButton.setEnabled(false); 673 fireStateChanged(); 674 } 675 }); 676 fromWSDLUrlButton.addActionListener(new ActionListener () { 677 public void actionPerformed(ActionEvent evt) { 678 ((WebServiceWizard)(helper.getWizard())).setPanelsAndSteps( 679 WebServiceWizard.PATH_CREATE_FROM_WSDL_URL); 680 if(!urlTextField.isEnabled()){ 681 urlTextField.setEnabled(true); 682 } 683 if(fromExistingCodeButton.isSelected()) { 684 fromExistingCodeButton.setSelected(false); 685 } 686 fromExistingCodeButton.setEnabled(false); 687 if(browseButton.isEnabled()){ 688 browseButton.setEnabled(false); 689 } 690 if(wsdlFileTextField.isEnabled()){ 691 wsdlFileTextField.setEnabled(false); 692 } 693 fireStateChanged(); 694 } 695 }); 696 browseButton.addActionListener(new ActionListener () { 697 public void actionPerformed(ActionEvent evt) { 698 JFileChooser chooser = new JFileChooser (previousDirectory); 699 chooser.setMultiSelectionEnabled(false); 700 chooser.setAcceptAllFileFilterUsed(false); 701 chooser.addChoosableFileFilter(WSDL_FILE_FILTER); 702 chooser.setFileFilter(WSDL_FILE_FILTER); 703 704 if(chooser.showOpenDialog(WebServiceWizardPanel.this) == JFileChooser.APPROVE_OPTION) { 705 File wsdlFile = chooser.getSelectedFile(); 706 wsdlFileTextField.setText(wsdlFile.getAbsolutePath()); 707 previousDirectory = wsdlFile.getPath(); 708 } 709 } 710 }); 711 712 } 713 714 public void changedUpdate(DocumentEvent e) { 715 fireStateChanged(); 716 } 717 718 public void insertUpdate(DocumentEvent e) { 719 fireStateChanged(); 720 } 721 722 public void removeUpdate(DocumentEvent e) { 723 fireStateChanged(); 724 } 725 726 727 public String getWSDLFilePath() { 728 return wsdlFileTextField.getText(); 729 } 730 731 public String getWSDLUrl() { 732 return urlTextField.getText(); 733 } 734 735 736 void readSettings(WizardDescriptor wizDescriptor) { 737 javax.swing.SwingUtilities.invokeLater(new Runnable () { 740 public void run() { 741 fireStateChanged(); 742 } 743 }); 744 } 745 746 void storeSettings(WizardDescriptor wizDescriptor) { 747 wizDescriptor.putProperty(WebServiceWizard.WSDL_FILE_PATH, wsdlFileTextField.getText().trim()); 748 wizDescriptor.putProperty(WebServiceWizard.WSDL_FILE_URL, urlTextField.getText().trim()); 749 } 750 751 752 private void fireStateChanged() { 755 if (listener != null) { 756 ChangeEvent evt = new ChangeEvent (this); 757 listener.stateChanged(evt); 758 } 759 } 760 761 private ButtonGroup typeButtons; 762 private JRadioButton fromScratchButton; 763 private JRadioButton fromWSDLButton; 764 private JRadioButton fromWSDLUrlButton; 765 private JCheckBox fromExistingCodeButton; 766 private JPanel wsdlFilePanel; 767 private JTextField wsdlFileTextField; 768 private JButton browseButton; 769 private JPanel urlPanel; 770 private JLabel urlLabel; 771 private JTextField urlTextField; 772 } 773 private static class WsdlFileFilter extends FileFilter { 774 public boolean accept(File f) { 775 boolean result; 776 if(f.isDirectory() || "wsdl".equalsIgnoreCase(FileUtil.getExtension(f.getName()))) { result = true; 778 } else { 779 result = false; 780 } 781 return result; 782 } 783 784 public String getDescription() { 785 return NbBundle.getMessage(WebServiceWizardDescriptor.class, "LBL_WsdlFilterDescription"); } 787 } 788 } 789 | Popular Tags |