1 19 20 package org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session; 21 22 import java.io.IOException ; 23 import org.netbeans.modules.j2ee.ejbcore.api.codegeneration.SessionGenerator; 24 import java.util.Collections ; 25 import java.util.NoSuchElementException ; 26 import java.util.Set ; 27 import javax.swing.JComponent ; 28 import javax.swing.event.ChangeListener ; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.api.project.SourceGroup; 31 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar; 32 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates; 33 import org.netbeans.spi.project.ui.templates.support.Templates; 34 import org.openide.filesystems.FileObject; 35 import org.netbeans.modules.j2ee.common.Util; 36 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 37 import org.netbeans.modules.j2ee.ejbcore.Utils; 38 import org.openide.ErrorManager; 39 import org.openide.WizardDescriptor; 40 import org.openide.util.NbBundle; 41 42 47 public final class SessionEJBWizard implements WizardDescriptor.InstantiatingIterator{ 48 49 private WizardDescriptor.Panel[] panels; 50 private int index = 0; 51 private SessionEJBWizardDescriptor ejbPanel; 52 private WizardDescriptor wiz; 53 54 public static SessionEJBWizard create () { 55 return new SessionEJBWizard (); 56 } 57 58 public String name () { 59 return NbBundle.getMessage (SessionEJBWizard.class, 60 "LBL_SessionEJBWizardTitle"); 61 } 62 63 public void uninitialize(WizardDescriptor wiz) { 64 } 65 66 public void initialize(WizardDescriptor wizardDescriptor) { 67 wiz = wizardDescriptor; 68 Project project = Templates.getProject(wiz); 69 SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project); 70 ejbPanel = new SessionEJBWizardDescriptor(); 71 WizardDescriptor.Panel wizardDescriptorPanel = JavaTemplates.createPackageChooser(project,sourceGroups, ejbPanel, true); 72 73 JComponent jComponent = (JComponent ) wizardDescriptorPanel.getComponent(); 74 Util.changeLabelInComponent(jComponent, 75 NbBundle.getMessage(SessionEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), 76 NbBundle.getMessage(SessionEJBWizard.class, "LBL_EJB_Name")); 77 Util.hideLabelAndLabelFor(jComponent, 78 NbBundle.getMessage(SessionEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label")); 79 panels = new WizardDescriptor.Panel[] {wizardDescriptorPanel}; 80 Utils.mergeSteps(wiz, panels, null); 81 } 82 83 public Set instantiate () { 84 FileObject pkg = Templates.getTargetFolder(wiz); 85 EjbJar ejbModule = EjbJar.getEjbJar(pkg); 86 boolean isSimplified = ejbModule.getJ2eePlatformVersion().equals(J2eeModule.JAVA_EE_5); 88 SessionGenerator sessionGenerator = SessionGenerator.create( 89 Templates.getTargetName(wiz), 90 pkg, 91 ejbPanel.hasRemote(), 92 ejbPanel.hasLocal(), 93 ejbPanel.isStateful(), 94 isSimplified, 95 true, !isSimplified ); 98 FileObject result = null; 99 try { 100 result = sessionGenerator.generate(); 101 } catch (IOException ex) { 102 ErrorManager.getDefault().notify(ex); 103 } 104 return result == null ? Collections.<FileObject>emptySet() : Collections.singleton(result); 105 } 106 107 public void addChangeListener(ChangeListener listener) { 108 } 109 110 public void removeChangeListener(ChangeListener listener) { 111 } 112 113 public boolean hasPrevious () { 114 return index > 0; 115 } 116 117 public boolean hasNext () { 118 return index < panels.length - 1; 119 } 120 121 public void nextPanel () { 122 if (! hasNext ()) { 123 throw new NoSuchElementException (); 124 } 125 index++; 126 } 127 public void previousPanel () { 128 if (! hasPrevious ()) { 129 throw new NoSuchElementException (); 130 } 131 index--; 132 } 133 public WizardDescriptor.Panel current () { 134 return panels[index]; 135 } 136 137 } 138 139 | Popular Tags |