1 19 20 package org.netbeans.modules.project.ui; 21 22 import java.awt.Component ; 23 import java.util.ArrayList ; 24 import java.util.List ; 25 import javax.swing.event.ChangeEvent ; 26 import javax.swing.event.ChangeListener ; 27 import org.netbeans.api.project.Project; 28 import org.netbeans.modules.project.uiapi.ProjectChooserFactory; 29 import org.openide.NotifyDescriptor; 30 import org.openide.WizardDescriptor; 31 import org.openide.ErrorManager; 32 import org.openide.loaders.DataObject; 33 import org.openide.loaders.DataObjectNotFoundException; 34 import org.openide.loaders.TemplateWizard; 35 import org.openide.util.HelpCtx; 36 import org.openide.util.NbBundle; 37 38 42 43 final class TemplateChooserPanel implements WizardDescriptor.Panel, ChangeListener { 44 45 private static String lastCategory = null; 46 private static String lastTemplate = null; 47 48 private final List <ChangeListener > listeners = new ArrayList <ChangeListener >(); 49 private TemplateChooserPanelGUI gui; 50 51 private Project project; 52 54 TemplateChooserPanel( Project p ) { 55 this.project = p; 56 57 } 58 59 public Component getComponent() { 60 if (gui == null) { 61 gui = new TemplateChooserPanelGUI(); 62 gui.addChangeListener(this); 63 } 64 return gui; 65 } 66 67 public HelpCtx getHelp() { 68 return null; 70 } 71 72 public boolean isValid() { 73 return gui != null && gui.getTemplate() != null; 74 } 75 76 public synchronized void addChangeListener(ChangeListener l) { 77 listeners.add(l); 78 } 79 80 public synchronized void removeChangeListener(ChangeListener l) { 81 listeners.remove(l); 82 } 83 84 private void fireChange() { 85 ChangeEvent e = new ChangeEvent (this); 86 List <ChangeListener > templist; 87 synchronized (this) { 88 templist = new ArrayList <ChangeListener > (listeners); 89 } 90 for (ChangeListener l: templist) { 91 l.stateChanged(e); 92 } 93 } 94 95 public void readSettings(Object settings) { 96 TemplateChooserPanelGUI panel = (TemplateChooserPanelGUI) this.getComponent(); 97 panel.readValues( project, lastCategory, lastTemplate ); 98 ((WizardDescriptor)settings).putProperty ("WizardPanel_contentSelectedIndex", new Integer (0)); ((WizardDescriptor)settings).putProperty ("WizardPanel_contentData", new String [] { NbBundle.getBundle (TemplateChooserPanel.class).getString ("LBL_TemplatesPanel_Name"), NbBundle.getBundle (TemplateChooserPanel.class).getString ("LBL_TemplatesPanel_Dots")}); ((WizardDescriptor)settings).putProperty ("NewFileWizard_Title", null); } 105 106 public void storeSettings(Object settings) { 107 108 WizardDescriptor wd = (WizardDescriptor)settings; 109 110 Object value = wd.getValue(); 111 112 if ( NotifyDescriptor.CANCEL_OPTION != value && 113 NotifyDescriptor.CLOSED_OPTION != value ) { 114 try { 115 116 Project newProject = gui.getProject (); 117 if (!project.equals (newProject)) { 118 project = newProject; 119 wd.putProperty( ProjectChooserFactory.WIZARD_KEY_PROJECT, newProject ); 120 } 121 122 if (gui.getTemplate () == null) { 123 return ; 124 } 125 126 if (wd instanceof TemplateWizard) { 127 ((TemplateWizard)wd).setTemplate( DataObject.find( gui.getTemplate() ) ); 128 } else { 129 wd.putProperty( ProjectChooserFactory.WIZARD_KEY_TEMPLATE, gui.getTemplate () ); 130 } 131 132 lastCategory = gui.getCategoryName(); 133 lastTemplate = gui.getTemplateName(); 134 } 135 catch( DataObjectNotFoundException e ) { 136 ErrorManager.getDefault().notify (e); 137 } 138 } 139 } 140 141 public void stateChanged(ChangeEvent e) { 142 151 fireChange(); 152 153 } 154 155 } 156 | Popular Tags |