001: package com.salmonllc.examples.example5;
002:
003: //The Salmon Open Framework for Internet Applications (SOFIA)
004: //Copyright (C) 1999 - 2002, Salmon LLC
005: //
006: //This program is free software; you can redistribute it and/or
007: //modify it under the terms of the GNU General Public License version 2
008: //as published by the Free Software Foundation;
009: //
010: //This program is distributed in the hope that it will be useful,
011: //but WITHOUT ANY WARRANTY; without even the implied warranty of
012: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: //GNU General Public License for more details.
014: //
015: //You should have received a copy of the GNU General Public License
016: //along with this program; if not, write to the Free Software
017: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: //
019: //For more information please visit http://www.salmonllc.com
020:
021: import com.salmonllc.html.HtmlText;
022: import com.salmonllc.html.events.PageEvent;
023: import com.salmonllc.html.events.PageListener;
024: import com.salmonllc.html.treeControl.TreeBuffer;
025: import com.salmonllc.jsp.JspController;
026: import com.salmonllc.properties.Props;
027: import com.salmonllc.util.MessageLog;
028:
029: public class TreeController extends JspController implements
030: PageListener {
031:
032: public com.salmonllc.html.HtmlText _returnToHomePageText;
033: public com.salmonllc.html.HtmlText _sourceList;
034: public com.salmonllc.html.HtmlTreeControl _tree1;
035: public com.salmonllc.html.HtmlCheckBox _showGridLines;
036: public com.salmonllc.html.HtmlCheckBox _showPrice;
037: private ProductCategoryModel _mod;
038: private boolean _priceShowing = false;
039:
040: public static final String ALIGN_RIGHT = "RIGHT";
041: public static final String ALIGN_LEFT = "LEFT";
042:
043: public void initialize() throws Exception {
044: addPageListener(this );
045:
046: //Populate the tree and get the internal buffer
047: _mod = new ProductCategoryModel(getApplicationName());
048: _mod.populateTree(_tree1);
049:
050: }
051:
052: public void pageRequested(PageEvent p) throws Exception {
053:
054: }
055:
056: public void pageRequestEnd(PageEvent p) throws Exception {
057: }
058:
059: public void pageSubmitEnd(PageEvent p) {
060: //check the value of the check box.
061: //Depending on what it is change the theme for the tree to show or hide the border.
062: String value = _showGridLines.getValue();
063: String theme = _tree1.getTheme();
064: if (theme != null && value.equals("0"))
065: _tree1.setTheme(null);
066: else if (theme == null && value.equals("1"))
067: _tree1.setTheme("BorderBox");
068:
069: value = _showPrice.getValue();
070:
071: if (value.equals("0"))
072: removeTreeComponents();
073: else {
074: try {
075: addTreeComponents();
076: } catch (Exception ex) {
077: MessageLog.writeErrorMessage(
078: "Error adding tree components", ex, this );
079: }
080: }
081: }
082:
083: public void pageSubmitted(PageEvent p) {
084:
085: }
086:
087: /**
088: * Remove the headers and extra columns from the tree
089: */
090: private void removeTreeComponents() {
091: if (!_priceShowing)
092: return;
093: _priceShowing = false;
094: TreeBuffer tb = _tree1.getTreeBuffer();
095: tb.resetHeaders();
096: tb.resetNodeComponents();
097: }
098:
099: /**
100: * Add headers and extra columns to the tree
101: * @throws Exception
102: */
103: private void addTreeComponents() throws Exception {
104: if (_priceShowing)
105: return;
106:
107: _priceShowing = true;
108: TreeBuffer tb = _tree1.getTreeBuffer();
109:
110: //add some headings to the tree
111: tb.addHeaderComponent(new HtmlText("Product Category/Name",
112: HtmlText.FONT_TABLE_HEADING, this ), ALIGN_LEFT, "50%");
113: tb.addHeaderComponent(new HtmlText("Price",
114: HtmlText.FONT_TABLE_HEADING, this ), ALIGN_RIGHT, "10%");
115: tb.addHeaderComponent(new HtmlText("Quantity",
116: HtmlText.FONT_TABLE_HEADING, this ), ALIGN_RIGHT, "10%");
117:
118: //add some components for the price and quantity
119: HtmlText t = new HtmlText("", Props.TREE_NODE_FONT, this );
120: t.setExpression(_mod,
121: ProductCategoryModel.PRODUCT_CATEGORY_PRICE,
122: "$###,###.99");
123: tb.addNodeComponent(t);
124:
125: t = new HtmlText("", Props.TREE_NODE_FONT, this);
126: t.setExpression(_mod,
127: ProductCategoryModel.PRODUCT_CATEGORY_QUANTITY);
128: tb.addNodeComponent(t);
129:
130: }
131:
132: }
|