1 19 20 package org.netbeans.modules.j2ee.ejbcore.patterns; 21 22 import java.io.IOException ; 23 import org.netbeans.api.project.ProjectUtils; 24 import org.netbeans.modules.j2ee.api.ejbjar.EnterpriseReferenceContainer; 25 import java.util.Collections ; 26 import java.util.NoSuchElementException ; 27 import java.util.Set ; 28 import javax.swing.event.ChangeListener ; 29 import org.netbeans.api.java.project.JavaProjectConstants; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.api.project.SourceGroup; 32 import org.netbeans.api.project.Sources; 33 import org.netbeans.modules.j2ee.ejbcore.EjbGenerationUtil; 34 import org.netbeans.modules.j2ee.ejbcore.Utils; 35 import org.netbeans.spi.java.project.support.ui.templates.JavaTemplates; 36 import org.netbeans.spi.project.ui.templates.support.Templates; 37 import org.openide.WizardDescriptor; 38 import org.openide.filesystems.FileObject; 39 import org.openide.loaders.DataFolder; 40 import org.openide.loaders.DataObject; 41 import org.openide.util.NbBundle; 42 43 44 49 public final class ServiceLocatorWizard implements WizardDescriptor.InstantiatingIterator { 50 private WizardDescriptor.Panel[] panels; 51 private int index = 0; 52 private WizardDescriptor wiz; 53 54 private static final String [] STEPS = 55 new String [] { 56 NbBundle.getMessage (ServiceLocatorWizard.class, 57 "LBL_SpecifyName") 58 }; 59 60 public String name () { 61 return NbBundle.getMessage (ServiceLocatorWizard.class, 62 "LBL_MessageServiceLocatorWizardTitle"); 63 } 64 65 public void uninitialize(WizardDescriptor wiz) { 66 } 67 68 public void initialize(WizardDescriptor wizardDescriptor) { 69 wiz = wizardDescriptor; 70 Project project = Templates.getProject(wiz); 71 Sources sources = ProjectUtils.getSources(project); 72 SourceGroup[] sourceGroups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 73 panels = new WizardDescriptor.Panel[] {JavaTemplates.createPackageChooser(project,sourceGroups)}; 74 Utils.mergeSteps(wiz, panels, STEPS); 75 } 76 77 public Set instantiate () throws IOException { 78 FileObject pkg = Templates.getTargetFolder(wiz); 79 String clsName = Templates.getTargetName(wiz); 80 Project project = Templates.getProject(wiz); 81 DataFolder dataFolder = DataFolder.findFolder(pkg); 82 FileObject template = Templates.getTemplate(wiz); 83 DataObject dTemplate = DataObject.find( template ); 84 DataObject dobj = dTemplate.createFromTemplate( dataFolder, clsName); 85 String pkgName = EjbGenerationUtil.getSelectedPackageName(pkg); 86 String fullName = (pkgName.length()>0?pkgName+'.':"")+clsName; 87 EnterpriseReferenceContainer erc = (EnterpriseReferenceContainer) 88 project.getLookup().lookup(EnterpriseReferenceContainer.class); 89 if (erc != null) { 90 erc.setServiceLocatorName(fullName); 91 } 92 FileObject createdFile = dobj.getPrimaryFile(); 93 94 return Collections.singleton(createdFile); 95 } 96 97 public void addChangeListener(ChangeListener listener) { 98 } 99 100 public void removeChangeListener(ChangeListener listener) { 101 } 102 103 public boolean hasPrevious () { 104 return index > 0; 105 } 106 107 public boolean hasNext () { 108 return index < panels.length - 1; 109 } 110 111 public void nextPanel () { 112 if (! hasNext ()) { 113 throw new NoSuchElementException (); 114 } 115 index++; 116 } 117 118 public void previousPanel () { 119 if (! hasPrevious ()) { 120 throw new NoSuchElementException (); 121 } 122 index--; 123 } 124 125 public WizardDescriptor.Panel current () { 126 return panels[index]; 127 } 128 129 } 130 131 | Popular Tags |