Source Code Cross Referenced for BookDetails.java in  » XML-UI » xui32 » auction » controller » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » XML UI » xui32 » auction.controller 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package auction.controller;
002:
003:        import auction.exceptions.BusinessException;
004:        import auction.model.Bid;
005:        import java.awt.Rectangle;
006:        import java.util.List;
007:        import javax.swing.JScrollBar;
008:        import javax.swing.ListSelectionModel;
009:        import net.xoetrope.optional.annotation.Find;
010:        import net.xoetrope.optional.data.pojo.XPersistentListHelper;
011:        import net.xoetrope.optional.data.pojo.XPojoModel;
012:        import net.xoetrope.xui.*;
013:        import net.xoetrope.swing.*;
014:
015:        import auction.dao.BookDAO;
016:        import auction.dao.CategoryDAO;
017:        import auction.dao.DAOFactory;
018:        import auction.dao.UserDAO;
019:        import auction.model.Category;
020:        import auction.model.Language;
021:        import auction.model.User;
022:        import auction.model.Book;
023:        import java.util.Collection;
024:        import java.util.Date;
025:        import net.xoetrope.optional.data.pojo.XPersistentDataBindingContext;
026:        import net.xoetrope.optional.data.pojo.XPojoHelper;
027:        import net.xoetrope.optional.data.pojo.XPersistentPojoModel;
028:        import net.xoetrope.xui.*;
029:        import net.xoetrope.swing.*;
030:        import net.xoetrope.xui.data.XListBinding;
031:        import net.xoetrope.xui.data.XModel;
032:
033:        /**
034:         * A controller of the book details page.
035:         */
036:        public class BookDetails extends CEPage {
037:            // DAOs
038:            private BookDAO bookDAO;
039:
040:            // UI components    
041:            @Find
042:            private XList categoryList;
043:            @Find
044:            private XList bidList;
045:            @Find
046:            private XLabel bidderLabel;
047:            @Find
048:            private XLabel bidAmountLabel;
049:            @Find
050:            private XLabel dateOfBidLabel;
051:            @Find
052:            private XImage bookCover;
053:            @Find
054:            private XLabel stateLabel;
055:
056:            // model nodes
057:            private XPersistentPojoModel selectedBookModel;;
058:            private XPersistentPojoModel maxBidModel;
059:            private XPersistentPojoModel newBidAmountModel;
060:
061:            // helpers
062:            private XPersistentListHelper bidListHelper;
063:            private XPersistentListHelper categoryListHelper;
064:
065:            public BookDetails() {
066:                super ();
067:            }
068:
069:            protected void init() {
070:                super .init();
071:                // get model nodes
072:                selectedBookModel = (XPersistentPojoModel) pojoHelper
073:                        .get("hibernateDAOFactory/bookDAO/selectedBook");
074:                maxBidModel = (XPersistentPojoModel) pojoHelper
075:                        .get("hibernateDAOFactory/bookDAO/maxBid");
076:                newBidAmountModel = (XPersistentPojoModel) pojoHelper
077:                        .get("hibernateDAOFactory/bookDAO/newBidAmount");
078:                // get DAOs
079:                bookDAO = factory.getBookDAO();
080:            }
081:
082:            public void pageCreated() {
083:                // create helpers
084:                bidListHelper = new XPersistentListHelper(bidList, this ,
085:                        "pojo/hibernateDAOFactory/bookDAO/selectedBid");
086:                categoryListHelper = new XPersistentListHelper(categoryList,
087:                        this );
088:                // set selection nodes
089:                bidList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
090:                categoryList
091:                        .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
092:            }
093:
094:            public void pageActivated() {
095:                // remove the selection from the category list.
096:                categoryList.clearSelection();
097:                categoryList.setFocusable(false);
098:                // update the cover of the selected book
099:                String imageName = (String) ((XModel) selectedBookModel
100:                        .get("image")).get();
101:                bookCover.setImageName(imageName);
102:                bookCover.setSize(bookCover.getPreferredSize()); //@todo tmp???
103:                bookCover.repaint();
104:            }
105:
106:            /**
107:             * Shows the "place new bid" dialog.
108:             */
109:            public void placeBid() {
110:                Book selectedBook = (Book) selectedBookModel.get();
111:
112:                if (selectedBook.isActive()) {
113:                    long newBidValue = 0;
114:                    Bid maxBid = (Bid) maxBidModel.get();
115:                    if (maxBid != null)
116:                        newBidValue = (maxBid.getAmount() + 1);
117:                    else
118:                        newBidValue = (Long) ((XModel) selectedBookModel
119:                                .get("initialPrice")).get();
120:
121:                    // store the value into the model node
122:                    newBidAmountModel.set(String.valueOf(newBidValue));
123:                    showPlaceBidDialog(NewBid.PLACE_BID);
124:                } else {
125:                    showMessageDialog("Selected auction is not active");
126:                }
127:            }
128:
129:            /**
130:             * Shows the "buy it now dialog"
131:             */
132:            public void buyItNow() {
133:                Book selectedBook = (Book) selectedBookModel.get();
134:
135:                if (selectedBook.isActive()) {
136:                    Long reservePrice = selectedBook.getReservePrice();
137:                    newBidAmountModel.set(String.valueOf(reservePrice));
138:                    showPlaceBidDialog(NewBid.BUY_IT_NOW);
139:                } else {
140:                    showMessageDialog("Selected auction is not active");
141:                }
142:            }
143:
144:            /**
145:             * Gets the value of the new bid stored in the
146:             * "newBidAmountModel" node
147:             * @return the value of the new bid
148:             */
149:            private Long getNewBidAmount() {
150:                Long newBidAmount = null;
151:                String newBidAmountS = (String) newBidAmountModel.get();
152:                try {
153:                    newBidAmount = Long.parseLong(newBidAmountS);
154:                } catch (RuntimeException ex) {
155:                    newBidAmount = null;
156:                }
157:                return newBidAmount;
158:            }
159:
160:            /**
161:             * Displays the dialog for placing a new bid.
162:             * @param the type of dialog, either "place a new bid" or
163:             * "buy it now"
164:             */
165:            private void showPlaceBidDialog(int type) {
166:                String msg = null;
167:
168:                // set the dialog caption
169:                String caption = "";
170:                if (type == NewBid.BUY_IT_NOW)
171:                    caption = "Buy it now";
172:                else if (type == NewBid.PLACE_BID)
173:                    caption = "Place a new bid";
174:
175:                if (showDialog("NewBid", caption) == XDialog.OK_CLICKED) {
176:                    // get and validate the value of the new bid
177:                    Long newBidAmount = getNewBidAmount();
178:                    if (newBidAmount == null) {
179:                        showMessageDialog("wrong value of the new bid");
180:                        return;
181:                    }
182:
183:                    try {
184:                        // explicitly start a new db transaction
185:                        // in order to place a new bid
186:                        pojoContext.beginWorkUnit(false);
187:
188:                        selectedBookModel.merge();
189:                        Book selectedBook = (Book) selectedBookModel.get();
190:                        Bid maxBid = (Bid) maxBidModel.get();
191:                        try {
192:                            Bid newBid = selectedBook.placeBid(
193:                                    getCurrentUser(), newBidAmount.longValue(),
194:                                    maxBid);
195:                            if (newBid.isSuccessful()) {
196:                                updateBinding(getBinding(stateLabel));
197:                                msg = "Congratulations, you have won the auction!";
198:                            }
199:                        } catch (BusinessException ex) {
200:                            msg = ex.getMessage();
201:                        }
202:
203:                        // get the max bid from the db to update the UI with it
204:                        maxBid = bookDAO.getMaxBid(selectedBook.getId());
205:                        if (maxBid == null)
206:                            maxBid = new Bid();
207:                        maxBidModel.set(maxBid);
208:
209:                        // update the UI
210:                        bidListHelper.updateListHolder();
211:                        updateBoundComponentValues();
212:                        // select the first bid on the list of bids
213:                        bidList.setSelectedIndex(0);
214:
215:                        pojoContext.endWorkUnit();
216:                    } catch (Exception ex) {
217:                        handleException(ex);
218:                    }
219:                }
220:                // check if there's anything to show in the message dialog
221:                if (msg != null)
222:                    showMessageDialog(msg);
223:            }
224:
225:            /**
226:             * Invoked whenever the selection on the
227:             * list of bids is changed
228:             */
229:            public void bidSelectionChanged() {
230:                if (bidListHelper.selectionChanged()) {
231:                    // update bid related components
232:                    updateBinding(getBinding(bidderLabel));
233:                    updateBinding(getBinding(bidAmountLabel));
234:                    updateBinding(getBinding(dateOfBidLabel));
235:                }
236:            }
237:
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.