KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > multiview > EntityOverviewPanel


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.ddloaders.multiview;
21
22 import org.netbeans.modules.j2ee.dd.api.ejb.CmpField;
23 import org.netbeans.modules.j2ee.dd.api.ejb.Entity;
24 import org.netbeans.modules.j2ee.ddloaders.multiview.ui.EntityOverviewForm;
25 import org.netbeans.modules.xml.multiview.ItemComboBoxHelper;
26 import org.netbeans.modules.xml.multiview.ItemEditorHelper;
27 import org.netbeans.modules.xml.multiview.ItemCheckBoxHelper;
28 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer;
29 import org.netbeans.modules.xml.multiview.ui.SectionNodeView;
30
31 import javax.swing.*;
32 import java.awt.event.ActionEvent JavaDoc;
33 import java.awt.event.ActionListener JavaDoc;
34
35 /**
36  * @author pfiala
37  */

38 public class EntityOverviewPanel extends EntityOverviewForm {
39
40     private XmlMultiViewDataSynchronizer synchronizer;
41     private Entity entity;
42     private static final String JavaDoc PK_COMPOUND = Utils.getBundleMessage("LBL_Compound_PK");
43     private EntityHelper entityHelper;
44
45     /**
46      * Creates new form EntityOverviewForm
47      */

48     public EntityOverviewPanel(SectionNodeView sectionNodeView, final Entity entity, final EntityHelper entityHelper) {
49         super(sectionNodeView);
50         this.entityHelper = entityHelper;
51         synchronizer = ((EjbJarMultiViewDataObject) sectionNodeView.getDataObject()).getModelSynchronizer();
52
53         JTextField ejbNameTextField = getEjbNameTextField();
54         JTextField persistenceTypeTextField = getPersistenceTypeTextField();
55         JTextField abstractSchemaNameTextField = getAbstractSchemaNameTextField();
56         JLabel primaryKeyFieldLabel = getPrimaryKeyFieldLabel();
57         final JComboBox primaryKeyFieldComboBox = getPrimaryKeyFieldComboBox();
58         final JComboBox primaryKeyClassComboBox = getPrimaryKeyClassComboBox();
59         final JTextField primaryKeyClassTextField = getPrimaryKeyClassTextField();
60
61         addRefreshable(new ItemEditorHelper(ejbNameTextField, new TextItemEditorModel(synchronizer, false) {
62             protected String JavaDoc getValue() {
63                 return entity.getEjbName();
64             }
65
66             protected void setValue(String JavaDoc value) {
67                 entity.setEjbName(value);
68             }
69         }));
70         ejbNameTextField.setEditable(false);
71
72         persistenceTypeTextField.setEditable(false);
73         this.entity = entity;
74         String JavaDoc persistenceType = this.entity.getPersistenceType();
75         boolean isCmp = Entity.PERSISTENCE_TYPE_CONTAINER.equals(persistenceType);
76         persistenceTypeTextField.setText(persistenceType + ((isCmp ? " (CMP)" : " (BMP)"))); //NOI18N
77

78         addRefreshable(new ItemEditorHelper(abstractSchemaNameTextField, new TextItemEditorModel(synchronizer, true) {
79             protected String JavaDoc getValue() {
80                 return entity.getAbstractSchemaName();
81             }
82
83             protected void setValue(String JavaDoc value) {
84                 entity.setAbstractSchemaName(value);
85             }
86         }));
87         abstractSchemaNameTextField.setEditable(false);
88
89         if (isCmp) {
90             primaryKeyFieldLabel.setVisible(true);
91             primaryKeyFieldComboBox.setVisible(true);
92             primaryKeyClassComboBox.setVisible(true);
93             primaryKeyClassTextField.setVisible(false);
94
95             initPrimaryKeyFieldComboBox();
96             final ItemComboBoxHelper primaryKeyComboBoxHelper = new ItemComboBoxHelper(synchronizer,
97                     primaryKeyFieldComboBox) {
98                 public String JavaDoc getItemValue() {
99                     String JavaDoc value = entity.getPrimkeyField();
100                     return value == null ? PK_COMPOUND : value;
101                 }
102
103                 public void setItemValue(String JavaDoc value) {
104                     try {
105                         entityHelper.setPrimkeyField(value == PK_COMPOUND ? null : value);
106                     } catch (ClassNotFoundException JavaDoc e) {
107                         Utils.notifyError(e);
108                     }
109                 }
110             };
111             addRefreshable(primaryKeyComboBoxHelper);
112             primaryKeyFieldComboBox.addActionListener(new ActionListener JavaDoc() {
113                 public void actionPerformed(ActionEvent JavaDoc e) {
114                     int selectedIndex = primaryKeyFieldComboBox.getSelectedIndex();
115                     if (selectedIndex == 0) {
116                         primaryKeyClassComboBox.setEnabled(true);
117                         primaryKeyClassComboBox.setSelectedItem(entity.getPrimKeyClass());
118                     } else {
119                         primaryKeyClassComboBox.setEnabled(false);
120                     }
121                     primaryKeyClassComboBox.setSelectedItem(entity.getPrimKeyClass());
122                 }
123             });
124             primaryKeyClassComboBox.setEnabled(primaryKeyFieldComboBox.getSelectedIndex() == 0);
125
126             primaryKeyClassComboBox.addItem("boolean"); //NOI18N
127
primaryKeyClassComboBox.addItem("byte"); //NOI18N
128
primaryKeyClassComboBox.addItem("char"); //NOI18N
129
primaryKeyClassComboBox.addItem("double"); //NOI18N
130
primaryKeyClassComboBox.addItem("float"); //NOI18N
131
primaryKeyClassComboBox.addItem("int"); //NOI18N
132
primaryKeyClassComboBox.addItem("long"); //NOI18N
133
primaryKeyClassComboBox.addItem("java.lang.Boolean"); //NOI18N
134
primaryKeyClassComboBox.addItem("java.lang.Byte"); //NOI18N
135
primaryKeyClassComboBox.addItem("java.lang.Character"); //NOI18N
136
primaryKeyClassComboBox.addItem("java.lang.Double"); //NOI18N
137
primaryKeyClassComboBox.addItem("java.lang.Float"); //NOI18N
138
primaryKeyClassComboBox.addItem("java.lang.Integer"); //NOI18N
139
primaryKeyClassComboBox.addItem("java.lang.Long"); //NOI18N
140
primaryKeyClassComboBox.addItem("java.lang.Object"); //NOI18N
141
primaryKeyClassComboBox.addItem("java.lang.String"); //NOI18N
142
primaryKeyClassComboBox.addItem("java.math.BigDecimal");//NOI18N
143

144             addRefreshable(new ItemComboBoxHelper(synchronizer, primaryKeyClassComboBox) {
145                 public String JavaDoc getItemValue() {
146                     return entity.getPrimKeyClass();
147                 }
148
149                 public void setItemValue(String JavaDoc value) {
150                     if (Utils.isValidPackageName(value)) {
151 // entityHelper.setPrimKeyClass(JMIUtils.resolveType(value));
152
} else {
153                         primaryKeyComboBoxHelper.refresh();
154                     }
155                 }
156             });
157
158         } else {
159             primaryKeyFieldLabel.setVisible(false);
160             primaryKeyFieldComboBox.setVisible(false);
161             primaryKeyClassComboBox.setVisible(false);
162             primaryKeyClassTextField.setVisible(true);
163
164             addRefreshable(new ItemEditorHelper(primaryKeyClassTextField, new TextItemEditorModel(synchronizer, false) {
165                 protected String JavaDoc getValue() {
166                     return entity.getPrimKeyClass();
167                 }
168
169                 protected void setValue(String JavaDoc value) {
170                     entity.setPrimKeyClass(value);
171                 }
172             }));
173         }
174         addRefreshable(new ItemCheckBoxHelper(synchronizer, getReentrantCheckBox()) {
175             public boolean getItemValue() {
176                 return entity.isReentrant();
177             }
178
179             public void setItemValue(boolean value) {
180                 entity.setReentrant(value);
181             }
182         });
183     }
184
185     private void initPrimaryKeyFieldComboBox() {
186         final JComboBox primaryKeyFieldComboBox = getPrimaryKeyFieldComboBox();
187         CmpField[] cmpFields = entityHelper.cmpFields.getCmpFields();
188         String JavaDoc[] items = new String JavaDoc[cmpFields.length + 1];
189         items[0] = PK_COMPOUND;
190         for (int i = 0; i < cmpFields.length; i++) {
191             items[i+1] = cmpFields[i].getFieldName();
192         }
193         primaryKeyFieldComboBox.setModel(new DefaultComboBoxModel(items));
194     }
195
196     public void dataModelPropertyChange(Object JavaDoc source, String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
197         super.dataModelPropertyChange(source, propertyName, oldValue, newValue);
198     }
199
200     public void refreshView() {
201         initPrimaryKeyFieldComboBox();
202         super.refreshView();
203         getReentrantCheckBox().setSelected(entity.isReentrant());
204     }
205 }
206
Popular Tags