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