1 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 ; 33 import java.awt.event.ActionListener ; 34 35 38 public class EntityOverviewPanel extends EntityOverviewForm { 39 40 private XmlMultiViewDataSynchronizer synchronizer; 41 private Entity entity; 42 private static final String PK_COMPOUND = Utils.getBundleMessage("LBL_Compound_PK"); 43 private EntityHelper entityHelper; 44 45 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 getValue() { 63 return entity.getEjbName(); 64 } 65 66 protected void setValue(String value) { 67 entity.setEjbName(value); 68 } 69 })); 70 ejbNameTextField.setEditable(false); 71 72 persistenceTypeTextField.setEditable(false); 73 this.entity = entity; 74 String persistenceType = this.entity.getPersistenceType(); 75 boolean isCmp = Entity.PERSISTENCE_TYPE_CONTAINER.equals(persistenceType); 76 persistenceTypeTextField.setText(persistenceType + ((isCmp ? " (CMP)" : " (BMP)"))); 78 addRefreshable(new ItemEditorHelper(abstractSchemaNameTextField, new TextItemEditorModel(synchronizer, true) { 79 protected String getValue() { 80 return entity.getAbstractSchemaName(); 81 } 82 83 protected void setValue(String 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 getItemValue() { 99 String value = entity.getPrimkeyField(); 100 return value == null ? PK_COMPOUND : value; 101 } 102 103 public void setItemValue(String value) { 104 try { 105 entityHelper.setPrimkeyField(value == PK_COMPOUND ? null : value); 106 } catch (ClassNotFoundException e) { 107 Utils.notifyError(e); 108 } 109 } 110 }; 111 addRefreshable(primaryKeyComboBoxHelper); 112 primaryKeyFieldComboBox.addActionListener(new ActionListener () { 113 public void actionPerformed(ActionEvent 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"); primaryKeyClassComboBox.addItem("byte"); primaryKeyClassComboBox.addItem("char"); primaryKeyClassComboBox.addItem("double"); primaryKeyClassComboBox.addItem("float"); primaryKeyClassComboBox.addItem("int"); primaryKeyClassComboBox.addItem("long"); primaryKeyClassComboBox.addItem("java.lang.Boolean"); primaryKeyClassComboBox.addItem("java.lang.Byte"); primaryKeyClassComboBox.addItem("java.lang.Character"); primaryKeyClassComboBox.addItem("java.lang.Double"); primaryKeyClassComboBox.addItem("java.lang.Float"); primaryKeyClassComboBox.addItem("java.lang.Integer"); primaryKeyClassComboBox.addItem("java.lang.Long"); primaryKeyClassComboBox.addItem("java.lang.Object"); primaryKeyClassComboBox.addItem("java.lang.String"); primaryKeyClassComboBox.addItem("java.math.BigDecimal"); 144 addRefreshable(new ItemComboBoxHelper(synchronizer, primaryKeyClassComboBox) { 145 public String getItemValue() { 146 return entity.getPrimKeyClass(); 147 } 148 149 public void setItemValue(String value) { 150 if (Utils.isValidPackageName(value)) { 151 } 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 getValue() { 166 return entity.getPrimKeyClass(); 167 } 168 169 protected void setValue(String 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 [] items = new String [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 source, String propertyName, Object oldValue, Object 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 |