1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers; 26 27 import java.awt.BorderLayout ; 28 import java.awt.Dimension ; 29 import java.beans.PropertyChangeEvent ; 30 import java.beans.PropertyChangeListener ; 31 import java.text.MessageFormat ; 32 import java.util.ArrayList ; 33 import java.util.Collection ; 34 import java.util.ResourceBundle ; 35 import javax.swing.JPanel ; 36 37 import org.netbeans.modules.j2ee.sun.share.Constants; 38 import org.netbeans.modules.j2ee.sun.share.configbean.Utils; 39 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.HelpContext; 40 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.InputDialog; 41 42 46 public class SecurityEditGroupPanel extends JPanel { 47 48 private static final ResourceBundle customizerBundle = ResourceBundle.getBundle( 49 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.Bundle"); 51 private final GroupTableModel groupModel; 52 53 private final String originalGroupName; 54 private String groupName; 55 56 57 public SecurityEditGroupPanel(String entry, GroupTableModel gml) { 58 groupModel = gml; 59 originalGroupName = groupName = entry; 60 61 initComponents(); 62 initUserComponents(); 63 initFields(); 64 } 65 66 protected String getGroupName() { 67 return groupName; 68 } 69 70 protected String getOriginalGroupName() { 71 return originalGroupName; 72 } 73 74 79 private void initComponents() { 81 java.awt.GridBagConstraints gridBagConstraints; 82 83 jLblRequiredMark = new javax.swing.JLabel (); 84 jLblGroupName = new javax.swing.JLabel (); 85 jTxtGroupName = new javax.swing.JTextField (); 86 87 setLayout(new java.awt.GridBagLayout ()); 88 89 jLblRequiredMark.setLabelFor(jTxtGroupName); 90 jLblRequiredMark.setText("*"); 91 gridBagConstraints = new java.awt.GridBagConstraints (); 92 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 93 add(jLblRequiredMark, gridBagConstraints); 94 95 jLblGroupName.setLabelFor(jTxtGroupName); 96 jLblGroupName.setText(customizerBundle.getString("LBL_GroupName_1")); 97 gridBagConstraints = new java.awt.GridBagConstraints (); 98 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 99 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 0); 100 add(jLblGroupName, gridBagConstraints); 101 102 jTxtGroupName.addKeyListener(new java.awt.event.KeyAdapter () { 103 public void keyReleased(java.awt.event.KeyEvent evt) { 104 jTxtGroupNameKeyReleased(evt); 105 } 106 }); 107 108 gridBagConstraints = new java.awt.GridBagConstraints (); 109 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 110 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 111 gridBagConstraints.weightx = 1.0; 112 gridBagConstraints.insets = new java.awt.Insets (6, 6, 0, 11); 113 add(jTxtGroupName, gridBagConstraints); 114 jTxtGroupName.getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_GroupName")); 115 jTxtGroupName.getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_GroupName")); 116 117 } 119 private void jTxtGroupNameKeyReleased(java.awt.event.KeyEvent evt) { groupName = jTxtGroupName.getText(); 121 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 122 } 124 private javax.swing.JLabel jLblGroupName; 126 private javax.swing.JLabel jLblRequiredMark; 127 private javax.swing.JTextField jTxtGroupName; 128 130 private void initUserComponents() { 131 getAccessibleContext().setAccessibleName(customizerBundle.getString("ACSN_EditGroupName")); getAccessibleContext().setAccessibleDescription(customizerBundle.getString("ACSD_EditGroupName")); } 134 135 private void initFields() { 136 jTxtGroupName.setText(groupName); 137 } 138 139 Collection getErrors() { 140 ArrayList errors = new ArrayList (); 142 String newGroupName = getGroupName(); 143 144 146 if(!Utils.notEmpty(newGroupName)) { 147 errors.add(customizerBundle.getString("ERR_BlankGroupName")); } 149 150 154 if(newGroupName != null && !newGroupName.equals(getOriginalGroupName()) && 155 groupModel.contains(newGroupName)) { 156 errors.add(MessageFormat.format(customizerBundle.getString("ERR_GroupExists"), new Object [] { newGroupName })); } 158 159 return errors; 160 } 161 162 170 static void editGroupName(JPanel parent, String entry, GroupTableModel model) { 171 SecurityEditGroupPanel editGroupPanel = new SecurityEditGroupPanel(entry, model); 172 editGroupPanel.displayDialog(parent, customizerBundle.getString("TITLE_EditGroup"), HelpContext.HELP_SECURITY_EDIT_GROUP); 174 } 175 176 private void displayDialog(JPanel parent, String title, String helpId) { 177 BetterInputDialog dialog = new BetterInputDialog(parent, title, helpId, this); 178 179 do { 180 int dialogChoice = dialog.display(); 181 182 if(dialogChoice == dialog.CANCEL_OPTION) { 183 break; 184 } 185 186 if(dialogChoice == dialog.OK_OPTION) { 187 Collection errors = getErrors(); 188 189 String newGrouplName = getGroupName(); 190 String oldGroupName = getOriginalGroupName(); 191 192 if(dialog.hasErrors()) { 193 dialog.showErrors(); 195 } else { 196 if(!Utils.strEquals(newGrouplName, oldGroupName)) { 198 groupModel.replaceElement(oldGroupName, newGrouplName); 199 } 200 201 } 206 } 207 } while(dialog.hasErrors()); 208 } 209 210 private static class BetterInputDialog extends InputDialog { 211 private final SecurityEditGroupPanel dialogPanel; 212 private final String panelHelpId; 213 214 public BetterInputDialog(JPanel parent, String title, String helpId, SecurityEditGroupPanel childPanel) { 215 super(parent, title); 216 217 dialogPanel = childPanel; 218 panelHelpId = helpId; 219 220 dialogPanel.setPreferredSize(new Dimension (parent.getWidth()*3/4, 221 dialogPanel.getPreferredSize().height)); 222 223 this.getAccessibleContext().setAccessibleName(dialogPanel.getAccessibleContext().getAccessibleName()); 224 this.getAccessibleContext().setAccessibleDescription(dialogPanel.getAccessibleContext().getAccessibleDescription()); 225 226 getContentPane().add(childPanel, BorderLayout.CENTER); 227 addListeners(); 228 pack(); 229 setLocationInside(parent); 230 handleErrorDisplay(); 231 } 232 233 private void addListeners() { 234 dialogPanel.addPropertyChangeListener(Constants.USER_DATA_CHANGED, new PropertyChangeListener () { 235 public void propertyChange(PropertyChangeEvent evt) { 236 handleErrorDisplay(); 237 } 238 }); 239 } 240 241 private void handleErrorDisplay() { 242 ArrayList errors = new ArrayList (); 243 errors.addAll(dialogPanel.getErrors()); 244 setErrors(errors); 245 } 246 247 protected String getHelpId() { 248 return panelHelpId; 249 } 250 } 251 } 252 | Popular Tags |