001: package com.xoetrope.carousel.catalog.templates.javaclasses;
002:
003: import net.xoetrope.xui.XPage;
004: import net.xoetrope.swing.XDialog; //BEGIN_BLOCK_IMPORTS
005: import com.xoetrope.carousel.build.BuildProperties;
006: import net.xoetrope.swing.XLabel;
007: import net.xoetrope.swing.XTextArea;
008: import net.xoetrope.xui.data.XBaseModel;
009: import net.xoetrope.xui.data.XModel;
010:
011: //END_BLOCK_IMPORTS
012:
013: public class Checkout extends XPage {
014: //BEGIN_BLOCK_VARS
015: protected XTextArea tabArea, descriptionArea;
016: protected XLabel totalPrice;
017:
018: //END_BLOCK_VARS
019:
020: public Checkout() {
021: }
022:
023: public void pageActivated() {
024: //BEGIN_BLOCK_VARS
025: descriptionArea = (XTextArea) findComponent("descriptionArea");
026: tabArea = (XTextArea) findComponent("tabLabel");
027: tabArea.setText("Product\t\t\t" + "Quantity\t\t\t"
028: + "Price\n\n");
029: totalPrice = (XLabel) findComponent("totalPrice");
030:
031: XModel cart = (XModel) rootModel.get("productsCart");
032: double total = 0;
033:
034: descriptionArea.setText("");
035:
036: if (cart.getNumChildren() > 1) {
037: for (int i = 1; i < cart.getNumChildren(); i++) {
038: XBaseModel header = (XBaseModel) cart.get(i);
039:
040: XBaseModel title = (XBaseModel) header.get(0);
041: XBaseModel qty = (XBaseModel) header.get(1);
042: XBaseModel price = (XBaseModel) header.get(2);
043:
044: String info = null;
045: if (((String) title.getAttribValue(0)).length() > 25) {
046: info = title.getAttribValue(0) + "\t "
047: + qty.getAttribValue(0) + "\t\t\t"
048: + price.getAttribValue(0) + "\n";
049: } else if (((String) title.getAttribValue(0)).length() > 10) {
050: info = title.getAttribValue(0) + "\t\t "
051: + qty.getAttribValue(0) + "\t\t\t"
052: + price.getAttribValue(0) + "\n";
053: } else {
054: info = title.getAttribValue(0) + "\t\t\t "
055: + qty.getAttribValue(0) + "\t\t\t"
056: + price.getAttribValue(0) + "\n";
057: }
058: //BEGIN_BLOCK_PRICES
059: String p = ((String) price.getAttribValue(0))
060: .substring(1);
061: total = total + Double.parseDouble(p);
062: //END_BLOCK_PRICES
063: descriptionArea.setText(descriptionArea.getText()
064: + info);
065: }
066: //BEGIN_BLOCK_PRICES
067: String result = "$" + Double.toString(total);
068: result = result.substring(0, result.indexOf(".") + 3);
069: totalPrice.setText(result);
070: //END_BLOCK_PRICES
071: }
072: //END_BLOCK_VARS
073: }
074:
075: //BEGIN_BLOCK_PREVIOUS
076: public void openCatalog() {
077: pageMgr.showPage("Products");
078: }
079:
080: //END_BLOCK_PREVIOUS
081: //BEGIN_BLOCK_HOME
082: public void openWelcome() {
083: pageMgr.showPage("Welcome");
084: }
085:
086: //END_BLOCK_HOME
087: //BEGIN_BLOCK_ABOUT
088: public void openAbout() {
089: XDialog dlg = (XDialog) pageMgr.loadPage("About");
090: dlg.pack();
091: dlg.showDialog(this );
092: }
093:
094: //END_BLOCK_ABOUT
095: //BEGIN_BLOCK_CLOSE
096: public void submitOrder() {
097: XDialog dlg = (XDialog) pageMgr.loadPage("Submit");
098: dlg.pack();
099: dlg.showDialog(this );
100: //BEGIN_BLOCK_VARS
101: descriptionArea.setText("");
102: //END_BLOCK_VARS
103: }
104:
105: //END_BLOCK_CLOSE
106: public void closeCatalog() {
107: System.exit(0);
108: }
109: }
|