1 19 20 package org.netbeans.modules.j2ee.ejbcore.ejb.wizard.mdb; 21 22 import java.io.IOException ; 23 import org.netbeans.modules.j2ee.ejbcore.api.codegeneration.MessageGenerator; 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.modules.j2ee.common.DelegatingWizardDescriptorPanel; 33 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates; 34 import org.netbeans.spi.project.ui.templates.support.Templates; 35 import org.openide.filesystems.FileObject; 36 import org.netbeans.modules.j2ee.common.Util; 37 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 38 import org.netbeans.modules.j2ee.ejbcore.Utils; 39 import org.openide.WizardDescriptor; 40 import org.openide.util.NbBundle; 41 42 47 public final class MessageEJBWizard implements WizardDescriptor.InstantiatingIterator{ 48 49 private WizardDescriptor.Panel[] panels; 50 private int index = 0; 51 private MessageEJBWizardPanel ejbPanel; 52 private WizardDescriptor wiz; 53 54 private static final String [] SESSION_STEPS = new String [] { 55 NbBundle.getMessage(MessageEJBWizard.class, "LBL_SpecifyEJBInfo") 56 }; 57 58 public String name () { 59 return NbBundle.getMessage (MessageEJBWizard.class, "LBL_MessageEJBWizardTitle"); 60 } 61 62 public void uninitialize(WizardDescriptor wiz) { 63 } 64 65 public void initialize(WizardDescriptor wizardDescriptor) { 66 wiz = wizardDescriptor; 67 Project project = Templates.getProject(wiz); 68 SourceGroup[] sourceGroups = Util.getJavaSourceGroups(project); 69 ejbPanel = new MessageEJBWizardPanel(wiz); 70 WizardDescriptor.Panel wizardPanel = new ValidatingPanel(JavaTemplates.createPackageChooser(project,sourceGroups, ejbPanel, true)); 71 JComponent jComponent = (JComponent ) wizardPanel.getComponent (); 72 Util.changeLabelInComponent(jComponent, NbBundle.getMessage(MessageEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_ClassName_Label"), NbBundle.getMessage(MessageEJBWizard.class, "LBL_EJB_Name") ); 73 Util.hideLabelAndLabelFor(jComponent, NbBundle.getMessage(MessageEJBWizard.class, "LBL_JavaTargetChooserPanelGUI_CreatedFile_Label")); 74 panels = new WizardDescriptor.Panel[] {wizardPanel}; 75 Utils.mergeSteps(wiz, panels, SESSION_STEPS); 76 } 77 78 public Set instantiate() throws IOException { 79 FileObject pkg = Templates.getTargetFolder(wiz); 80 EjbJar ejbModule = EjbJar.getEjbJar(pkg); 81 82 boolean isSimplified = ejbModule.getJ2eePlatformVersion().equals(J2eeModule.JAVA_EE_5); 84 MessageGenerator generator = MessageGenerator.create( 85 Templates.getTargetName(wiz), 86 pkg, 87 ejbPanel.isQueue(), 88 isSimplified, 89 !isSimplified ); 91 FileObject result = generator.generate(); 92 return result == null ? Collections.EMPTY_SET : Collections.singleton(result); 93 } 94 95 public void addChangeListener(ChangeListener listener) { 96 } 97 98 public void removeChangeListener(ChangeListener listener) { 99 } 100 101 public boolean hasPrevious () { 102 return index > 0; 103 } 104 105 public boolean hasNext () { 106 return index < panels.length - 1; 107 } 108 109 public void nextPanel () { 110 if (! hasNext ()) { 111 throw new NoSuchElementException (); 112 } 113 index++; 114 } 115 public void previousPanel () { 116 if (! hasPrevious ()) { 117 throw new NoSuchElementException (); 118 } 119 index--; 120 } 121 public WizardDescriptor.Panel current () { 122 return panels[index]; 123 } 124 125 129 private static final class ValidatingPanel extends DelegatingWizardDescriptorPanel { 130 131 public ValidatingPanel(WizardDescriptor.Panel delegate) { 132 super(delegate); 133 } 134 135 public boolean isValid() { 136 if (!org.netbeans.modules.j2ee.common.Util.isValidServerInstance(getProject())) { 137 getWizardDescriptor().putProperty("WizardPanel_errorMessage", 138 NbBundle.getMessage(MessageEJBWizard.class, "ERR_MissingServer")); return false; 140 } 141 return super.isValid(); 142 } 143 } 144 } 145 | Popular Tags |