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