KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > ejbmodule > CmpEntityEjbCustomizer


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  * CmpEntityEjbCustomizer.java October 26, 2003, 9:23 PM
21  *
22  */

23
24 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.ejbmodule;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.awt.GridBagConstraints JavaDoc;
29
30 import com.sun.jdo.api.persistence.model.Model;
31 import com.sun.jdo.modules.persistence.mapping.core.util.MappingContext;
32 import com.sun.jdo.modules.persistence.mapping.core.util.MappingContextFactory;
33 import com.sun.jdo.modules.persistence.mapping.ejb.ui.panels.BeanMappingPanel;
34
35 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Cmp;
36 import org.netbeans.modules.j2ee.sun.dd.api.ejb.Finder;
37 import org.netbeans.modules.j2ee.sun.dd.api.ejb.OneOneFinders;
38
39 import org.netbeans.modules.j2ee.sun.share.configbean.Base;
40 import org.netbeans.modules.j2ee.sun.share.configbean.BaseEjb;
41 import org.netbeans.modules.j2ee.sun.share.configbean.CmpEntityEjb;
42 import org.netbeans.modules.j2ee.sun.share.configbean.EjbJarRoot;
43
44 /**
45  *
46  * @author Rajeshwar Patil
47  * @version %I%, %G%
48  */

