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.jsp;
021:
022: /////////////////////////
023: //$Archive: /sofia/sourcecode/com/salmonllc/jsp/JspRowSelector.java $
024: //$Author: Deepak $
025: //$Revision: 9 $
026: //$Modtime: 7/06/04 2:39p $
027: /////////////////////////
028:
029: import com.salmonllc.html.HtmlFormComponent;
030: import com.salmonllc.html.HtmlPage;
031: import com.salmonllc.html.events.ValueChangedEvent;
032: import com.salmonllc.properties.Props;
033:
034: /**
035: * This type can be used to add a row selector to an html table.
036: */
037: public class JspRowSelector extends HtmlFormComponent {
038: private String _unSelectedValue = "0";
039: private String _onClick;
040:
041: private String _imageOn;
042: private String _imageOff;
043:
044: /**
045: * Constructs a Html row selector object for an HtmlDataTable
046: */
047: public JspRowSelector(String name, HtmlPage p) {
048: super (name, p);
049: }
050:
051: public boolean executeEvent(int eventType) throws Exception {
052: if (_events != null)
053: if (_events.size() > 0 && _dsBuff != null)
054: for (int i = 0; i < _dsBuff.getRowCount(); i++)
055: _dsBuff.setAny(i, _dsColNo, _unSelectedValue);
056:
057: return super .executeEvent(eventType);
058: }
059:
060: public void generateHTML(java.io.PrintWriter p, int rowNo)
061: throws Exception {
062: if (!_visible)
063: return;
064:
065: boolean checked = false;
066: _value = getValue(rowNo);
067:
068: if (_value != null && (!_value.trim().equals(""))) {
069: if (_value.equals("" + rowNo))
070: checked = true;
071: } else
072: _value = "";
073:
074: String tag = "<INPUT TYPE=\"RADIO\" NAME=\"" + getName()
075: + "\" VALUE=\"" + rowNo + "\"";
076:
077: if (!_enabled) {
078: if (useDisabledAttribute()) {
079: tag += " disabled=\"" + true + "\"";
080: } else if (_imageOn != null && _imageOff != null) {
081: String out = "<IMG SRC=\"";
082: if (checked)
083: out += _imageOn;
084: else
085: out += _imageOff;
086: out += "\">";
087:
088: p.print(out);
089: return;
090: }
091: }
092:
093: if (_onClick != null && !_onClick.trim().equals(""))
094: tag += " ONCLICK=\"" + _onClick + "\"";
095:
096: if (checked)
097: tag += " CHECKED";
098:
099: tag += ">";
100:
101: p.println(tag);
102:
103: }
104:
105: /**
106: * This method gets the javascript to be executed when the component gets clicked.
107: */
108: public String getOnClick() {
109: return _onClick;
110: }
111:
112: public boolean processParms(java.util.Hashtable parms, int row)
113: throws Exception {
114: Object oldValue = _value;
115:
116: if (row > -1) {
117: if (_dsBuff != null)
118: oldValue = _dsBuff.getAny(row, _dsColNo);
119: } else {
120: if (_dsBuff != null)
121: oldValue = _dsBuff.getAny(_dsColNo);
122: }
123:
124: String val[] = (String[]) parms.get(getName());
125:
126: int selectedRow = -1;
127: if (val != null)
128: selectedRow = Integer.parseInt(val[0]);
129:
130: if (selectedRow == row)
131: _value = "" + selectedRow;
132:
133: if (!valuesEqual(oldValue, _value)
134: && _value.equals("" + selectedRow)) {
135: String s = null;
136: if (oldValue != null)
137: s = oldValue.toString();
138: ValueChangedEvent e = new ValueChangedEvent(getPage(),
139: this , getName(), getFullName(), s, _value, row,
140: _dsColNo, _dsBuff);
141: addEvent(e);
142: }
143:
144: return false;
145: }
146:
147: /**
148: * This method sets the javascript to be executed when the component is checked.
149: */
150: public void setOnClick(String value) {
151: _onClick = value;
152: }
153:
154: /**
155: * This method sets the row in the datastore that is selected
156: */
157: public void setSelectedRow(int rowNo) {
158: setValue("" + rowNo, rowNo);
159:
160: }
161:
162: public void setTheme(String theme) {
163: super .setTheme(theme);
164: Props props = getPage().getPageProperties();
165:
166: _imageOn = props.getThemeProperty(theme,
167: Props.RADIOBUTTON_IMAGE_ON);
168: _imageOff = props.getThemeProperty(theme,
169: Props.RADIOBUTTON_IMAGE_OFF);
170: }
171: }
|