Login.java :  » Database-ORM » tro-community-7.2-1 » discRack » presentation » Java Open Source

Java Open Source » Database ORM » tro community 7.2 1 
tro community 7.2 1 » discRack » presentation » Login.java
package discRack.presentation;

import discRack.presentation.delements.*;
import discRack.presentation.dpanels.*;
import discRack.business.person.PersonFactory;

import java.util.*;
import java.io.*;
import javax.swing.*;

/**
 * Used to manager Login.
 *
 * @author Sasa Bojanic
 * @version 1.0
 */
public class Login extends DComplexElement {
   private DSimpleElement refLogin=new DSimpleElement("Login");
   private DSimpleElement refPassword=new DSimpleElement("Password",false,true);

   public Login () {
      super("Please Login");

      fillStructure();
   }

   protected void fillStructure () {
      isRequired=true;
      refLogin.setRequired(true);
      refPassword.setRequired(true);
      complexStructure.add(refLogin);
      complexStructure.add(refPassword);
   }

   /**
     * This method is called only if user doesn't press Cancel button within
     * the dialog for editing properties, so the changes are applied here.
     * @param groupPanel The panel for editing parameters.
     * @return always returns <tt>true</tt>.
     */
    public boolean setDODSElements (DPanel p) {
       DGroupPanel dgp=(DGroupPanel)p;
       DTextPanel ltp=(DTextPanel)dgp.getPanel(0);
       DTextPanel ptp=(DTextPanel)dgp.getPanel(1);

       String login=ltp.getText();
       String password=ptp.getText();

       try {
          discRack.business.person.Person pers=PersonFactory.findPerson(login);
          if (pers==null) {
             JOptionPane.showMessageDialog(p.getWindow(),
                   "Please enter valid login","Login error",
                   JOptionPane.ERROR_MESSAGE);
             ltp.getComponent(2).requestFocus();
             return false;
          } else {
             if (!pers.getPassword().equals(password)) {
                JOptionPane.showMessageDialog(p.getWindow(),
                      "Password is not correct !","Login error",
                      JOptionPane.ERROR_MESSAGE);
                ptp.getComponent(2).requestFocus();
                return false;
             } else {
                return true;
             }
          }
       } catch (Exception ex) {
          JOptionPane.showMessageDialog(p.getWindow(),
                "Something went wrong, please try again !","Login error",
                JOptionPane.ERROR_MESSAGE);
          return false;
       }
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.