01: package auction.controller;
02:
03: import auction.dao.CategoryDAO;
04: import auction.dao.DAOFactory;
05: import auction.model.Category;
06: import auction.model.User;
07: import auction.persistence.HibernateUtil;
08: import java.awt.Component;
09: import java.util.Enumeration;
10: import java.util.Iterator;
11: import java.util.List;
12: import java.util.Set;
13: import java.util.Vector;
14: import javax.swing.JComboBox;
15: import javax.swing.tree.TreeNode;
16: import net.xoetrope.optional.annotation.Find;
17: import net.xoetrope.optional.data.pojo.*;
18: import net.xoetrope.swing.app.XDockableFrame;
19: import net.xoetrope.swing.tree.XTreeBinding;
20: import net.xoetrope.xui.*;
21: import net.xoetrope.swing.*;
22: import net.xoetrope.xui.data.XDataBinding;
23: import net.xoetrope.xui.data.XListBinding;
24: import net.xoetrope.xui.data.XModel;
25: import net.xoetrope.xui.exception.XExceptionHandler;
26: import org.hibernate.Session;
27: import org.hibernate.Transaction;
28:
29: /**
30: * A controller of the Welcome page.
31: */
32: public class Welcome extends CEPage {
33: @Find
34: private XLabel loginFailedLabel;
35:
36: public void pageCreated() {
37: Toolbar toolbar = (Toolbar) pageMgr.getTarget("Toolbar");
38: toolbar.setVisible(false);
39: }
40:
41: /**
42: * Tries to logon a user
43: */
44: public void logon() {
45: saveBoundComponentValues();
46: User user = (User) currentUserModel.get();
47: try {
48: pojoContext.beginWorkUnit(false);
49: user = userDAO.validateLogin(user);
50: pojoContext.endWorkUnit();
51: } catch (Exception ex) {
52: handleException(ex);
53: }
54:
55: if (user != null) {
56: loginFailedLabel.setVisible(false);
57: currentUserModel.set(user);
58: Toolbar toolbar = (Toolbar) pageMgr.getTarget("Toolbar");
59: toolbar.setVisible(true);
60: showSearchPage();
61: } else {
62: // clear the forms
63: ((XModel) currentUserModel.get("username")).set("");
64: ((XModel) currentUserModel.get("password")).set("");
65: loginFailedLabel.setVisible(true);
66: updateBoundComponentValues();
67: }
68: }
69:
70: /**
71: * Displays the search page, makes the user detail labels
72: * visible
73: */
74: private void showSearchPage() {
75: Toolbar toolbar = (Toolbar) pageMgr.getPage("Toolbar");
76:
77: XLabel userLabel = (XLabel) toolbar.findComponent("userLabel");
78: XLabel userNameLabel = (XLabel) toolbar.findComponent(toolbar,
79: "userNameLabel");
80: XButton logOffButton = (XButton) toolbar.findComponent(toolbar,
81: "logOffButton");
82:
83: userLabel.setVisible(true);
84: userNameLabel.setVisible(true);
85: logOffButton.setVisible(true);
86:
87: toolbar.showSearchPage();
88: }
89:
90: }
|