49 public class CmpEntityEjbCustomizer extends EntityEjbCustomizer{
50
51     private CmpEntityEjb theBean;
52     private OneOneFinderPanel finderPanel;
53 // private FlushAtEndOfMethodPanel flushAtEndOfMethodPanel;
54
private PrefetchDisabledPanel prefetchDisabledPanel;
55     private CmpEntityEjbPanel cmpEntityEjbPanel;
56     private CmpPanel cmpPanel;
57     private BeanMappingPanel mappingPanel;
58
59     /** Creates a new instance of CmpEntityEjbCustomizer */
60     public CmpEntityEjbCustomizer() {
61     }
62
63
64     public void setObject(Object JavaDoc bean) {
65         super.setObject(bean);
66         // Only do this if the bean is actually changing.
67
if(theBean != bean) {
68             if(bean instanceof CmpEntityEjb) {
69                 theBean = (CmpEntityEjb) bean;
70            }
71         }
72     }
73
74
75     //get the bean specific panel
76
protected javax.swing.JPanel JavaDoc getBeanPanel(){
77         cmpPanel = new CmpPanel();
78
79         EntityEjbPanel entityEjbPanel = (EntityEjbPanel)super.getBeanPanel();
80         if(entityEjbPanel != null){
81             GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
82             gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
83             gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
84             gridBagConstraints.weightx = 1.0;
85             cmpPanel.add(entityEjbPanel, gridBagConstraints);
86         }
87
88         cmpEntityEjbPanel = new CmpEntityEjbPanel(this);
89         if(cmpEntityEjbPanel != null){
90             GridBagConstraints JavaDoc gridBagConstraints = new GridBagConstraints JavaDoc();
91             gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
92             gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
93             gridBagConstraints.weightx = 1.0;
94             cmpPanel.add(cmpEntityEjbPanel, gridBagConstraints);
95         }
96
97         return cmpPanel;
98     }
99
100
101     //initialize all the elements in the bean specific panel
102
protected void initializeBeanPanel(BaseEjb theBean){
103         super.initializeBeanPanel(theBean);
104         if(!(theBean instanceof CmpEntityEjb)){
105             assert(false);
106         }
107
108         CmpEntityEjb cmpEntityEjb = (CmpEntityEjb)theBean;
109         Cmp cmp = cmpEntityEjb.getCmp();
110         
111         if(cmp != null){
112             String JavaDoc mappingProperties =
113                 cmp.getMappingProperties();
114             if(mappingProperties != null){
115                 cmpEntityEjbPanel.setMappingProperties(mappingProperties);
116             }
117         }
118     }
119
120
121     protected void addTabbedBeanPanels() {
122         super.addTabbedBeanPanels();
123         MappingContext dummyContext =
124             MappingContextFactory.getMappingContext(Model.RUNTIME);
125         OneOneFinderModel finderModel =
126             new OneOneFinderModel();
127         finderModel.addTableModelListener(this);
128         finderPanel = new OneOneFinderPanel(finderModel);
129         finderPanel.getAccessibleContext().setAccessibleName(bundle.getString("One_One_Finders_Acsbl_Name")); //NOI18N
130
finderPanel.getAccessibleContext().setAccessibleDescription(bundle.getString("One_One_Finders_Acsbl_Desc")); //NOI18N
131
tabbedPanel.addTab(bundle.getString("LBL_One_One_Finders"), // NOI18N
132
finderPanel);
133
134
135
136 // flushAtEndOfMethodPanel = new FlushAtEndOfMethodPanel(theBean, this);
137
// flushAtEndOfMethodPanel.addTableModelListener(this);
138
// tabbedPanel.addTab(bundle.getString("LBL_Flush_At_End_Of_Method"), // NOI18N
139
// flushAtEndOfMethodPanel);
140

141
142         prefetchDisabledPanel = new PrefetchDisabledPanel(theBean, this);
143         prefetchDisabledPanel.getAccessibleContext().setAccessibleName(bundle.getString("Prefetch_Disabled_Acsbl_Name")); //NOI18N
144
prefetchDisabledPanel.getAccessibleContext().setAccessibleDescription(bundle.getString("Prefetch_Disabled_Acsbl_Desc")); //NOI18N
145
prefetchDisabledPanel.addTableModelListener(this);
146         tabbedPanel.addTab(bundle.getString("LBL_Prefetch_Disabled"), // NOI18N
147
prefetchDisabledPanel);
148
149         mappingPanel = new BeanMappingPanel(dummyContext);
150         mappingPanel.getAccessibleContext().setAccessibleName(bundle.getString("Cmp_Mapping_Acsbl_Name")); //NOI18N
151
mappingPanel.getAccessibleContext().setAccessibleDescription(bundle.getString("Cmp_Mapping_Acsbl_Desc")); //NOI18N
152
mappingPanel.setApplyChangesImmediately(true);
153         tabbedPanel.add(mappingPanel, bundle.getString("LBL_Cmp_Mapping"), 0); // NOI18N
154

155         //Select Cmp Mapping Panel
156
tabbedPanel.setSelectedIndex(0);
157     }
158
159
160     protected void initializeTabbedBeanPanels(BaseEjb theBean) {
161         super.initializeTabbedBeanPanels(theBean);
162         if(!(theBean instanceof CmpEntityEjb)){
163             assert(false);
164         }
165
166
167         CmpEntityEjb cmpEntityEjb = (CmpEntityEjb)theBean;
168         Cmp cmp = cmpEntityEjb.getCmp();
169         if(cmp == null){
170             finderPanel.setModel(cmpEntityEjb,null);
171         }else{
172             OneOneFinders oneOneFinders = cmp.getOneOneFinders();
173             if(oneOneFinders == null){
174                 finderPanel.setModel(cmpEntityEjb,null);
175             }else{
176                 Finder[] finder = oneOneFinders.getFinder();
177                 finderPanel.setModel(cmpEntityEjb, finder);
178             }
179         }
180  
181 // flushAtEndOfMethodPanel.setData(cmpEntityEjb);
182

183         prefetchDisabledPanel.setData(cmpEntityEjb);
184
185         if (theBean != null) {
186             Base myParent = theBean.getParent();
187             EjbJarRoot jarBean;
188
189             if (myParent instanceof EjbJarRoot) {
190                 String JavaDoc beanName = null;
191
192                 jarBean = (EjbJarRoot)myParent;
193                 beanName = theBean.getEjbName();
194                 mappingPanel.setMappingContext(
195                     jarBean.getMappingContext(), jarBean.getEJBInfoHelper());
196
197                 // if no corresponding MCE object, this must be a new
198
// bean, have jarBean create the skeleton
199
jarBean.ensureCmpMappingExists(beanName);
200
201                 mappingPanel.showMappingForBean(beanName);
202             }
203         }
204 // TODO - clear the mapping panel if theBean is null?
205
}
206
207
208     public Collection JavaDoc getErrors(){
209         ArrayList JavaDoc errors = null;
210         if(validationSupport == null) assert(false);
211         errors = (ArrayList JavaDoc)super.getErrors();
212
213         //Cmp Entity Ejb field Validations
214
String JavaDoc property = cmpEntityEjbPanel.getMappingProperties();
215         errors.addAll(validationSupport.validate(property,
216             "/sun-ejb-jar/enterprise-beans/ejb/cmp/mapping-properties", //NOI18N
217
bundle.getString("LBL_Mapping_Properties"))); //NOI18N
218

219         return errors;
220     }
221
222
223     public String JavaDoc getHelpId() {
224     return "AS_CFG_CmpEntityEjb"; //NOI18N
225
}
226
227     //Cmp Entity Ejb(Mapping Properties) update methods
228
void updateMappingProperties(String JavaDoc mappingProperties){
229         Cmp cmp = getCmp();
230         if((EMPTY_STRING.equals(mappingProperties)) || (null == mappingProperties)){
231             cmp.setMappingProperties(null);
232             updateCmp();
233         }else{
234             cmp.setMappingProperties(mappingProperties);
235         }
236         notifyChange();
237     }
238
239
240     private Cmp getCmp(){
241         Cmp cmp = theBean.getCmp();
242         if(cmp == null){
243             cmp = theBean.getConfig().getStorageFactory().createCmp();
244             try {
245                 theBean.setCmp(cmp);
246             }catch(java.beans.PropertyVetoException JavaDoc exception){
247             }
248         }
249         return cmp;
250     }
251
252
253     private void updateCmp(){
254         Cmp cmp = getCmp();
255         if(cmp.getMappingProperties() != null) return;
256         if (cmp.getOneOneFinders() != null) return;
257
258         try{
259             theBean.setCmp(null);
260         }catch(java.beans.PropertyVetoException JavaDoc exception){
261         }
262     }
263 }
264
Popular Tags