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 NewWebServiceWizardIterator implements TemplateWizard.Iterator { 51 52 private Project project; 53 54 55 public NewWebServiceWizardIterator() { 56 } 57 58 public static NewWebServiceWizardIterator create() { 59 return new NewWebServiceWizardIterator(); 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.createService(); 70 } 71 72 return Collections.singleton(dTemplate); 73 } 74 75 private transient int index; 76 private transient WizardDescriptor.Panel[] panels; 77 private transient TemplateWizard wiz; 78 private transient WizardDescriptor.Panel bottomPanel; 79 80 83 public void initialize(TemplateWizard wiz) { 84 this.wiz = wiz; 85 index = 0; 86 87 project = Templates.getProject(wiz); 88 89 SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project); 90 bottomPanel = new WebServiceType(project, wiz); 91 WizardDescriptor.Panel firstPanel; if (sourceGroups.length == 0) 95 firstPanel = new FinishableProxyWizardPanel(Templates.createSimpleTargetChooser(project, sourceGroups, bottomPanel)); 96 else 97 firstPanel = new FinishableProxyWizardPanel(JavaTemplates.createPackageChooser(project, sourceGroups, bottomPanel, true)); 98 99 JComponent comp = (JComponent ) firstPanel.getComponent(); 100 Util.changeLabelInComponent(comp, NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_Webservice_Name") ); 101 Util.hideLabelAndLabelFor(comp, NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label")); 102 103 panels = new WizardDescriptor.Panel[] { 104 firstPanel, 105 }; 108 109 Object prop = this.wiz.getProperty("WizardPanel_contentData"); String [] beforeSteps = null; 112 if (prop != null && prop instanceof String []) { 113 beforeSteps = (String []) prop; 114 } 115 String [] steps = createSteps(beforeSteps, panels); 116 117 for (int i = 0; i < panels.length; i++) { 119 Component c = panels[i].getComponent(); 120 if (c instanceof JComponent ) { JComponent jc = (JComponent ) c; 122 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); } 127 } 128 } 129 130 public void uninitialize(TemplateWizard wiz) { 131 if (this.wiz != null) { 132 this.wiz.putProperty(WizardProperties.WEB_SERVICE_TYPE, null); 133 } 134 panels = null; 137 } 138 139 private String [] createSteps(String [] before, WizardDescriptor.Panel[] panels) { 140 int diff = 0; 141 if (before == null) { 142 before = new String [0]; 143 } else if (before.length > 0) { 144 diff = ("...".equals (before[before.length - 1])) ? 1 : 0; } 146 String [] res = new String [ (before.length - diff) + panels.length]; 147 for (int i = 0; i < res.length; i++) { 148 if (i < (before.length - diff)) { 149 res[i] = before[i]; 150 } else { 151 res[i] = panels[i - before.length + diff].getComponent ().getName (); 152 } 153 } 154 return res; 155 } 156 157 public String name() { 158 return MessageFormat.format(NbBundle.getMessage(NewWebServiceWizardIterator.class, "LBL_WizardStepsCount"), (new Integer (index + 1)).toString(), (new Integer (panels.length)).toString()); } 160 161 public boolean hasNext() { 162 return index < panels.length - 1; 167 } 168 169 public boolean hasPrevious() { 170 return index > 0; 171 } 172 173 public void nextPanel() { 174 if (!hasNext()) throw new NoSuchElementException (); 175 index++; 176 } 177 178 public void previousPanel() { 179 if (!hasPrevious()) throw new NoSuchElementException (); 180 index--; 181 } 182 183 public WizardDescriptor.Panel current() { 184 return panels[index]; 185 } 186 187 public final void addChangeListener(ChangeListener l) {} 189 public final void removeChangeListener(ChangeListener l) {} 190 191 198 } 199 | Popular Tags |