1 19 20 package org.netbeans.modules.j2ee.persistence.unit; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import org.netbeans.modules.j2ee.persistence.dd.persistence.model_1_0.PersistenceUnit; 27 import org.netbeans.modules.xml.multiview.XmlMultiViewDataObject; 28 import org.netbeans.modules.xml.multiview.ui.InnerPanelFactory; 29 import org.netbeans.modules.xml.multiview.ui.SectionView; 30 import org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor; 31 import org.netbeans.modules.xml.multiview.ui.SectionInnerPanel; 32 33 39 public class PersistenceUnitPanelFactory implements InnerPanelFactory, PropertyChangeListener { 40 41 private PUDataObject dObj; 42 private ToolBarDesignEditor editor; 43 47 private Map <PersistenceUnit, PersistenceUnitPanel> cache = new HashMap <PersistenceUnit, PersistenceUnitPanel>(10); 48 49 50 PersistenceUnitPanelFactory(ToolBarDesignEditor editor, PUDataObject dObj) { 51 this.dObj=dObj; 52 this.editor=editor; 53 dObj.addPropertyChangeListener(this); 54 } 55 56 61 public SectionInnerPanel createInnerPanel(Object key) { 62 if (!(key instanceof PersistenceUnit)) { 63 throw new IllegalArgumentException ("The given key must be an instance of PersistenceUnit"); } 65 PersistenceUnit punit = (PersistenceUnit) key; 66 PersistenceUnitPanel panel = cache.get(punit); 67 if (panel == null){ 68 panel = new PersistenceUnitPanel((SectionView)editor.getContentView(), dObj, punit); 69 cache.put(punit, panel); 70 } 71 return panel; 72 } 73 74 public void propertyChange(PropertyChangeEvent evt) { 75 if (!XmlMultiViewDataObject.PROPERTY_DATA_MODIFIED.equals(evt.getPropertyName())){ 76 cache.clear(); 77 } 78 } 79 } 80 81 | Popular Tags |