1 package org.enhydra.shark.corbaclient.workflowadmin.user; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 6 import javax.swing.*; 7 import org.enhydra.shark.corbaclient.workflowadmin.user.actions.*; 8 import org.enhydra.shark.corbaclient.*; 9 10 17 public class UserAccount extends ActionPanel { 18 19 public static int CREATE_NEW=0; 20 public static int CHANGE_PASSWORD=1; 21 public static int CHANGE_SETTINGS=2; 22 23 private static Dimension textFieldDimension=new Dimension(200,20); 24 25 private JTextField groupname; 26 private JTextField username; 27 private JPasswordField password; 28 private JPasswordField confirmPassword; 29 private JTextField firstname; 30 private JTextField lastname; 31 private JTextField email; 32 33 private UserAccountSettings userAccountSettings; 34 35 private int type; 36 37 public UserAccount (JFrame parent,UserAccountSettings uas,int type) throws Exception { 38 super(); 39 if (type!=CREATE_NEW && type!=CHANGE_PASSWORD && type!=CHANGE_SETTINGS) { 40 throw new Exception ("The dialog type is not allowed"); 41 } 42 43 this.userAccountSettings=uas; 44 this.type=type; 45 super.init(); 46 super.initDialog(parent,ResourceManager.getLanguageDependentString("DialogUserAccountSettings"), 47 true,true); 48 } 49 50 protected void createActions () {} 51 52 protected Component createCenterComponent(){ 53 JPanel mp=new JPanel(); 54 mp.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 55 mp.setLayout(new BoxLayout(mp,BoxLayout.Y_AXIS)); 56 57 JPanel p = new JPanel(); 58 JLabel l; 59 if (type==CREATE_NEW) { 60 p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); 61 l=new JLabel(ResourceManager.getLanguageDependentString("GroupnameKey")+":"); 62 groupname=new JTextField(userAccountSettings.groupname); 63 groupname.setMinimumSize(new Dimension(textFieldDimension)); 64 groupname.setMaximumSize(new Dimension(textFieldDimension)); 65 groupname.setPreferredSize(new Dimension(textFieldDimension)); 66 if (type!=CREATE_NEW) { 67 groupname.setEnabled(false); 68 } 69 p.add(Box.createHorizontalGlue()); 70 p.add(l); 71 p.add(groupname); 72 mp.add(p); 73 p = new JPanel(); 74 } 75 76 p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); 77 l=new JLabel(ResourceManager.getLanguageDependentString("UsernameKey")+":"); 78 username=new JTextField(userAccountSettings.username); 79 username.setMinimumSize(new Dimension(textFieldDimension)); 80 username.setMaximumSize(new Dimension(textFieldDimension)); 81 username.setPreferredSize(new Dimension(textFieldDimension)); 82 if (type!=CREATE_NEW) { 83 username.setEnabled(false); 84 } 85 p.add(Box.createHorizontalGlue()); 86 p.add(l); 87 p.add(username); 88 mp.add(p); 89 90 if (type!=CHANGE_SETTINGS) { 91 p = new JPanel(); 92 p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); 93 l=new JLabel(ResourceManager.getLanguageDependentString("PasswordKey")+":"); 94 password=new JPasswordField(); 95 password.setMinimumSize(new Dimension(textFieldDimension)); 96 password.setMaximumSize(new Dimension(textFieldDimension)); 97 password.setPreferredSize(new Dimension(textFieldDimension)); 98 p.add(Box.createHorizontalGlue()); 99 p.add(l); 100 p.add(password); 101 mp.add(p); 102 103 p = new JPanel(); 104 p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); 105 l=new JLabel(ResourceManager.getLanguageDependentString("ConfirmPasswordKey")+":"); 106 confirmPassword=new JPasswordField(); 107 confirmPassword.setMinimumSize(new Dimension(textFieldDimension)); 108 confirmPassword.setMaximumSize(new Dimension(textFieldDimension)); 109 confirmPassword.setPreferredSize(new Dimension(textFieldDimension)); 110 p.add(Box.createHorizontalGlue()); 111 p.add(l); 112 p.add(confirmPassword); 113 mp.add(p); 114 } 115 116 p = new JPanel(); 117 p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); 118 l=new JLabel(ResourceManager.getLanguageDependentString("FirstNameKey")+":"); 119 firstname=new JTextField(userAccountSettings.firstname); 120 firstname.setMinimumSize(new Dimension(textFieldDimension)); 121 firstname.setMaximumSize(new Dimension(textFieldDimension)); 122 firstname.setPreferredSize(new Dimension(textFieldDimension)); 123 p.add(Box.createHorizontalGlue()); 124 p.add(l); 125 p.add(firstname); 126 mp.add(p); 127 128 p = new JPanel(); 129 p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); 130 l=new JLabel(ResourceManager.getLanguageDependentString("LastNameKey")+":"); 131 lastname=new JTextField(userAccountSettings.lastname); 132 lastname.setMinimumSize(new Dimension(textFieldDimension)); 133 lastname.setMaximumSize(new Dimension(textFieldDimension)); 134 lastname.setPreferredSize(new Dimension(textFieldDimension)); 135 p.add(Box.createHorizontalGlue()); 136 p.add(l); 137 p.add(lastname); 138 mp.add(p); 139 140 p = new JPanel(); 141 p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS)); 142 l=new JLabel(ResourceManager.getLanguageDependentString("EmailAddressKey")+":"); 143 email=new JTextField(userAccountSettings.email); 144 email.setMinimumSize(new Dimension(textFieldDimension)); 145 email.setMaximumSize(new Dimension(textFieldDimension)); 146 email.setPreferredSize(new Dimension(textFieldDimension)); 147 p.add(Box.createHorizontalGlue()); 148 p.add(l); 149 p.add(email); 150 mp.add(p); 151 152 if (type==CHANGE_PASSWORD) { 153 firstname.setEnabled(false); 154 lastname.setEnabled(false); 155 email.setEnabled(false); 156 } 157 158 return mp; 159 } 160 161 protected void cancelChanges () { 162 userAccountSettings.username=null; 163 myDialog.dispose(); 164 } 165 166 protected void applyChanges () { 167 if (type!=CHANGE_SETTINGS) { 168 String pwd=new String (password.getPassword()); 169 String cnfrmPwd=new String (confirmPassword.getPassword()); 170 if (!pwd.equals(cnfrmPwd)) { 171 JOptionPane.showMessageDialog(this, 172 ResourceManager.getLanguageDependentString("ErrorPasswordsDoNotMatch"), 173 ResourceManager.getLanguageDependentString("DialogUserAccountSettings"), 174 JOptionPane.ERROR_MESSAGE); 175 return; 176 } 177 userAccountSettings.password=pwd; 178 } 179 if (groupname!=null) { 180 userAccountSettings.groupname=groupname.getText().trim(); 181 } 182 userAccountSettings.username=username.getText().trim(); 183 userAccountSettings.firstname=firstname.getText().trim(); 184 userAccountSettings.lastname=lastname.getText().trim(); 185 userAccountSettings.email=email.getText().trim(); 186 myDialog.dispose(); 187 } 188 189 } 190 191 | Popular Tags |