001: //package statement
002: package com.salmonllc.examples.example3;
003:
004: //The Salmon Open Framework for Internet Applications (SOFIA)
005: //Copyright (C) 1999 - 2002, Salmon LLC
006: //
007: //This program is free software; you can redistribute it and/or
008: //modify it under the terms of the GNU General Public License version 2
009: //as published by the Free Software Foundation;
010: //
011: //This program is distributed in the hope that it will be useful,
012: //but WITHOUT ANY WARRANTY; without even the implied warranty of
013: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: //GNU General Public License for more details.
015: //
016: //You should have received a copy of the GNU General Public License
017: //along with this program; if not, write to the Free Software
018: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: //
020: //For more information please visit http://www.salmonllc.com
021:
022: //Salmon import statements
023: import com.salmonllc.jsp.*;
024: import com.salmonllc.html.*;
025: import com.salmonllc.html.events.*;
026: import com.salmonllc.sql.*;
027:
028: public class InteractiveSQLController extends JspController implements
029: SubmitListener {
030:
031: public com.salmonllc.examples.example2.DBSelector _selector;
032: public com.salmonllc.html.HtmlSubmitButton _retrieve;
033: public com.salmonllc.html.HtmlText _heading2;
034: public com.salmonllc.html.HtmlText _heading3;
035: public com.salmonllc.html.HtmlText _heading;
036: public com.salmonllc.html.HtmlText _results;
037: public com.salmonllc.html.HtmlText _select1;
038: public com.salmonllc.html.HtmlText _text1;
039: public com.salmonllc.jsp.JspBox _box1;
040: public com.salmonllc.jsp.JspBox _box2;
041:
042: private com.salmonllc.html.HtmlDataTable _resultsTable;
043:
044: /**
045: * Initialize gets called the first time page is requested in a browser session.
046: */
047: public void initialize() {
048: //Make this page a listener for the retrieve button
049: _retrieve.addSubmitListener(this );
050:
051: //Dynamically create a datatable for the results
052: _resultsTable = new HtmlDataTable("results", null, this );
053:
054: //replace the place holder component on the page with the dynamically generated one
055: //The contents of the component will be filled in when the user clickes retrieve
056: replaceComponent(_results.getName(), _resultsTable);
057:
058: //make the results table invisible, it won't appear until the user clicks retrieve
059: //by setting the box to invisible, all the componenents in it become invisible also.
060: _box2.setVisible(false);
061: }
062:
063: /**
064: * This method will get execued when the user clicks the retrieve button
065: */
066: public boolean submitPerformed(SubmitEvent e) throws Exception {
067: //first get the columns selected by the user. This can be done by asking the selector component
068: ColumnDefinition def[] = _selector.getSelectedColumns();
069: if (def.length == 0) {
070: //This is an error condition, hide the result table and emphasize the instructions
071: _select1.setFont(HtmlText.FONT_ERROR);
072: _box2.setVisible(false);
073: return true;
074: }
075:
076: //Set the font for the select text back to normal since this ins't an error condition
077: _select1.setFont(HtmlText.FONT_DEFAULT);
078:
079: //remove all the components from the results table and create a new blank datastore
080: _resultsTable.removeAll();
081: DataStore model = new DataStore(getApplicationName());
082: _resultsTable.setDataStore(model);
083:
084: //Here is a loop that dymaically adds columns to the datastore model and to the datatable view
085: for (int i = 0; i < def.length; i++) {
086: //add a column to the model
087: model.addColumn(def[i].getTableName(), def[i]
088: .getColumnName(), def[i].getDSDataType());
089:
090: //add a title to the heading
091: HtmlText t1 = new HtmlText(def[i].getColumnName(),
092: HtmlText.FONT_TABLE_HEADING, this );
093: _resultsTable.setHeadingComponentAt(i, t1);
094:
095: //add a display column and bind it to the datatstore
096: HtmlText t2 = new HtmlText("", this );
097: t2.setExpression(model, def[i].getTableName() + "."
098: + def[i].getColumnName());
099: _resultsTable.setRowComponentAt(i, t2);
100: }
101:
102: //get the data from the database
103: model.retrieve();
104:
105: //set the datatable to visible and scroll to it
106: _box2.setVisible(true);
107: scrollToItem("scrollToMe");
108: return true;
109: }
110:
111: }
|