1 19 20 package org.netbeans.modules.project.ui; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.text.MessageFormat ; 25 import javax.swing.JComponent ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectUtils; 28 import org.netbeans.api.project.Sources; 29 import org.netbeans.modules.project.uiapi.ProjectChooserFactory; 30 import org.netbeans.spi.project.ui.templates.support.Templates; 31 import org.openide.WizardDescriptor; 32 import org.openide.loaders.DataObject; 33 import org.openide.loaders.DataObjectNotFoundException; 34 35 import org.openide.loaders.TemplateWizard; 36 import org.openide.util.NbBundle; 37 38 public final class NewFileWizard extends TemplateWizard { 39 40 private Project currP; 41 private MessageFormat format; 42 44 private Project getCurrentProject () { 45 return currP; 46 } 47 48 private void setCurrentProject (Project p) { 49 this.currP = p; 50 } 51 52 public NewFileWizard( Project project ) { 53 setCurrentProject (project); 54 putProperty( ProjectChooserFactory.WIZARD_KEY_PROJECT, getCurrentProject () ); 55 format = new MessageFormat (NbBundle.getBundle (NewFileWizard.class).getString ("LBL_NewFileWizard_MessageFormat")); 56 addPropertyChangeListener (new PropertyChangeListener () { 59 public void propertyChange (PropertyChangeEvent evt) { 60 if (ProjectChooserFactory.WIZARD_KEY_PROJECT.equals (evt.getPropertyName ())) { 62 Project newProject = (Project)evt.getNewValue (); 63 if (!getCurrentProject ().equals (newProject)) { 64 setCurrentProject (newProject); 66 try { 67 if (Templates.getTemplate (NewFileWizard.this) != null) { 70 DataObject obj = DataObject.find (Templates.getTemplate (NewFileWizard.this)); 71 72 Object unknownIterator = obj.getPrimaryFile ().getAttribute ("instantiatingIterator"); if (unknownIterator == null) { 75 unknownIterator = obj.getPrimaryFile ().getAttribute ("templateWizardIterator"); } 77 if (unknownIterator == null) { 79 try { 80 obj.getPrimaryFile ().setAttribute ("instantiatingIterator", NewFileIterator.genericFileIterator ()); } catch (java.io.IOException e) { 82 } 84 } 85 Hacks.reloadPanelsInWizard (NewFileWizard.this, obj); 86 } 87 } catch (DataObjectNotFoundException ex) { 88 ex.printStackTrace(); 89 } 90 } 91 } 92 } 93 }); 94 } 95 96 public void updateState () { 97 super.updateState (); 98 String substitute = (String )getProperty ("NewFileWizard_Title"); String title; 100 if (substitute == null) { 101 title = NbBundle.getBundle (NewFileWizard.class).getString ("LBL_NewFileWizard_Title"); } else { 103 Object [] args = new Object [] { 104 NbBundle.getBundle (NewFileWizard.class).getString ("LBL_NewFileWizard_Subtitle"), substitute}; 106 title = format.format (args); 107 } 108 super.setTitle (title); 109 } 110 111 public void setTitle (String ignore) {} 112 113 protected WizardDescriptor.Panel createTemplateChooser () { 114 WizardDescriptor.Panel panel = new TemplateChooserPanel( getCurrentProject () ); 115 JComponent jc = (JComponent )panel.getComponent (); 116 jc.getAccessibleContext ().setAccessibleName (NbBundle.getBundle (NewProjectWizard.class).getString ("ACSN_NewFileWizard")); jc.getAccessibleContext ().setAccessibleDescription (NbBundle.getBundle (NewProjectWizard.class).getString ("ACSD_NewFileWizard")); return panel; 119 } 120 121 protected WizardDescriptor.Panel createTargetChooser () { 122 Sources c = ProjectUtils.getSources(getCurrentProject ()); 123 return Templates.createSimpleTargetChooser(getCurrentProject (), c.getSourceGroups(Sources.TYPE_GENERIC)); 124 } 125 126 } 127 128 134 | Popular Tags |