KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > unit > PersistenceUnitPanelFactory


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.persistence.unit;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
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 /**
34  * Factory for creating persistence unit panels.
35  *
36  * @author mkuchtiak
37  * @author Erno Mononen
38  */

39 public class PersistenceUnitPanelFactory implements InnerPanelFactory, PropertyChangeListener JavaDoc {
40     
41     private PUDataObject dObj;
42     private ToolBarDesignEditor editor;
43     /**
44      * A naive cache for preventing reinitialization of persistence unit panels
45      * if nothing has changed.
46      */

47     private Map JavaDoc<PersistenceUnit, PersistenceUnitPanel> cache = new HashMap JavaDoc<PersistenceUnit, PersistenceUnitPanel>(10);
48     
49     /** Creates a new instance of PersistenceUnitPanelFactory */
50     PersistenceUnitPanelFactory(ToolBarDesignEditor editor, PUDataObject dObj) {
51         this.dObj=dObj;
52         this.editor=editor;
53         dObj.addPropertyChangeListener(this);
54     }
55     
56     /**
57      * Gets the inner panel associated with the given key or creates a new inner
58      * panel if the key had no associated panel yet.
59      * @param key the persistence unit whose associated panel should be retrieved.
60      */

61     public SectionInnerPanel createInnerPanel(Object JavaDoc key) {
62         if (!(key instanceof PersistenceUnit)) {
63             throw new IllegalArgumentException JavaDoc("The given key must be an instance of PersistenceUnit"); //NO18N
64
}
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 JavaDoc evt) {
75         if (!XmlMultiViewDataObject.PROPERTY_DATA_MODIFIED.equals(evt.getPropertyName())){
76             cache.clear();
77         }
78     }
79 }
80
81
Popular Tags