01: package jtaDiscRack.presentation;
02:
03: import jtaDiscRack.presentation.delements.*;
04: import jtaDiscRack.presentation.dpanels.*;
05: import jtaDiscRack.business.person.PersonFactory;
06:
07: import javax.swing.*;
08:
09: /**
10: * Used to manager Login.
11: *
12: * @author Sasa Bojanic
13: * @version 1.0
14: */
15: public class Login extends DComplexElement {
16: private DSimpleElement refLogin = new DSimpleElement("Login");
17: private DSimpleElement refPassword = new DSimpleElement("Password",
18: false, true);
19:
20: public Login() {
21: super ("Please Login");
22:
23: fillStructure();
24: }
25:
26: protected void fillStructure() {
27: isRequired = true;
28: refLogin.setRequired(true);
29: refPassword.setRequired(true);
30: complexStructure.add(refLogin);
31: complexStructure.add(refPassword);
32: }
33:
34: /**
35: * This method is called only if user doesn't press Cancel button within
36: * the dialog for editing properties, so the changes are applied here.
37: * @param groupPanel The panel for editing parameters.
38: * @return always returns <tt>true</tt>.
39: */
40: public boolean setDODSElements(DPanel p) {
41: DGroupPanel dgp = (DGroupPanel) p;
42: DTextPanel ltp = (DTextPanel) dgp.getPanel(0);
43: DTextPanel ptp = (DTextPanel) dgp.getPanel(1);
44:
45: String login = ltp.getText();
46: String password = ptp.getText();
47:
48: try {
49: jtaDiscRack.business.person.Person pers = PersonFactory
50: .findPerson(login);
51: if (pers == null) {
52: JOptionPane.showMessageDialog(p.getWindow(),
53: "Please enter valid login", "Login error",
54: JOptionPane.ERROR_MESSAGE);
55: ltp.getComponent(2).requestFocus();
56: return false;
57: } else {
58: if (!pers.getPassword().equals(password)) {
59: JOptionPane.showMessageDialog(p.getWindow(),
60: "Password is not correct !", "Login error",
61: JOptionPane.ERROR_MESSAGE);
62: ptp.getComponent(2).requestFocus();
63: return false;
64: } else {
65: return true;
66: }
67: }
68: } catch (Exception ex) {
69: JOptionPane.showMessageDialog(p.getWindow(),
70: "Something went wrong, please try again !",
71: "Login error", JOptionPane.ERROR_MESSAGE);
72: return false;
73: }
74: }
75:
76: }
|