1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp; 26 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.ResourceBundle ; 30 import java.text.MessageFormat ; 31 32 import java.awt.Dimension ; 33 34 import javax.swing.JPanel ; 35 import javax.swing.DefaultComboBoxModel ; 36 37 import org.netbeans.modules.j2ee.sun.share.Constants; 38 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion; 39 import org.netbeans.modules.j2ee.sun.share.configbean.Utils; 40 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableDialogPanelAccessor; 41 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.TextMapping; 42 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.ValidationSupport; 43 44 48 public class KeyFieldEntryPanel extends JPanel implements GenericTableDialogPanelAccessor { 49 50 private static final ResourceBundle webappBundle = ResourceBundle.getBundle( 51 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.Bundle"); 53 private static final ResourceBundle commonBundle = ResourceBundle.getBundle( 54 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); 56 private static final TextMapping [] keyScopeTypes = ScopeMapping.getKeyScopeMappings(); 57 58 private static final int NAME_FIELD = 0; 60 private static final int SCOPE_FIELD = 1; 61 private static final int NUM_FIELDS = 2; 63 private String keyFieldName; 65 private String keyFieldScope; 66 67 private DefaultComboBoxModel keyFieldScopeModel; 69 70 71 public KeyFieldEntryPanel() { 72 initComponents(); 73 initUserComponents(); 74 } 75 76 81 private void initComponents() { 83 java.awt.GridBagConstraints gridBagConstraints; 84 85 jLblKeyFieldReq = new javax.swing.JLabel (); 86 jLblKeyFieldName = new javax.swing.JLabel (); 87 jTxtKeyFieldName = new javax.swing.JTextField (); 88 jLblFiller1 = new javax.swing.JLabel (); 89 jLblKeyScope = new javax.swing.JLabel (); 90 jCbxKeyScope = new javax.swing.JComboBox (); 91 92 setLayout(new java.awt.GridBagLayout ()); 93 94 jLblKeyFieldReq.setLabelFor(jTxtKeyFieldName); 95 jLblKeyFieldReq.setText(commonBundle.getString("LBL_RequiredMark")); 96 gridBagConstraints = new java.awt.GridBagConstraints (); 97 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 98 add(jLblKeyFieldReq, gridBagConstraints); 99 jLblKeyFieldReq.getAccessibleContext().setAccessibleName(commonBundle.getString("ACSN_RequiredMark")); 100 jLblKeyFieldReq.getAccessibleContext().setAccessibleDescription(commonBundle.getString("ACSD_RequiredMark")); 101 102 jLblKeyFieldName.setDisplayedMnemonic(webappBundle.getString("MNE_KeyFieldName").charAt(0)); 103 jLblKeyFieldName.setLabelFor(jTxtKeyFieldName); 104 jLblKeyFieldName.setText(webappBundle.getString("LBL_KeyFieldName_1")); 105 gridBagConstraints = new java.awt.GridBagConstraints (); 106 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 107 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 108 add(jLblKeyFieldName, gridBagConstraints); 109 110 jTxtKeyFieldName.addKeyListener(new java.awt.event.KeyAdapter () { 111 public void keyReleased(java.awt.event.KeyEvent evt) { 112 jTxtKeyFieldNameKeyReleased(evt); 113 } 114 }); 115 116 gridBagConstraints = new java.awt.GridBagConstraints (); 117 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 118 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 119 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 5); 120 add(jTxtKeyFieldName, gridBagConstraints); 121 jTxtKeyFieldName.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_KeyFieldName")); 122 jTxtKeyFieldName.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_KeyFieldName")); 123 124 jLblFiller1.setLabelFor(jCbxKeyScope); 125 gridBagConstraints = new java.awt.GridBagConstraints (); 126 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 127 add(jLblFiller1, gridBagConstraints); 128 129 jLblKeyScope.setDisplayedMnemonic(webappBundle.getString("MNE_KeyFieldScope").charAt(0)); 130 jLblKeyScope.setLabelFor(jCbxKeyScope); 131 jLblKeyScope.setText(webappBundle.getString("LBL_KeyFieldScope_1")); 132 gridBagConstraints = new java.awt.GridBagConstraints (); 133 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 134 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 0); 135 add(jLblKeyScope, gridBagConstraints); 136 137 jCbxKeyScope.addActionListener(new java.awt.event.ActionListener () { 138 public void actionPerformed(java.awt.event.ActionEvent evt) { 139 jCbxKeyScopeActionPerformed(evt); 140 } 141 }); 142 143 gridBagConstraints = new java.awt.GridBagConstraints (); 144 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 145 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 146 gridBagConstraints.weightx = 1.0; 147 gridBagConstraints.insets = new java.awt.Insets (6, 6, 5, 5); 148 add(jCbxKeyScope, gridBagConstraints); 149 jCbxKeyScope.getAccessibleContext().setAccessibleName(webappBundle.getString("ACSN_KeyFieldScope")); 150 jCbxKeyScope.getAccessibleContext().setAccessibleDescription(webappBundle.getString("ACSD_KeyFieldScope")); 151 152 } 154 private void jCbxKeyScopeActionPerformed(java.awt.event.ActionEvent evt) { TextMapping scope = (TextMapping) keyFieldScopeModel.getSelectedItem(); 156 keyFieldScope = scope.getXMLString(); 157 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 158 } 160 private void jTxtKeyFieldNameKeyReleased(java.awt.event.KeyEvent evt) { keyFieldName = jTxtKeyFieldName.getText(); 162 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 163 } 165 private javax.swing.JComboBox jCbxKeyScope; 167 private javax.swing.JLabel jLblFiller1; 168 private javax.swing.JLabel jLblKeyFieldName; 169 private javax.swing.JLabel jLblKeyFieldReq; 170 private javax.swing.JLabel jLblKeyScope; 171 private javax.swing.JTextField jTxtKeyFieldName; 172 174 private void initUserComponents() { 175 keyFieldScopeModel = new DefaultComboBoxModel (); 177 for(int i = 0; i < keyScopeTypes.length; i++) { 178 keyFieldScopeModel.addElement(keyScopeTypes[i]); 179 } 180 jCbxKeyScope.setModel(keyFieldScopeModel); 181 } 182 183 private TextMapping getScopeMapping(String xmlKey) { 184 TextMapping result = null; 185 if(xmlKey == null) { 186 xmlKey = ""; } 188 for(int i = 0; i < keyScopeTypes.length; i++) { 189 if(keyScopeTypes[i].getXMLString().compareTo(xmlKey) == 0) { 190 result = keyScopeTypes[i]; 191 break; 192 } 193 } 194 195 return result; 196 } 197 198 201 public void init(ASDDVersion asVersion, int preferredWidth, java.util.List entries, Object data) { 202 setPreferredSize(new Dimension (preferredWidth, getPreferredSize().height)); 203 } 204 205 public Object [] getValues() { 206 Object [] result = new Object [NUM_FIELDS]; 207 208 result[NAME_FIELD] = keyFieldName; 209 result[SCOPE_FIELD] = keyFieldScope; 210 211 return result; 212 } 213 214 public void setValues(Object [] values) { 215 if(values != null && values.length == NUM_FIELDS) { 216 keyFieldName = (String ) values[NAME_FIELD]; 217 keyFieldScope = (String ) values[SCOPE_FIELD]; 218 } else { 219 if(values != null) { 220 assert (values.length == NUM_FIELDS); } 222 223 keyFieldName = ""; keyFieldScope = ""; } 227 228 setComponentValues(); 229 } 230 231 private void setComponentValues() { 232 jTxtKeyFieldName.setText(keyFieldName); 233 keyFieldScopeModel.setSelectedItem(getScopeMapping(keyFieldScope)); 234 } 235 236 public Collection getErrors(ValidationSupport validationSupport) { 237 ArrayList errorList = new ArrayList (); 238 239 if(!Utils.notEmpty(keyFieldName)) { 240 Object [] args = new Object [1]; 241 args[0] = webappBundle.getString("LBL_KeyFieldName"); 242 errorList.add(MessageFormat.format(commonBundle.getString("ERR_SpecifiedFieldIsEmpty"), args)); 243 } else if(!Utils.isJavaIdentifier(keyFieldName)) { 244 Object [] args = new Object [1]; 245 args[0] = keyFieldName; 246 errorList.add(MessageFormat.format(commonBundle.getString("ERR_NotValidIdentifier"), args)); 247 } 248 249 return errorList; 250 } 251 252 public boolean requiredFieldsFilled() { 253 return (keyFieldName != null && keyFieldName.length() > 0); 254 } 255 } 256 | Popular Tags |