1 19 20 package org.netbeans.modules.j2ee.persistence.wizard; 21 22 import java.awt.Component ; 23 import java.util.HashSet ; 24 import java.util.Iterator ; 25 import java.util.Set ; 26 import javax.swing.JComponent ; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 29 30 import org.openide.WizardDescriptor; 31 import org.openide.util.HelpCtx; 32 33 36 public final class PersistenceClientEntitySelection implements WizardDescriptor.Panel, WizardDescriptor.FinishablePanel, ChangeListener { 37 38 private WizardDescriptor wizardDescriptor; 39 private String panelName; 40 private HelpCtx helpCtx; 41 private PersistenceClientEntitySelectionVisual component; 42 43 44 45 public PersistenceClientEntitySelection(String panelName, HelpCtx helpCtx, WizardDescriptor wizardDescriptor) { 46 this.panelName = panelName; 47 this.helpCtx = helpCtx; 48 this.wizardDescriptor = wizardDescriptor; 49 } 50 51 public boolean isFinishPanel() { 52 return false; 53 } 54 55 public Component getComponent() { 56 if (component == null) { 57 component = new PersistenceClientEntitySelectionVisual(panelName, wizardDescriptor); 58 component.addChangeListener(this); 59 } 60 return component; 61 } 62 63 public HelpCtx getHelp() { 64 return helpCtx; 65 } 66 67 public boolean isValid() { 68 getComponent(); 69 return component.valid(wizardDescriptor); 70 } 71 72 private final Set listeners = new HashSet (1); 73 74 public final void addChangeListener(ChangeListener l) { 75 synchronized (listeners) { 76 listeners.add(l); 77 } 78 } 79 public final void removeChangeListener(ChangeListener l) { 80 synchronized (listeners) { 81 listeners.remove(l); 82 } 83 } 84 protected final void fireChangeEvent(ChangeEvent ev) { 85 Iterator it; 86 synchronized (listeners) { 87 it = new HashSet (listeners).iterator(); 88 } 89 while (it.hasNext()) { 90 ((ChangeListener )it.next()).stateChanged(ev); 91 } 92 } 93 94 public void readSettings(Object settings) { 95 wizardDescriptor = (WizardDescriptor) settings; 96 component.read(wizardDescriptor); 97 98 Object substitute = ((JComponent ) component).getClientProperty("NewProjectWizard_Title"); if (substitute != null){ 102 wizardDescriptor.putProperty("NewProjectWizard_Title", substitute); } 104 } 105 106 public void storeSettings(Object settings) { 107 WizardDescriptor d = (WizardDescriptor) settings; 108 component.store(d); 109 d.putProperty(WizardProperties.PERSISTENCE_UNIT, component.getPersistenceUnit()); 110 ((WizardDescriptor) d).putProperty("NewProjectWizard_Title", null); } 112 113 public void stateChanged(ChangeEvent e) { 114 fireChangeEvent(e); 115 } 116 117 } 118 | Popular Tags |