1 19 20 package org.netbeans.modules.java.j2seplatform.wizard; 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Collections ; 29 import java.util.Enumeration ; 30 import java.util.HashMap ; 31 import java.util.HashSet ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.Map ; 35 import java.util.Properties ; 36 import java.util.Set ; 37 import javax.swing.event.ChangeListener ; 38 import org.netbeans.api.java.platform.JavaPlatform; 39 import org.netbeans.modules.java.j2seplatform.platformdefinition.J2SEPlatformImpl; 40 import org.netbeans.modules.java.j2seplatform.platformdefinition.PlatformConvertor; 41 import org.netbeans.modules.java.j2seplatform.platformdefinition.Util; 42 import org.openide.ErrorManager; 43 import org.openide.WizardDescriptor; 44 import org.openide.filesystems.FileObject; 45 import org.openide.filesystems.FileUtil; 46 import org.openide.filesystems.Repository; 47 import org.openide.loaders.DataFolder; 48 import org.openide.loaders.DataObject; 49 import org.openide.modules.InstalledFileLocator; 50 import org.openide.util.NbBundle; 51 52 59 public class J2SEWizardIterator implements WizardDescriptor.InstantiatingIterator { 60 61 private static final String [] SOLARIS_64_FOLDERS = {"sparcv9","amd64"}; 63 DataFolder installFolder; 64 DetectPanel.WizardPanel detectPanel; 65 Collection listeners; 66 NewJ2SEPlatform platform; 67 NewJ2SEPlatform secondaryPlatform; 68 WizardDescriptor wizard; 69 int currentIndex; 70 71 public J2SEWizardIterator(FileObject installFolder) throws IOException { 72 this.installFolder = DataFolder.findFolder(installFolder); 73 this.platform = NewJ2SEPlatform.create (installFolder); 74 String archFolder = null; 75 for (int i = 0; i< SOLARIS_64_FOLDERS.length; i++) { 76 if (Util.findTool("java",Collections.singleton(installFolder),SOLARIS_64_FOLDERS[i]) != null) { 77 archFolder = SOLARIS_64_FOLDERS[i]; 78 break; 79 } 80 } 81 if (archFolder != null) { 82 this.secondaryPlatform = NewJ2SEPlatform.create (installFolder); 83 this.secondaryPlatform.setArchFolder(archFolder); 84 } 85 } 86 87 FileObject getInstallFolder() { 88 return installFolder.getPrimaryFile(); 89 } 90 91 public void addChangeListener(ChangeListener l) { 92 listeners.add(l); 93 } 94 95 public WizardDescriptor.Panel current() { 96 switch (this.currentIndex) { 97 case 0: 98 return this.detectPanel; 99 default: 100 throw new IllegalStateException (); 101 } 102 } 103 104 public boolean hasNext() { 105 return false; 106 } 107 108 public boolean hasPrevious() { 109 return false; 110 } 111 112 public void initialize(WizardDescriptor wiz) { 113 this.wizard = wiz; 114 this. detectPanel = new DetectPanel.WizardPanel(this); 115 this.currentIndex = 0; 116 } 117 118 123 public java.util.Set instantiate() throws IOException { 124 this.detectPanel.storeSettings (this.wizard); 126 Set result = new HashSet (); 127 for (Iterator it = getPlatforms().iterator(); it.hasNext();) { 128 NewJ2SEPlatform platform = (NewJ2SEPlatform) it.next(); 129 if (platform.isValid()) { 130 final String systemName = platform.getAntName(); 131 FileObject platformsFolder = Repository.getDefault().getDefaultFileSystem().findResource( 132 "Services/Platforms/org-netbeans-api-java-Platform"); if (platformsFolder.getFileObject(systemName,"xml")!=null) { String msg = NbBundle.getMessage(J2SEWizardIterator.class,"ERROR_InvalidName"); 135 throw (IllegalStateException )ErrorManager.getDefault().annotate( 136 new IllegalStateException (msg), ErrorManager.USER, null, msg,null, null); 137 } 138 DataObject dobj = PlatformConvertor.create(platform, DataFolder.findFolder(platformsFolder),systemName); 139 result.add((JavaPlatform) dobj.getNodeDelegate().getLookup().lookup(JavaPlatform.class)); 140 } 141 } 142 return Collections.unmodifiableSet(result); 143 144 } 145 146 public String name() { 147 return NbBundle.getMessage(J2SEWizardIterator.class, "TITLE_PlatformName"); 148 } 149 150 public void nextPanel() { 151 this.currentIndex++; 152 } 153 154 public void previousPanel() { 155 this.currentIndex--; 156 } 157 158 public void removeChangeListener(ChangeListener l) { 159 listeners.add(l); 160 } 161 162 public void uninitialize(WizardDescriptor wiz) { 163 this.wizard = null; 164 this.detectPanel = null; 165 } 166 167 public NewJ2SEPlatform getPlatform() { 168 return this.platform; 169 } 170 171 public NewJ2SEPlatform getSecondaryPlatform () { 172 return this.secondaryPlatform; 173 } 174 175 private List getPlatforms () { 176 List result = new ArrayList (); 177 result.add(this.platform); 178 if (this.secondaryPlatform != null) { 179 result.add(this.secondaryPlatform); 180 } 181 return result; 182 } 183 } 184 | Popular Tags |