001: package discRack.presentation;
002:
003: import discRack.presentation.delements.*;
004: import discRack.presentation.dpanels.*;
005: import discRack.business.person.PersonFactory;
006: import org.enhydra.dods.exceptions.AssertionDataObjectException;
007:
008: import java.util.*;
009: import java.io.*;
010: import javax.swing.*;
011:
012: /**
013: * Used to manager Person DO data.
014: *
015: * @author Sasa Bojanic
016: * @version 1.0
017: */
018: public class Person extends DComplexElement {
019: private DSimpleElement refFirstname = new DSimpleElement(
020: "First Name");
021: private DSimpleElement refLastname = new DSimpleElement("Last Name");
022: private DSimpleElement refLogin = new DSimpleElement("Login Name");
023: private DSimpleElement refPassword = new DSimpleElement("Password",
024: false, true);
025: private DSimpleElement refREPassword = new DSimpleElement(
026: "Re-enter Password", false, true);
027:
028: public Person() {
029: super ("Please Register");
030:
031: fillStructure();
032: }
033:
034: protected void fillStructure() {
035: refFirstname.setRequired(true);
036: refLastname.setRequired(true);
037: refLogin.setRequired(true);
038: refPassword.setRequired(true);
039: complexStructure.add(refFirstname);
040: complexStructure.add(refLastname);
041: complexStructure.add(refLogin);
042: complexStructure.add(refPassword);
043: complexStructure.add(refREPassword);
044: }
045:
046: /**
047: * This method is called only if user doesn't press Cancel button within
048: * the dialog for editing properties, so the changes are applied here.
049: * @param groupPanel The panel for editing parameters.
050: * @return always returns <tt>true</tt>.
051: */
052: public boolean setDODSElements(DPanel p) {
053: DGroupPanel dgp = (DGroupPanel) p;
054: DTextPanel fntp = (DTextPanel) dgp.getPanel(0);
055: DTextPanel lntp = (DTextPanel) dgp.getPanel(1);
056: DTextPanel ltp = (DTextPanel) dgp.getPanel(2);
057: DTextPanel ptp = (DTextPanel) dgp.getPanel(3);
058: DTextPanel rptp = (DTextPanel) dgp.getPanel(4);
059:
060: String firstname = fntp.getText();
061: String lastname = lntp.getText();
062: String login = ltp.getText();
063: String password = ptp.getText();
064: String repassword = rptp.getText();
065:
066: // check if username is unique
067: try {
068: if (PersonFactory.findPerson(login) != null) {
069: JOptionPane
070: .showMessageDialog(
071: p.getWindow(),
072: "The username you've selected is not unique, please change it !",
073: "Registering error",
074: JOptionPane.ERROR_MESSAGE);
075: ltp.requestFocus();
076: return false;
077: }
078: } catch (Exception ex) {
079: JOptionPane.showMessageDialog(p.getWindow(),
080: "Something went wrong, please try again !",
081: "Registering error", JOptionPane.ERROR_MESSAGE);
082: return false;
083: }
084:
085: if (!password.equals(repassword)) {
086: JOptionPane
087: .showMessageDialog(
088: p.getWindow(),
089: "Re-entered password is not the same as password, please enter it again!",
090: "Registering error",
091: JOptionPane.ERROR_MESSAGE);
092: rptp.requestFocus();
093: return false;
094: }
095: try {
096: discRack.business.person.Person pers = new discRack.business.person.Person();
097: pers.setFirstname(firstname);
098: pers.setLastname(lastname);
099: pers.setLogin(login);
100: pers.setPassword(password);
101: pers.save();
102: return true;
103: } catch (AssertionDataObjectException ex) {
104: JOptionPane.showMessageDialog(p.getWindow(),
105: "Read-only cache: DML opertions not allowed.",
106: "Registering error", JOptionPane.ERROR_MESSAGE);
107: return false;
108: } catch (Exception ex) {
109: JOptionPane.showMessageDialog(p.getWindow(),
110: "Something went wrong, please try again !",
111: "Registering error", JOptionPane.ERROR_MESSAGE);
112: return false;
113: }
114: }
115: }
|