1 19 20 package org.netbeans.bluej.packagewizard; 21 22 import java.io.IOException ; 23 import java.lang.reflect.InvocationTargetException ; 24 import java.lang.reflect.Method ; 25 import java.util.Set ; 26 import javax.swing.event.ChangeListener ; 27 import org.netbeans.api.project.FileOwnerQuery; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.bluej.BluejProject; 30 import org.netbeans.spi.project.ui.templates.support.Templates; 31 import org.openide.WizardDescriptor; 32 import org.openide.filesystems.FileObject; 33 import org.openide.filesystems.FileSystem; 34 import org.openide.util.Lookup; 35 36 41 public class PackageWizardIterator implements WizardDescriptor.InstantiatingIterator { 42 43 private WizardDescriptor.InstantiatingIterator delegate; 44 45 private WizardDescriptor wiz; 46 47 private Set set; 48 49 50 public static PackageWizardIterator createWizard() { 51 return new PackageWizardIterator(); 52 } 53 54 55 private PackageWizardIterator() { 56 ClassLoader ldr = (ClassLoader ) Lookup.getDefault().lookup(ClassLoader .class); 57 Class clazz; 58 Method method; 59 try { 60 clazz = Class.forName("org.netbeans.modules.java.project.NewJavaFileWizardIterator", true, ldr); method = clazz.getMethod("packageWizard", null); delegate = (WizardDescriptor.InstantiatingIterator)method.invoke(null, null); 63 } catch (SecurityException ex) { 64 ex.printStackTrace(); 65 } catch (NoSuchMethodException ex) { 66 ex.printStackTrace(); 67 } catch (ClassNotFoundException ex) { 68 ex.printStackTrace(); 69 } catch (IllegalArgumentException ex) { 70 ex.printStackTrace(); 71 } catch (IllegalAccessException ex) { 72 ex.printStackTrace(); 73 } catch (InvocationTargetException ex) { 74 ex.printStackTrace(); 75 } 76 } 77 78 public Set instantiate() throws IOException { 79 FileObject dir = Templates.getTargetFolder( wiz ); 80 Project project = FileOwnerQuery.getOwner(dir); 81 if (project.getLookup().lookup(BluejProject.class) != null) { 82 FileSystem fs = dir.getFileSystem(); 83 84 fs.runAtomicAction( 85 new FileSystem.AtomicAction() { 86 public void run() throws IOException { 87 set = delegate.instantiate(); 88 FileObject fo = (FileObject)set.iterator().next(); 89 fo.createData("bluej.pkg"); } 91 } 92 ); 93 94 } else { 95 set = delegate.instantiate(); 96 97 } 98 return set; 99 } 100 101 public void initialize(WizardDescriptor wizard) { 102 wiz = wizard; 103 delegate.initialize(wizard); 104 } 105 106 public void uninitialize(WizardDescriptor wizard) { 107 delegate.uninitialize(wizard); 108 } 109 110 public WizardDescriptor.Panel current() { 111 return delegate.current(); 112 } 113 114 public String name() { 115 return delegate.name(); 116 } 117 118 public boolean hasNext() { 119 return delegate.hasNext(); 120 } 121 122 public boolean hasPrevious() { 123 return delegate.hasPrevious(); 124 } 125 126 public void nextPanel() { 127 delegate.nextPanel(); 128 } 129 130 public void previousPanel() { 131 delegate.previousPanel(); 132 } 133 134 public void addChangeListener(ChangeListener l) { 135 delegate.addChangeListener(l); 136 } 137 138 public void removeChangeListener(ChangeListener l) { 139 delegate.removeChangeListener(l); 140 } 141 142 } 143
| Popular Tags
|