KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > presentation > Person


1 package discRack.presentation;
2
3 import discRack.presentation.delements.*;
4 import discRack.presentation.dpanels.*;
5 import discRack.business.person.PersonFactory;
6 import org.enhydra.dods.exceptions.AssertionDataObjectException;
7
8 import java.util.*;
9 import java.io.*;
10 import javax.swing.*;
11
12 /**
13  * Used to manager Person DO data.
14  *
15  * @author Sasa Bojanic
16  * @version 1.0
17  */

18 public class Person extends DComplexElement {
19    private DSimpleElement refFirstname=new DSimpleElement("First Name");
20    private DSimpleElement refLastname=new DSimpleElement("Last Name");
21    private DSimpleElement refLogin=new DSimpleElement("Login Name");
22    private DSimpleElement refPassword=new DSimpleElement("Password",false,true);
23    private DSimpleElement refREPassword=new DSimpleElement("Re-enter Password",false,true);
24
25    public Person () {
26       super("Please Register");
27
28       fillStructure();
29    }
30
31    protected void fillStructure () {
32       refFirstname.setRequired(true);
33       refLastname.setRequired(true);
34       refLogin.setRequired(true);
35       refPassword.setRequired(true);
36       complexStructure.add(refFirstname);
37       complexStructure.add(refLastname);
38       complexStructure.add(refLogin);
39       complexStructure.add(refPassword);
40       complexStructure.add(refREPassword);
41    }
42
43    /**
44      * This method is called only if user doesn't press Cancel button within
45      * the dialog for editing properties, so the changes are applied here.
46      * @param groupPanel The panel for editing parameters.
47      * @return always returns <tt>true</tt>.
48      */

49     public boolean setDODSElements (DPanel p) {
50        DGroupPanel dgp=(DGroupPanel)p;
51        DTextPanel fntp=(DTextPanel)dgp.getPanel(0);
52        DTextPanel lntp=(DTextPanel)dgp.getPanel(1);
53        DTextPanel ltp=(DTextPanel)dgp.getPanel(2);
54        DTextPanel ptp=(DTextPanel)dgp.getPanel(3);
55        DTextPanel rptp=(DTextPanel)dgp.getPanel(4);
56
57        String JavaDoc firstname=fntp.getText();
58        String JavaDoc lastname=lntp.getText();
59        String JavaDoc login=ltp.getText();
60        String JavaDoc password=ptp.getText();
61        String JavaDoc repassword=rptp.getText();
62
63        // check if username is unique
64
try {
65           if(PersonFactory.findPerson(login)!=null) {
66              JOptionPane.showMessageDialog(p.getWindow(),
67                    "The username you've selected is not unique, please change it !",
68                    "Registering error",
69                    JOptionPane.ERROR_MESSAGE);
70              ltp.requestFocus();
71              return false;
72           }
73        } catch (Exception JavaDoc ex) {
74           JOptionPane.showMessageDialog(p.getWindow(),
75                 "Something went wrong, please try again !","Registering error",
76                 JOptionPane.ERROR_MESSAGE);
77           return false;
78        }
79
80        if (!password.equals(repassword)) {
81           JOptionPane.showMessageDialog(p.getWindow(),
82                 "Re-entered password is not the same as password, please enter it again!",
83                 "Registering error", JOptionPane.ERROR_MESSAGE);
84           rptp.requestFocus();
85           return false;
86        }
87        try {
88           discRack.business.person.Person pers=new discRack.business.person.Person();
89           pers.setFirstname(firstname);
90           pers.setLastname(lastname);
91           pers.setLogin(login);
92           pers.setPassword(password);
93           pers.save();
94           return true;
95        } catch (AssertionDataObjectException ex) {
96           JOptionPane.showMessageDialog(p.getWindow(),
97                 "Read-only cache: DML opertions not allowed.","Registering error",
98                 JOptionPane.ERROR_MESSAGE);
99           return false;
100        } catch (Exception JavaDoc ex) {
101           JOptionPane.showMessageDialog(p.getWindow(),
102                 "Something went wrong, please try again !","Registering error",
103                 JOptionPane.ERROR_MESSAGE);
104           return false;
105        }
106     }
107 }
108
Popular Tags