001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.forms;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/forms/BaseForm.java $
024: //$Author: Srufle $
025: //$Revision: 18 $
026: //$Modtime: 4/15/03 2:24p $
027: /////////////////////////
028:
029: import com.salmonllc.html.*;
030: import com.salmonllc.html.events.PageEvent;
031: import com.salmonllc.html.events.PageListener;
032: import com.salmonllc.sql.DataStore;
033:
034: /**
035: * Base class for forms.
036: */
037: public class BaseForm extends HtmlContainer implements PageListener {
038: protected HtmlLineBreak _line_break;
039: protected DataStore _ds;
040:
041: /**
042: * Constructor.
043: * @param name String Component name for this form
044: * @param page HtmlPage Page containing this form
045: * @param ds DataStore Data store object to use, if null then create one.
046: */
047: public BaseForm(String name, HtmlPage page, DataStore ds) {
048: super (name, page);
049: _line_break = new HtmlLineBreak(page);
050: if (ds == null)
051: _ds = new DataStore(page.getApplicationName());
052: else
053: _ds = ds;
054: page.addPageListener(this );
055: }
056:
057: /**
058: * Creates an integer-type drop-down list like HtmlComponenFactory but tailored
059: * to needs of the forms subclasses.
060: * @return com.salmonllc.html.HtmlDropDownList
061: * @param name java.lang.String
062: * @param values int[]
063: * @param displayValues java.lang.String[]
064: */
065: public HtmlDropDownList newIntegerDropDown(String name,
066: int values[], String displayValues[]) {
067: HtmlDropDownList ddl = new HtmlDropDownList(name, getPage());
068: ddl.addOption(null, "");
069: String displayValue = null;
070: for (int i = 0; i < values.length; i++) {
071: if (i < displayValues.length)
072: displayValue = displayValues[i];
073: else
074: displayValue = "Value " + i;
075: ddl.addOption(new Integer(values[i]).toString(),
076: displayValue);
077: }
078: return ddl;
079: }
080:
081: public void pageRequested(PageEvent p) throws Exception {
082: }
083:
084: public void pageRequestEnd(PageEvent p) throws Exception {
085: }
086:
087: public void pageSubmitEnd(PageEvent p) {
088: }
089:
090: public void pageSubmitted(PageEvent p) {
091: }
092:
093: /**
094: * Creates an integer-type drop-down list like HtmlComponenFactory but tailored
095: * to needs of the forms subclasses.
096: * @return com.salmonllc.html.HtmlDropDownList
097: * @param name java.lang.String
098: * @param values int[]
099: * @param displayValues java.lang.String[]
100: */
101: public HtmlDropDownList newStringDropDown(String name,
102: String values[], String displayValues[]) {
103: HtmlDropDownList ddl = new HtmlDropDownList(name, getPage());
104: ddl.addOption(null, "");
105: String displayValue = null;
106: for (int i = 0; i < values.length; i++) {
107: if (i < displayValues.length)
108: displayValue = displayValues[i];
109: else
110: displayValue = "Value " + i;
111: ddl.addOption(values[i], displayValue);
112: }
113: return ddl;
114: }
115: }
|