1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import javax.swing.event.ChangeEvent ; 25 import javax.swing.event.ChangeListener ; 26 import javax.swing.event.EventListenerList ; 27 import org.openide.WizardDescriptor; 28 import org.openide.util.HelpCtx; 29 import org.openide.util.NbBundle; 30 31 36 public abstract class BasicWizardPanel implements WizardDescriptor.Panel, PropertyChangeListener { 37 38 private boolean valid = true; 39 private WizardDescriptor settings; 40 41 private EventListenerList listeners = new EventListenerList (); 42 43 protected BasicWizardPanel(WizardDescriptor settings) { 44 this.settings = settings; 45 } 46 47 public void setSettings(WizardDescriptor settings) { 48 this.settings = settings; 49 } 50 51 protected WizardDescriptor getSettings() { 52 return settings; 53 } 54 55 public void addChangeListener(ChangeListener l) { 56 listeners.add(ChangeListener .class, l); 57 } 58 59 public void removeChangeListener(ChangeListener l) { 60 listeners.remove(ChangeListener .class, l); 61 } 62 63 protected void fireChange() { 64 ChangeListener [] chListeners = (ChangeListener []) listeners. 65 getListeners(ChangeListener .class); 66 ChangeEvent e = new ChangeEvent (this); 67 for (int i = 0; i < chListeners.length; i++) { 68 chListeners[i].stateChanged(e); 69 } 70 } 71 72 75 protected final String getMessage(String key) { 76 return NbBundle.getMessage(getClass(), key); 77 } 78 79 public HelpCtx getHelp() { 80 return null; 81 } 82 83 public void storeSettings(Object settings) {} 84 85 public void readSettings(Object settings) {} 86 87 public boolean isValid() { 88 return valid; 89 } 90 91 96 public void propertyChange(PropertyChangeEvent evt) { 97 if ("valid".equals(evt.getPropertyName())) { boolean nueValid = ((Boolean ) evt.getNewValue()).booleanValue(); 99 if (nueValid != valid) { 100 valid = nueValid; 101 fireChange(); 102 } 103 } 104 } 105 106 abstract static class NewTemplatePanel extends BasicWizardPanel { 107 108 private final NewModuleProjectData data; 109 110 NewTemplatePanel(final NewModuleProjectData data) { 111 super(data.getSettings()); 112 this.data = data; 113 } 114 115 abstract void reloadData(); 116 abstract void storeData(); 117 118 public NewModuleProjectData getData() { 119 return data; 120 } 121 122 public void readSettings(Object settings) { 123 reloadData(); 124 } 125 126 public void storeSettings(Object settings) { 127 storeData(); 128 } 129 130 protected String getWizardTypeString() { 131 String helpId = null; 132 switch (data.getWizardType()) { 133 case NewNbModuleWizardIterator.TYPE_SUITE: 134 helpId = "suite"; break; 136 case NewNbModuleWizardIterator.TYPE_MODULE: 137 case NewNbModuleWizardIterator.TYPE_SUITE_COMPONENT: 138 helpId = "module"; break; 140 case NewNbModuleWizardIterator.TYPE_LIBRARY_MODULE: 141 helpId = "library"; break; 143 default: 144 assert false : "Unknown wizard type = " + data.getWizardType(); 145 } 146 return helpId; 147 } 148 149 } 150 151 } | Popular Tags |