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 NewWebServiceWizardIterator implements TemplateWizard.Iterator { 49 50 private Project project; 51 52 53 public NewWebServiceWizardIterator() { 54 } 55 56 public static NewWebServiceWizardIterator create() { 57 return new NewWebServiceWizardIterator(); 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).create(); 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 77 public void initialize(TemplateWizard wiz) { 78 this.wiz = wiz; 79 index = 0; 80 81 project = Templates.getProject(wiz); 82 83 SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project); 84 bottomPanel = new WebServiceType(project, wiz); 85 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(Util.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_Webservice_Name") ); 95 Util.hideLabelAndLabelFor(comp, NbBundle.getMessage(Util.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label")); 96 97 panels = new WizardDescriptor.Panel[] { 98 firstPanel, 99 }; 102 103 Object prop = this.wiz.getProperty("WizardPanel_contentData"); String [] beforeSteps = null; 106 if (prop != null && prop instanceof String []) { 107 beforeSteps = (String []) prop; 108 } 109 String [] steps = createSteps(beforeSteps, panels); 110 111 for (int i = 0; i < panels.length; i++) { 113 Component c = panels[i].getComponent(); 114 if (c instanceof JComponent ) { JComponent jc = (JComponent ) c; 116 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); } 121 } 122 } 123 124 public void uninitialize(TemplateWizard wiz) { 125 if (this.wiz != null) { 126 this.wiz.putProperty(WizardProperties.WEB_SERVICE_TYPE, null); 127 } 128 panels = null; 131 } 132 133 private String [] createSteps(String [] before, WizardDescriptor.Panel[] panels) { 134 int diff = 0; 135 if (before == null) { 136 before = new String [0]; 137 } else if (before.length > 0) { 138 diff = ("...".equals (before[before.length - 1])) ? 1 : 0; } 140 String [] res = new String [ (before.length - diff) + panels.length]; 141 for (int i = 0; i < res.length; i++) { 142 if (i < (before.length - diff)) { 143 res[i] = before[i]; 144 } else { 145 res[i] = panels[i - before.length + diff].getComponent ().getName (); 146 } 147 } 148 return res; 149 } 150 151 public String name() { 152 return MessageFormat.format(NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_WizardStepsCount"), new String [] {(new Integer (index + 1)).toString(), (new Integer (panels.length)).toString()}); } 154 155 public boolean hasNext() { 156 return index < panels.length - 1; 161 } 162 163 public boolean hasPrevious() { 164 return index > 0; 165 } 166 167 public void nextPanel() { 168 if (!hasNext()) throw new NoSuchElementException (); 169 index++; 170 } 171 172 public void previousPanel() { 173 if (!hasPrevious()) throw new NoSuchElementException (); 174 index--; 175 } 176 177 public WizardDescriptor.Panel current() { 178 return panels[index]; 179 } 180 181 public final void addChangeListener(ChangeListener l) {} 183 public final void removeChangeListener(ChangeListener l) {} 184 185 192 } 193 | Popular Tags |