1 19 package org.netbeans.modules.apisupport.feedreader; 20 21 import java.awt.Component ; 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.io.InputStream ; 25 import java.text.MessageFormat ; 26 import java.util.Enumeration ; 27 import java.util.LinkedHashSet ; 28 import java.util.NoSuchElementException ; 29 import java.util.Set ; 30 import javax.swing.JComponent ; 31 import javax.swing.event.ChangeListener ; 32 import org.netbeans.api.project.ProjectManager; 33 import org.netbeans.spi.project.ui.support.ProjectChooser; 34 import org.netbeans.spi.project.ui.templates.support.Templates; 35 import org.openide.WizardDescriptor; 36 import org.openide.filesystems.FileObject; 37 import org.openide.filesystems.FileUtil; 38 import org.openide.util.NbBundle; 39 40 public class FeedReaderWizardIterator implements WizardDescriptor.InstantiatingIterator { 41 42 private static final long serialVersionUID = 1L; 43 44 private transient int index; 45 private transient WizardDescriptor.Panel[] panels; 46 private transient WizardDescriptor wiz; 47 48 public static FeedReaderWizardIterator createIterator() { 49 return new FeedReaderWizardIterator(); 50 } 51 52 private WizardDescriptor.Panel[] createPanels() { 53 return new WizardDescriptor.Panel[] { 54 new FeedReaderWizardPanel(), 55 }; 56 } 57 58 private String [] createSteps() { 59 return new String [] { 60 NbBundle.getMessage(FeedReaderWizardPanel.class, "LBL_Step1"), 61 }; 62 } 63 64 public Set instantiate() throws IOException { 65 Set resultSet = new LinkedHashSet (); 66 File dirF = FileUtil.normalizeFile((File ) wiz.getProperty("projdir")); 67 dirF.mkdirs(); 68 69 FileObject template = Templates.getTemplate(wiz); 70 FileObject dir = FileUtil.toFileObject(dirF); 71 InputStream is = template.getInputStream(); 72 try { 73 FileUtil.extractJar(dir, is); 74 } finally { 75 is.close(); 76 } 77 79 resultSet.add(dir); 81 Enumeration e = dir.getFolders(true); 83 while (e.hasMoreElements()) { 84 FileObject subfolder = (FileObject) e.nextElement(); 85 if (ProjectManager.getDefault().isProject(subfolder)) { 86 resultSet.add(subfolder); 87 } 88 } 89 90 File parent = dirF.getParentFile(); 91 if (parent != null && parent.exists()) { 92 ProjectChooser.setProjectsFolder(parent); 93 } 94 95 return resultSet; 96 } 97 98 public void initialize(WizardDescriptor wiz) { 99 this.wiz = wiz; 100 index = 0; 101 panels = createPanels(); 102 String [] steps = createSteps(); 104 for (int i = 0; i < panels.length; i++) { 105 Component c = panels[i].getComponent(); 106 if (steps[i] == null) { 107 steps[i] = c.getName(); 111 } 112 if (c instanceof JComponent ) { JComponent jc = (JComponent )c; 114 jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer (i)); jc.putClientProperty("WizardPanel_contentData", steps); } 119 } 120 } 121 122 public void uninitialize(WizardDescriptor wiz) { 123 this.wiz.putProperty("projdir", null); this.wiz.putProperty("name", null); this.wiz = null; 126 panels = null; 127 } 128 129 public String name() { 130 return MessageFormat.format("{0} of {1}", 131 new Object [] {new Integer (index + 1), new Integer (panels.length) }); 132 } 133 134 public boolean hasNext() { 135 return index < panels.length - 1; 136 } 137 138 public boolean hasPrevious() { 139 return index > 0; 140 } 141 142 public void nextPanel() { 143 if (!hasNext()) { 144 throw new NoSuchElementException (); 145 } 146 index++; 147 } 148 149 public void previousPanel() { 150 if (!hasPrevious()) { 151 throw new NoSuchElementException (); 152 } 153 index--; 154 } 155 156 public WizardDescriptor.Panel current() { 157 return panels[index]; 158 } 159 160 public final void addChangeListener(ChangeListener l) {} 162 public final void removeChangeListener(ChangeListener l) {} 163 164 } 165 | Popular Tags |