1 19 20 package org.netbeans.modules.websvc.dev.wizard; 21 22 import java.awt.Component ; 23 import java.io.IOException ; 24 import java.text.MessageFormat ; 25 import java.util.Collections ; 26 import java.util.NoSuchElementException ; 27 import java.util.Set ; 28 29 import javax.swing.JComponent ; 30 import javax.swing.event.ChangeListener ; 31 import org.netbeans.api.project.Project; 32 import org.netbeans.api.project.SourceGroup; 33 34 import org.openide.WizardDescriptor; 35 36 import org.netbeans.modules.j2ee.common.Util; 37 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates; 38 import org.netbeans.spi.project.ui.templates.support.Templates; 39 import org.openide.filesystems.FileObject; 40 import org.openide.loaders.DataObject; 41 import org.openide.loaders.TemplateWizard; 42 import org.openide.util.NbBundle; 43 44 48 public class NewWebServiceFromWSDLWizardIterator implements TemplateWizard.Iterator { 49 50 private Project project; 51 52 53 public NewWebServiceFromWSDLWizardIterator() { 54 } 55 56 public static NewWebServiceFromWSDLWizardIterator create() { 57 return new NewWebServiceFromWSDLWizardIterator(); 58 } 59 60 public Set instantiate(TemplateWizard wiz) throws IOException { 61 FileObject template = Templates.getTemplate( wiz ); 62 DataObject dTemplate = DataObject.find( template ); 63 64 new WebServiceCreator(project, wiz).createFromWSDL(); 65 66 return Collections.singleton(dTemplate); 67 } 68 69 private transient int index; 70 private transient WizardDescriptor.Panel[] panels; 71 private transient TemplateWizard wiz; 72 private transient WizardDescriptor.Panel bottomPanel; 73 74 public void initialize(TemplateWizard wiz) { 75 this.wiz = wiz; 76 index = 0; 77 78 project = Templates.getProject(wiz); 79 80 SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project); 81 bottomPanel = new WebServiceFromWSDL(wiz, project); 82 WizardDescriptor.Panel firstPanel; if (sourceGroups.length == 0) 84 firstPanel = new FinishableProxyWizardPanel(Templates.createSimpleTargetChooser(project, sourceGroups, bottomPanel)); 85 else 86 firstPanel = new FinishableProxyWizardPanel(JavaTemplates.createPackageChooser(project, sourceGroups, bottomPanel, true)); 87 88 JComponent comp = (JComponent ) firstPanel.getComponent(); 89 Util.changeLabelInComponent(comp, NbBundle.getMessage(Util.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_Webservice_Name") ); 90 Util.hideLabelAndLabelFor(comp, NbBundle.getMessage(Util.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label")); 91 92 panels = new WizardDescriptor.Panel[] { 93 firstPanel, 94 }; 95 96 Object prop = this.wiz.getProperty("WizardPanel_contentData"); String [] beforeSteps = null; 99 if (prop != null && prop instanceof String []) { 100 beforeSteps = (String []) prop; 101 } 102 String [] steps = createSteps(beforeSteps, panels); 103 104 for (int i = 0; i < panels.length; i++) { 106 Component c = panels[i].getComponent(); 107 if (c instanceof JComponent ) { JComponent jc = (JComponent ) c; 109 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); } 114 } 115 } 116 117 public void uninitialize(TemplateWizard wiz) { 118 if (this.wiz != null) { 119 this.wiz.putProperty(WizardProperties.WEB_SERVICE_TYPE, null); 120 } 121 panels = null; 122 } 123 124 private String [] createSteps(String [] before, WizardDescriptor.Panel[] panels) { 125 int diff = 0; 126 if (before == null) { 127 before = new String [0]; 128 } else if (before.length > 0) { 129 diff = ("...".equals (before[before.length - 1])) ? 1 : 0; } 131 String [] res = new String [ (before.length - diff) + panels.length]; 132 for (int i = 0; i < res.length; i++) { 133 if (i < (before.length - diff)) { 134 res[i] = before[i]; 135 } else { 136 res[i] = panels[i - before.length + diff].getComponent ().getName (); 137 } 138 } 139 return res; 140 } 141 142 public String name() { 143 return MessageFormat.format(NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_WizardStepsCount"), new String [] {(new Integer (index + 1)).toString(), (new Integer (panels.length)).toString()}); } 145 146 public boolean hasNext() { 147 return index < panels.length - 1; 148 } 149 150 public boolean hasPrevious() { 151 return index > 0; 152 } 153 154 public void nextPanel() { 155 if (!hasNext()) throw new NoSuchElementException (); 156 index++; 157 } 158 159 public void previousPanel() { 160 if (!hasPrevious()) throw new NoSuchElementException (); 161 index--; 162 } 163 164 public WizardDescriptor.Panel current() { 165 return panels[index]; 166 } 167 168 public final void addChangeListener(ChangeListener l) {} 170 public final void removeChangeListener(ChangeListener l) {} 171 172 } 173 | Popular Tags |