KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > swingclient > workflowadmin > user > UserAccount


1 package org.enhydra.shark.swingclient.workflowadmin.user;
2
3 import java.awt.*;
4 import java.awt.event.*;
5
6 import javax.swing.*;
7 import org.enhydra.shark.swingclient.workflowadmin.user.actions.*;
8 import org.enhydra.shark.swingclient.*;
9
10 /**
11  * Used to enter the data required to create or change
12  * settings of user account.
13  *
14  * @author Sasa Bojanic
15  * @version 1.0
16  */

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 JavaDoc {
38       super();
39       if (type!=CREATE_NEW && type!=CHANGE_PASSWORD && type!=CHANGE_SETTINGS) {
40          throw new Exception JavaDoc ("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
60       if (type==CREATE_NEW) {
61          p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
62          l=new JLabel(ResourceManager.getLanguageDependentString("GroupnameKey")+":");
63          groupname=new JTextField(userAccountSettings.groupname);
64          groupname.setMinimumSize(new Dimension(textFieldDimension));
65          groupname.setMaximumSize(new Dimension(textFieldDimension));
66          groupname.setPreferredSize(new Dimension(textFieldDimension));
67          if (type!=CREATE_NEW) {
68             groupname.setEnabled(false);
69          }
70          p.add(Box.createHorizontalGlue());
71          p.add(l);
72          p.add(groupname);
73          mp.add(p);
74          p = new JPanel();
75       }
76
77       p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
78       l=new JLabel(ResourceManager.getLanguageDependentString("UsernameKey")+":");
79       username=new JTextField(userAccountSettings.username);
80       username.setMinimumSize(new Dimension(textFieldDimension));
81       username.setMaximumSize(new Dimension(textFieldDimension));
82       username.setPreferredSize(new Dimension(textFieldDimension));
83       if (type!=CREATE_NEW) {
84          username.setEnabled(false);
85       }
86       p.add(Box.createHorizontalGlue());
87       p.add(l);
88       p.add(username);
89       mp.add(p);
90
91       if (type!=CHANGE_SETTINGS) {
92          p = new JPanel();
93          p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
94          l=new JLabel(ResourceManager.getLanguageDependentString("PasswordKey")+":");
95          password=new JPasswordField();
96          password.setMinimumSize(new Dimension(textFieldDimension));
97          password.setMaximumSize(new Dimension(textFieldDimension));
98          password.setPreferredSize(new Dimension(textFieldDimension));
99          p.add(Box.createHorizontalGlue());
100          p.add(l);
101          p.add(password);
102          mp.add(p);
103
104          p = new JPanel();
105          p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
106          l=new JLabel(ResourceManager.getLanguageDependentString("ConfirmPasswordKey")+":");
107          confirmPassword=new JPasswordField();
108          confirmPassword.setMinimumSize(new Dimension(textFieldDimension));
109          confirmPassword.setMaximumSize(new Dimension(textFieldDimension));
110          confirmPassword.setPreferredSize(new Dimension(textFieldDimension));
111          p.add(Box.createHorizontalGlue());
112          p.add(l);
113          p.add(confirmPassword);
114          mp.add(p);
115       }
116
117       p = new JPanel();
118       p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
119       l=new JLabel(ResourceManager.getLanguageDependentString("FirstNameKey")+":");
120       firstname=new JTextField(userAccountSettings.firstname);
121       firstname.setMinimumSize(new Dimension(textFieldDimension));
122       firstname.setMaximumSize(new Dimension(textFieldDimension));
123       firstname.setPreferredSize(new Dimension(textFieldDimension));
124       p.add(Box.createHorizontalGlue());
125       p.add(l);
126       p.add(firstname);
127       mp.add(p);
128
129       p = new JPanel();
130       p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
131       l=new JLabel(ResourceManager.getLanguageDependentString("LastNameKey")+":");
132       lastname=new JTextField(userAccountSettings.lastname);
133       lastname.setMinimumSize(new Dimension(textFieldDimension));
134       lastname.setMaximumSize(new Dimension(textFieldDimension));
135       lastname.setPreferredSize(new Dimension(textFieldDimension));
136       p.add(Box.createHorizontalGlue());
137       p.add(l);
138       p.add(lastname);
139       mp.add(p);
140
141       p = new JPanel();
142       p.setLayout(new BoxLayout(p,BoxLayout.X_AXIS));
143       l=new JLabel(ResourceManager.getLanguageDependentString("EmailAddressKey")+":");
144       email=new JTextField(userAccountSettings.email);
145       email.setMinimumSize(new Dimension(textFieldDimension));
146       email.setMaximumSize(new Dimension(textFieldDimension));
147       email.setPreferredSize(new Dimension(textFieldDimension));
148       p.add(Box.createHorizontalGlue());
149       p.add(l);
150       p.add(email);
151       mp.add(p);
152
153       if (type==CHANGE_PASSWORD) {
154          firstname.setEnabled(false);
155          lastname.setEnabled(false);
156          email.setEnabled(false);
157       }
158
159       return mp;
160    }
161
162    protected void cancelChanges () {
163       userAccountSettings.username=null;
164       myDialog.dispose();
165    }
166
167    protected void applyChanges () {
168       if (type!=CHANGE_SETTINGS) {
169          String JavaDoc pwd=new String JavaDoc(password.getPassword());
170          String JavaDoc cnfrmPwd=new String JavaDoc(confirmPassword.getPassword());
171          if (!pwd.equals(cnfrmPwd)) {
172             JOptionPane.showMessageDialog(this,
173                                           ResourceManager.getLanguageDependentString("ErrorPasswordsDoNotMatch"),
174                                           ResourceManager.getLanguageDependentString("DialogUserAccountSettings"),
175                                           JOptionPane.ERROR_MESSAGE);
176             return;
177          }
178          userAccountSettings.password=pwd;
179       }
180       if (groupname!=null) {
181          userAccountSettings.groupname=groupname.getText().trim();
182       }
183       userAccountSettings.username=username.getText().trim();
184       userAccountSettings.firstname=firstname.getText().trim();
185       userAccountSettings.lastname=lastname.getText().trim();
186       userAccountSettings.email=email.getText().trim();
187       myDialog.dispose();
188    }
189
190 }
191
192
Popular Tags