KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > presentation > Login


1 package discRack.presentation;
2
3 import discRack.presentation.delements.*;
4 import discRack.presentation.dpanels.*;
5 import discRack.business.person.PersonFactory;
6
7 import java.util.*;
8 import java.io.*;
9 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",false,true);
20
21    public Login () {
22       super("Please Login");
23
24       fillStructure();
25    }
26
27    protected void fillStructure () {
28       isRequired=true;
29       refLogin.setRequired(true);
30       refPassword.setRequired(true);
31       complexStructure.add(refLogin);
32       complexStructure.add(refPassword);
33    }
34
35    /**
36      * This method is called only if user doesn't press Cancel button within
37      * the dialog for editing properties, so the changes are applied here.
38      * @param groupPanel The panel for editing parameters.
39      * @return always returns <tt>true</tt>.
40      */

41     public boolean setDODSElements (DPanel p) {
42        DGroupPanel dgp=(DGroupPanel)p;
43        DTextPanel ltp=(DTextPanel)dgp.getPanel(0);
44        DTextPanel ptp=(DTextPanel)dgp.getPanel(1);
45
46        String JavaDoc login=ltp.getText();
47        String JavaDoc password=ptp.getText();
48
49        try {
50           discRack.business.person.Person pers=PersonFactory.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 JavaDoc ex) {
69           JOptionPane.showMessageDialog(p.getWindow(),
70                 "Something went wrong, please try again !","Login error",
71                 JOptionPane.ERROR_MESSAGE);
72           return false;
73        }
74     }
75
76 }
77
Popular Tags