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