0001: //** Copyright Statement ***************************************************
0002: //The Salmon Open Framework for Internet Applications (SOFIA)
0003: // Copyright (C) 1999 - 2002, Salmon LLC
0004: //
0005: // This program is free software; you can redistribute it and/or
0006: // modify it under the terms of the GNU General Public License version 2
0007: // as published by the Free Software Foundation;
0008: //
0009: // This program is distributed in the hope that it will be useful,
0010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
0011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012: // GNU General Public License for more details.
0013: //
0014: // You should have received a copy of the GNU General Public License
0015: // along with this program; if not, write to the Free Software
0016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0017: //
0018: // For more information please visit http://www.salmonllc.com
0019: //** End Copyright Statement ***************************************************
0020: package com.salmonllc.jsp;
0021:
0022: /////////////////////////
0023: //$Archive: /SOFIA/SourceCode/com/salmonllc/jsp/JspDataTable.java $
0024: //$Author: Dan $
0025: //$Revision: 65 $
0026: //$Modtime: 11/05/04 11:06a $
0027: /////////////////////////
0028:
0029: import java.awt.*;
0030: import java.io.IOException;
0031: import java.io.OutputStream;
0032: import java.lang.reflect.Method;
0033: import java.util.*;
0034:
0035: import com.salmonllc.html.*;
0036: import com.salmonllc.localizer.LanguagePreferences;
0037: import com.salmonllc.localizer.LanguageResourceFinder;
0038: import com.salmonllc.properties.Props;
0039: import com.salmonllc.sql.*;
0040: import com.salmonllc.util.*;
0041:
0042: /**
0043: * This object is used to render tabular data in a JSP Page
0044: */
0045: public class JspDataTable extends JspContainer implements
0046: ImageGenerator {
0047: public static final String PAGE_BUTTON_STYLE_RECTANGLE = "RECTANGLE";
0048: public static final String PAGE_BUTTON_STYLE_OVAL = "OVAL";
0049:
0050: public static final int PAGE_BUTTON_TYPE_SUBMIT = 0;
0051: public static final int PAGE_BUTTON_TYPE_IMAGE = 1;
0052: public static final int PAGE_BUTTON_TYPE_TEXT = 2;
0053: public static final int PAGE_BUTTON_TYPE_SCROLLBAR = 3;
0054:
0055: private DataStoreBuffer _ds;
0056: private HtmlComponent _submit;
0057:
0058: private int _nextTDHeaderNo;
0059: private int _nextTDRowNo;
0060: private int _nextTDFooterNo;
0061: private int _nextTDGroupHeaderNo;
0062: private int _nextTDGroupFooterNo;
0063:
0064: private int _nextTRHeaderNo;
0065: private int _nextTRRowNo;
0066: private int _nextTRFooterNo;
0067: private int _nextTRGroupHeaderNo;
0068: private int _nextTRGroupFooterNo;
0069:
0070: private String _bgcolor;
0071: private String _bordercolor;
0072: private String _defaultHeadingBackground;
0073: private String _defaultRowBackground1;
0074: private String _defaultRowBackground2;
0075: private String _theme;
0076:
0077: private int _breakColumns[];
0078: private HtmlComponent _clickSortComponent = null;
0079: private HtmlComponent _sortComponent = null;
0080: private int _sortDir = DataStore.SORT_DES;
0081: private int _sortColumn = -1;
0082: private int _baseSortColumn = -1;
0083: private int _baseSortDir;
0084: private Vector _propertyExpressions;
0085: private String _align = null;
0086: private int _border = -1;
0087: private int _cellPadding = -1;
0088: private int _cellSpacing = -1;
0089: private int _cols = -1;
0090: private int _hSpace = -1;
0091: private int _vSpace = -1;
0092: private String _height, _width;
0093:
0094: private boolean _scrollOnSort;
0095: private boolean _didSubmit;
0096: private boolean _scroll;
0097:
0098: private int _maxTDCols = 0;
0099:
0100: private String _groupBy;
0101: private boolean _clickSort;
0102: private boolean _color1 = true;
0103:
0104: private int _rowsPerPage = 10;
0105: private int _firstRowOnPage = 0;
0106: private int _maxPageButtons = 10;
0107: private int _firstSubmitButton = 0;
0108: private boolean _rowPerPageSel = true;
0109:
0110: private int _newRowsPerPage = -1;
0111: private int _oldRowsPerPage = _rowsPerPage;
0112: private int _newStartRow = -1;
0113: private int _newFirstButton = -1;
0114:
0115: private boolean _useCache = true;
0116: private long _cacheKey = 0;
0117: private Font _buttonFont;
0118: private String _fontString;
0119: private int _fontSize;
0120: private Color _textColor = Color.black;
0121: private Color _backgroundColor = Color.lightGray;
0122: private Color _topLeftBorder = Color.white;
0123: private Color _bottomRightBorder = Color.gray;
0124: private Color _transparentColor = Color.magenta;
0125: private String _style = PAGE_BUTTON_STYLE_RECTANGLE;
0126: private int _pageButtonType = PAGE_BUTTON_TYPE_SUBMIT;
0127: private int _imageHeight = 20;
0128: private String _imageURL;
0129: private String _scrollAnchor;
0130: private DataTablePageSelectRenderer _pageSelectRenderer;
0131: private DataTableRowsPerPageRenderer _rowsPerPageRenderer;
0132:
0133: private String _defaultRowStyleClassName1;
0134: private String _defaultRowStyleClassName2;
0135: private String _defaultHeadingStyleClassName;
0136:
0137: /*Claudio Pi (12-29-2002) Added, the following 5 instance varialbes for i18n of datatable labels*/
0138: private String _pageLabel = "Page";
0139: private String _pageOfLabel = "of";
0140: private String _rowsPerPageLabel = "Rows displayed per page";
0141: private String _totalRowsLabel = "Total rows";
0142: private boolean _updateLocale = true;
0143: private boolean _genTHeadAndBody = true;
0144: private HtmlRowHighlighter _rowHighlighter = null;
0145: private boolean _alwaysShowGroupFooter = false;
0146:
0147: private int _lastRenderedRow = -1;
0148:
0149: public JspDataTable(String name, com.salmonllc.html.HtmlPage p) {
0150: this (name, null, p);
0151: }
0152:
0153: public JspDataTable(String name, String theme,
0154: com.salmonllc.html.HtmlPage p) {
0155: super (name, p);
0156: setTheme(theme);
0157: _imageURL = generateImageURL();
0158: }
0159:
0160: /**
0161: * The propExpression will be evaluated by the evaluated for each row in the DataStore and the set method for the specified property will be called on the specified object.
0162: * @param comp The component to set the property for
0163: * @param propertyName The name of the property to set. The component must have a corresponding setProperty method or this method will throw a NoSuchMethodException
0164: * @param expEval DataStoreEvaluator The datastore evaluator that evaluates the expression
0165: * @exception java.lang.NoSuchMethodException The exception description.
0166: * @exception com.salmonllc.sql.DataStoreException The exception description.
0167: */
0168: public void addPropertyExpression(Object comp, String propertyName,
0169: DataStoreEvaluator expEval) throws NoSuchMethodException,
0170: DataStoreException {
0171: Class c = comp.getClass();
0172: Method m[] = c.getMethods();
0173: Method exe = null;
0174: String name = "set" + propertyName;
0175: Class parms[] = null;
0176: for (int i = 0; i < m.length; i++) {
0177: if (name.equalsIgnoreCase(m[i].getName())) {
0178: parms = m[i].getParameterTypes();
0179: if (parms.length == 1) {
0180: exe = m[i];
0181: break;
0182: }
0183: }
0184: }
0185: if (exe == null)
0186: throw new NoSuchMethodException(
0187: "Couldn't find a set method for property:"
0188: + propertyName);
0189: ThreeObjectContainer t = new ThreeObjectContainer(comp, exe,
0190: expEval);
0191: if (_propertyExpressions == null)
0192: _propertyExpressions = new Vector();
0193: _propertyExpressions.addElement(t);
0194: }
0195:
0196: /**
0197: * This method will add a property expression to the HtmlDataTable.
0198: * The propExpression will be evaluated for each row in the DataStore and the set method for the specified property will be called on the specified object.
0199: * @param comp The component to set the property for
0200: * @param propertyName The name of the property to set. The component must have a corresponding setProperty method or this method will throw a NoSuchMethodException
0201: * @param propExpression com.salmonllc.html.PropertyExpression The instance of PropertyExpression that should do the evaluating.
0202: * @exception java.lang.NoSuchMethodException The exception description.
0203: * @exception com.salmonllc.sql.DataStoreException The exception description.
0204: */
0205: public void addPropertyExpression(Object comp, String propertyName,
0206: DataStoreExpression propExpression)
0207: throws NoSuchMethodException, DataStoreException {
0208: DataStoreEvaluator dse = new DataStoreEvaluator(_ds,
0209: propExpression);
0210: addPropertyExpression(comp, propertyName, dse);
0211: }
0212:
0213: /**
0214: * The propExpression will be evaluated for each row in the DataStore and the set method for the specified property will be called on the specified object.
0215: @param comp The component to set the property for
0216: * @param propertyName The name of the property to set. The component must have a corresponding setProperty method or this method will throw a NoSuchMethodException
0217: * @param expression java.lang.String The datastore expression to evaluate
0218: * @exception java.lang.NoSuchMethodException The exception description.
0219: * @exception com.salmonllc.sql.DataStoreException The exception description.
0220: */
0221: public void addPropertyExpression(Object comp, String propertyName,
0222: String expression) throws NoSuchMethodException,
0223: DataStoreException {
0224: DataStoreEvaluator dse = new DataStoreEvaluator(_ds, expression);
0225: addPropertyExpression(comp, propertyName, dse);
0226: }
0227:
0228: public boolean executeEvent(int eventType) throws Exception {
0229: if (eventType == HtmlComponent.EVENT_OTHER) {
0230: for (int i = 0; i < getComponentCount(); i++) {
0231: HtmlComponent h = getComponent(i);
0232: if (!h.executeEvent(eventType))
0233: return false;
0234: }
0235: } else if (_submit != null
0236: && eventType == HtmlComponent.EVENT_SUBMIT) {
0237: if (_submit == this ) {
0238: if (_newRowsPerPage > -1) {
0239: _rowsPerPage = _newRowsPerPage;
0240: _firstSubmitButton = 0;
0241: _firstRowOnPage = 0;
0242: _newRowsPerPage = -1;
0243: }
0244:
0245: if (_newStartRow > -1)
0246: _firstRowOnPage = _newStartRow;
0247: if (_newFirstButton > -1)
0248: _firstSubmitButton = _newFirstButton;
0249:
0250: if (_clickSortComponent != null) {
0251: sortOnComponent(_clickSortComponent);
0252: _clickSortComponent = null;
0253: }
0254: _submit = null;
0255: if (_scroll) {
0256: if (_scrollAnchor != null)
0257: getPage().scrollToItem(_scrollAnchor);
0258: else {
0259: boolean didScroll = false;
0260: JspForm form = JspForm.findParentForm(this );
0261: if (form != null) {
0262: if (form.isScrollPositionSet()) {
0263: form.scrollToLastPosition();
0264: didScroll = true;
0265: }
0266: }
0267: if (!didScroll)
0268: getPage().scrollToItem(
0269: getName() + "TableStart");
0270: }
0271: _scroll = false;
0272: }
0273: } else {
0274: boolean retVal = _submit.executeEvent(eventType);
0275: _submit = null;
0276: return retVal;
0277: }
0278: }
0279: return true;
0280: }
0281:
0282: /**
0283: * This method will find a component suitable for sorting (an html for component attached to a datastore) inside the passed component.
0284: */
0285: public HtmlComponent findSortComponent(HtmlComponent sortComp) {
0286: if (sortComp == null)
0287: return null;
0288: else if (sortComp instanceof HtmlFormComponent) {
0289: if (((HtmlFormComponent) sortComp).getColumnNumber() != -1)
0290: return sortComp;
0291: } else if (sortComp instanceof HtmlText) {
0292: if (((HtmlText) sortComp).getExpressionEvaluator() != null)
0293: return sortComp;
0294: } else if (sortComp instanceof HtmlContainer) {
0295: Enumeration e = ((HtmlContainer) sortComp).getComponents();
0296: while (e.hasMoreElements()) {
0297: sortComp = (HtmlComponent) e.nextElement();
0298: if (sortComp != null)
0299: return findSortComponent(sortComp);
0300: }
0301: } else if (sortComp instanceof JspContainer) {
0302: int count = ((JspContainer) sortComp).getComponentCount();
0303: if (count == 0)
0304: return null;
0305: else {
0306: for (int i = 0; i < count; i++) {
0307: HtmlComponent comp = findSortComponent(((JspContainer) sortComp)
0308: .getComponent(i));
0309: if (comp != null)
0310: return comp;
0311: }
0312: }
0313: }
0314: return null;
0315: }
0316:
0317: /**
0318: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
0319: */
0320:
0321: public void flipColor() {
0322: _color1 = (!_color1);
0323: }
0324:
0325: /**
0326: * Generates the HTML for the component. This should not be called directly.
0327: */
0328: public void generateHTML(TagWriter t, String content)
0329: throws java.io.IOException {
0330: _didSubmit = false;
0331: /*Claudio Pi (12-29-2002) Added for i18n of data table labels*/
0332: processLocaleInfo();
0333: StringBuffer sb = new StringBuffer();
0334: if (!t.getDreamWeaverConv()) {
0335: sb.append("<INPUT TYPE=\"HIDDEN\" NAME=\"" + getFullName()
0336: + "ClickSortHidden\">");
0337: sb.append("<SCRIPT language=\"javascript\">");
0338: sb
0339: .append(" function " + getFullName()
0340: + "ClickSort(cell){");
0341: sb.append(getFormString() + getFullName()
0342: + "ClickSortHidden.value=cell;");
0343: JspForm form = JspForm.findParentForm(this );
0344: if (form != null)
0345: sb.append(form.getSubmitScript());
0346: else
0347: sb.append(getFormString() + "submit();");
0348: sb.append(" }");
0349: sb.append("</SCRIPT>");
0350: sb.append("<A NAME=\"" + getName() + "TableStart\"></A>");
0351: }
0352:
0353: boolean writeScrollDiv = _pageButtonType == PAGE_BUTTON_TYPE_SCROLLBAR
0354: && getPage().getBrowserType() == HtmlPage.BROWSER_MICROSOFT
0355: && getPage().getBrowserVersion() > 4;
0356: if (writeScrollDiv) {
0357: sb
0358: .append("<style>thead#"
0359: + getFullName()
0360: + "-thead td {position:relative;top: expression(document.getElementById(\""
0361: + getFullName()
0362: + "-div\").scrollTop-2);}</style>");
0363: sb.append("<div id=\"" + getFullName()
0364: + "-div\" style=\"height:" + _height
0365: + ";overflow: auto\">");
0366: }
0367:
0368: sb.append("<TABLE");
0369:
0370: if (_class != null)
0371: sb.append(" CLASS=\"" + _class + "\"");
0372:
0373: if (_border != -1)
0374: sb.append(" BORDER=\"" + _border + "\"");
0375:
0376: if (_bordercolor != null)
0377: sb.append(" BORDERCOLOR=\"" + _bordercolor + "\"");
0378:
0379: if (_cellPadding != -1)
0380: sb.append(" CELLPADDING=\"" + _cellPadding + "\"");
0381:
0382: if (_cellSpacing != -1)
0383: sb.append(" CELLSPACING=\"" + _cellSpacing + "\"");
0384:
0385: if (_bgcolor != null)
0386: sb.append(" BGCOLOR=\"" + _bgcolor + "\"");
0387:
0388: if (_height != null
0389: && _pageButtonType != PAGE_BUTTON_TYPE_SCROLLBAR)
0390: sb.append(" HEIGHT=\"" + _height + "\"");
0391:
0392: if (_width != null)
0393: sb.append(" WIDTH=\"" + _width + "\"");
0394:
0395: if (_align != null)
0396: sb.append(" ALIGN=\"" + _align + "\"");
0397:
0398: if (_cols != -1)
0399: sb.append(" COLS=\"" + _cols + "\"");
0400:
0401: if (_hSpace != -1)
0402: sb.append(" HSPACE=\"" + _hSpace + "\"");
0403:
0404: if (_vSpace != -1)
0405: sb.append(" VSPACE=\"" + _vSpace + "\"");
0406:
0407: sb.append(">");
0408:
0409: t.print(sb.toString(), TagWriter.TYPE_BEGIN_TAG);
0410: t.print(content, TagWriter.TYPE_CONTENT);
0411:
0412: sb.setLength(0);
0413:
0414: int rowCount = _ds == null ? 0 : _ds.getRowCount();
0415: int rowsPerPage = _rowsPerPage;
0416: if (rowCount > rowsPerPage) {
0417: if (_pageSelectRenderer == null) {
0418: if (_pageButtonType == PAGE_BUTTON_TYPE_SUBMIT)
0419: _pageSelectRenderer = DataTablePageSelectRenderer
0420: .getSubmitButtonRenderer();
0421: else if (_pageButtonType == PAGE_BUTTON_TYPE_IMAGE)
0422: _pageSelectRenderer = DataTablePageSelectRenderer
0423: .getImageButtonRenderer();
0424: else
0425: _pageSelectRenderer = DataTablePageSelectRenderer
0426: .getLinkRenderer();
0427: }
0428:
0429: flipColor();
0430: String backgroundColor = getCurrentRowBackgroundColor();
0431: String style = getCurrentRowStyleClassName();
0432: String styleString = "";
0433: if (backgroundColor != null)
0434: styleString += " BGCOLOR=\"" + backgroundColor + "\"";
0435: if (style != null)
0436: styleString += " CLASS=\"" + style + "\"";
0437: sb.append("<TR><TD VALIGN=\"MIDDLE\" COLSPAN=\""
0438: + getColumnCount() + "\"" + styleString + ">");
0439: int noButtons = (rowCount / rowsPerPage);
0440: if (rowCount % rowsPerPage > 0)
0441: noButtons++;
0442: int page = (_firstRowOnPage / rowsPerPage) + 1;
0443:
0444: sb.append(_pageSelectRenderer.generateRowSelector(this ,
0445: _theme, _pageLabel, _pageOfLabel, page,
0446: _firstSubmitButton, noButtons, _maxPageButtons,
0447: _imageURL));
0448: sb.append("</TD></TR>");
0449: }
0450:
0451: if (_rowPerPageSel && rowCount > _oldRowsPerPage) {
0452: if (_rowsPerPageRenderer == null)
0453: _rowsPerPageRenderer = DataTableRowsPerPageRenderer
0454: .getDefaultRenderer();
0455: flipColor();
0456:
0457: String backgroundColor = getCurrentRowBackgroundColor();
0458: String style = getCurrentRowStyleClassName();
0459: String styleString = "";
0460: if (backgroundColor != null)
0461: styleString += " BGCOLOR=\"" + backgroundColor + "\"";
0462: if (style != null)
0463: styleString += " CLASS=\"" + style + "\"";
0464: sb.append("<TR><TD VALIGN=\"MIDDLE\" COLSPAN=\""
0465: + getColumnCount() + "\"" + styleString + ">");
0466: sb.append(_rowsPerPageRenderer.generateRowSelector(this ,
0467: _theme, _totalRowsLabel, _rowsPerPageLabel, null,
0468: rowsPerPage, rowCount));
0469: sb.append("</TD></TR>");
0470: }
0471: sb.append("</TFOOT></TABLE>");
0472: if (writeScrollDiv)
0473: sb.append("</DIV>");
0474: t.print(sb.toString(), TagWriter.TYPE_END_TAG);
0475: makeEnabledAndVisible();
0476:
0477: // if (_scroll) {
0478: // getPage().scrollToItem(getName() + "TableStart");
0479: // _scroll = false;
0480: // }
0481: }
0482:
0483: public void generateImage(String img, OutputStream out)
0484: throws IOException {
0485: //create an image to draw
0486: ImageFactory fact = new ImageFactory();
0487: Image i = null;
0488:
0489: String source = img;
0490: if (img.equals("first"))
0491: source = "<<";
0492: else if (img.equals("last"))
0493: source = ">>";
0494: else if (img.equals("next"))
0495: source = ">";
0496: else if (img.equals("prior"))
0497: source = "<";
0498: else
0499: source = new Integer((Integer.parseInt(img) + 1))
0500: .toString();
0501:
0502: if (_style.equals(PAGE_BUTTON_STYLE_OVAL))
0503: i = fact.createOvalButton(_imageHeight,
0504: getPagingButtonFont(), source, _textColor,
0505: _backgroundColor, _topLeftBorder,
0506: _bottomRightBorder, _transparentColor, false,
0507: _enabled);
0508: else
0509: i = fact.createRectangleButton(_imageHeight,
0510: getPagingButtonFont(), source, _textColor,
0511: _backgroundColor, _topLeftBorder,
0512: _bottomRightBorder, false, _enabled);
0513:
0514: GifEncoder g = new GifEncoder(i, out, true, _transparentColor);
0515: g.encode();
0516:
0517: }
0518:
0519: /**
0520: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
0521: */
0522:
0523: public String generateNextTDName(int colSpan, int type) {
0524: String ret = "";
0525: if (type == TYPE_HEADER) {
0526: ret = getName() + "TDHeader" + _nextTDHeaderNo;
0527: _nextTDHeaderNo += colSpan;
0528: } else if (type == TYPE_FOOTER) {
0529: ret = getName() + "TDFooter" + _nextTDFooterNo;
0530: _nextTDFooterNo += colSpan;
0531: } else if (type == TYPE_ROW) {
0532: ret = getName() + "TDRow" + _nextTDRowNo;
0533: _nextTDRowNo += colSpan;
0534: } else if (type == TYPE_GROUP_HEADER) {
0535: ret = getName() + "TDGroupHeader" + _nextTDGroupHeaderNo;
0536: _nextTDGroupHeaderNo += colSpan;
0537: } else if (type == TYPE_GROUP_FOOTER) {
0538: ret = getName() + "TDGroupFooter" + _nextTDGroupFooterNo;
0539: _nextTDGroupFooterNo += colSpan;
0540: }
0541:
0542: return ret;
0543: }
0544:
0545: /**
0546: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
0547: */
0548:
0549: public String generateNextTRName(int type) {
0550: String ret = "";
0551: if (type == TYPE_HEADER) {
0552: ret = getName() + "TRHeader" + _nextTRHeaderNo;
0553: _nextTRHeaderNo++;
0554: } else if (type == TYPE_FOOTER) {
0555: ret = getName() + "TRFooter" + _nextTRFooterNo;
0556: _nextTRFooterNo++;
0557: } else if (type == TYPE_ROW) {
0558: ret = getName() + "TRRow" + _nextTRRowNo;
0559: _nextTRRowNo++;
0560: } else if (type == TYPE_GROUP_HEADER) {
0561: ret = getName() + "TRGroupHeader" + _nextTRGroupHeaderNo;
0562: _nextTRGroupHeaderNo++;
0563: } else if (type == TYPE_GROUP_FOOTER) {
0564: ret = getName() + "TRGroupFooter" + _nextTRGroupFooterNo;
0565: _nextTRGroupFooterNo++;
0566: }
0567:
0568: return ret;
0569: }
0570:
0571: /**
0572: * Gets the border thickness for the table.
0573: */
0574: public int getBorder() {
0575: return _border;
0576: }
0577:
0578: /**
0579: * Gets the background color for the table.
0580: */
0581: public String getBorderColor() {
0582: return _bordercolor;
0583: }
0584:
0585: /**
0586: * Returns an array of column numbers used for control breaks.
0587: */
0588: public int[] getBreakColumns() {
0589: if (_breakColumns == null && _groupBy != null) {
0590: JspController parent = (JspController) getPage();
0591: Hashtable t = parent.getComponentTable();
0592: StringTokenizer st = new StringTokenizer(_groupBy, ",");
0593: Vector res = new Vector();
0594: while (st.hasMoreTokens()) {
0595: String tok = st.nextToken();
0596: HtmlComponent comp = (HtmlComponent) t.get(tok);
0597: int col = -1;
0598: if (comp != null) {
0599: if (comp instanceof HtmlFormComponent)
0600: col = ((HtmlFormComponent) comp)
0601: .getColumnNumber();
0602: else if (comp instanceof HtmlText) {
0603: DataStoreEvaluator eval = ((HtmlText) comp)
0604: .getExpressionEvaluator();
0605: if (eval != null)
0606: col = _ds.getColumnIndex(eval
0607: .getExpression());
0608: }
0609: }
0610: if (col != -1)
0611: res.add(new Integer(col));
0612: }
0613:
0614: _breakColumns = new int[res.size()];
0615: for (int i = 0; i < res.size(); i++)
0616: _breakColumns[i] = ((Integer) res.elementAt(i))
0617: .intValue();
0618: }
0619:
0620: return _breakColumns;
0621: }
0622:
0623: public long getCacheKey() {
0624: return _cacheKey;
0625: }
0626:
0627: /**
0628: * Gets the cell padding for the table.
0629: */
0630: public int getCellPadding() {
0631: return _cellPadding;
0632: }
0633:
0634: /**
0635: * Gets the cell spacing for the table.
0636: */
0637: public int getCellSpacing() {
0638: return _cellSpacing;
0639: }
0640:
0641: /**
0642: * Returns whether or not the component should have headings that sort the table when the user clicks on them
0643: */
0644: public boolean getClickSort() {
0645: return _clickSort;
0646: }
0647:
0648: /**
0649: * Sets the cell padding for the table.
0650: */
0651: public int getCols() {
0652: return _cols;
0653: }
0654:
0655: private int getColumnCount() {
0656: if (_cols != -1)
0657: return _cols;
0658: else
0659: return _maxTDCols;
0660: }
0661:
0662: /**
0663: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
0664: */
0665: public String getCurrentRowBackgroundColor() {
0666: if (_color1)
0667: return getRowBackgroundColor1();
0668: else
0669: return getRowBackgroundColor2();
0670:
0671: }
0672:
0673: /**
0674: * Returns the next color that will be used to stripe the rows in the table
0675: */
0676: public String getNextRowBackgroundColor() {
0677: if (!_color1)
0678: return getRowBackgroundColor1();
0679: else
0680: return getRowBackgroundColor2();
0681:
0682: }
0683:
0684: /**
0685: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
0686: */
0687: public String getCurrentRowStyleClassName() {
0688: if (_color1)
0689: return getRowStyleClassName1();
0690: else
0691: return getRowStyleClassName2();
0692:
0693: }
0694:
0695: /**
0696: * Returns the DataStoreBuffer attached to this component.
0697: */
0698: public DataStoreBuffer getDataStoreBuffer() {
0699: return _ds;
0700: }
0701:
0702: /**
0703: * This method returns true if the datatable did the last submit of the page through a sort or clicking on a paging button.
0704: */
0705: public boolean getDidSubmit() {
0706: return _didSubmit;
0707: }
0708:
0709: /**
0710: * Returns the first row on the page displayed in the datatable.
0711: */
0712: public int getFirstRowOnPage() {
0713: return _firstRowOnPage;
0714: }
0715:
0716: /**
0717: * Returns the GroupBy string initialized by the JSP.
0718: */
0719: public String getGroupBy() {
0720: return _groupBy;
0721: }
0722:
0723: /**
0724: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
0725: */
0726:
0727: public String getHeaderTDNameForRow(String name) {
0728: String number = name.substring(getName().length() + 5);
0729: return getName() + "TDHeader" + number;
0730: }
0731:
0732: /**
0733: * This method returns the background color for the heading of the Data Table.
0734: */
0735: public String getHeadingBackgroundColor() {
0736: return _defaultHeadingBackground;
0737: }
0738:
0739: /**
0740: * This method returns the height for the DataTable
0741: */
0742: public String getHeight() {
0743: return _height;
0744:
0745: }
0746:
0747: /**
0748: * Gets the horizontal margin for the table.
0749: */
0750: public int getHSpace() {
0751: return _hSpace;
0752: }
0753:
0754: /**
0755: * This method gets the maximum number of paging buttons to display.
0756: */
0757: public int getMaxPageButtons() {
0758: return _maxPageButtons;
0759: }
0760:
0761: /**
0762: * Sets the maximum number of paging buttons for the table.
0763: */
0764: public int getMaxPagingButtons() {
0765: return _maxPageButtons;
0766: }
0767:
0768: /**
0769: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
0770: */
0771:
0772: public int getMaxTDColumns() {
0773: return _maxTDCols;
0774:
0775: }
0776:
0777: /**
0778: * This method returns the page the row is on.
0779: */
0780: public int getPage(int row) {
0781: return row / _rowsPerPage;
0782: }
0783:
0784: /**
0785: * Gets the type of paging buttons for the data table. Valid Types are PAGE_BUTTON_TYPE_SUBMIT, PAGE_BUTTON_TYPE_IMAGE, PAGE_BUTTON_TYPE_TEXT
0786: **/
0787:
0788: public int getPageButtonType() {
0789: return _pageButtonType;
0790: }
0791:
0792: /**
0793: * This method returns the background color of paging button images
0794: */
0795: public Color getPagingButtonBackgroundColor() {
0796: return _backgroundColor;
0797: }
0798:
0799: /**
0800: * This method returns the bottom right border color of paging button images
0801: */
0802: public Color getPagingButtonBottomRightColor() {
0803: return _bottomRightBorder;
0804: }
0805:
0806: /**
0807: * This method gets the Display Style for a generated page button image. Valid Values are PAGE_BUTTON_STYLE_RECTANGLE and PAGE_BUTTON_STYLE_OVAL
0808: */
0809: public String getPagingButtonDisplayStyle() {
0810: return _style;
0811: }
0812:
0813: /**
0814: * This method returns the font used for page button images
0815: */
0816: public Font getPagingButtonFont() {
0817: if (_buttonFont == null)
0818: _buttonFont = new Font(_fontString, 0, _fontSize);
0819: return _buttonFont;
0820: }
0821:
0822: /**
0823: * This method returns the height used for page button images
0824: */
0825: public int getPagingButtonHeight() {
0826: return _imageHeight;
0827: }
0828:
0829: /**
0830: * This method returns the text color of page button images
0831: */
0832: public Color getPagingButtonTextColor() {
0833: return _textColor;
0834: }
0835:
0836: /**
0837: * This method returns the first background color for the rows in the datatable
0838: */
0839: public String getRowBackgroundColor1() {
0840: return _defaultRowBackground1;
0841: }
0842:
0843: /**
0844: * This method returns the second background color for the rows in the datatable
0845: */
0846:
0847: public String getRowBackgroundColor2() {
0848: return _defaultRowBackground2;
0849: }
0850:
0851: /**
0852: * This method gets the number of rows to display on one page of output. A value <= 0 will indicate no limit to the number of rows displayed.
0853: */
0854: public int getRowsPerPage() {
0855: return _rowsPerPage;
0856: }
0857:
0858: /**
0859: * This method gets the anchor to scroll to when a paging button on the table is clicked. Set it to null for the top of the table.
0860: */
0861: public String getScrollAnchor() {
0862: return _scrollAnchor;
0863: }
0864:
0865: /**
0866: * Gets whether the datastore will build scrolling javascript when the user clicks on a column heading to sort or a paging button.
0867: */
0868: public boolean getScrollOnClickSort() {
0869: return _scrollOnSort;
0870: }
0871:
0872: /**
0873: * Returns true if rows per page selector is visible.
0874: */
0875: public boolean getSelRowsPerPage() {
0876: return _rowPerPageSel;
0877: }
0878:
0879: /**
0880: * This method returns the number of the last column that the user clicked on to sort the list.
0881: */
0882: public int getSortColumn() {
0883: return _sortColumn;
0884: }
0885:
0886: /**
0887: * This method returns the direction of the sort set when the user last clicked a column heading to sort the list. Valid values are DataStoreBuffer.SORT_ASC or DataStoreBuffer.SORT_DES.
0888: */
0889: public int getSortDirection() {
0890: return _sortDir;
0891: }
0892:
0893: public boolean getUseCache() {
0894: return _useCache;
0895: }
0896:
0897: /**
0898: * Gets the vertical margin for the table.
0899: */
0900: public int getVSpace() {
0901: return _vSpace;
0902: }
0903:
0904: /**
0905: * Gets the width of the DataTable
0906: */
0907: public String getWidth() {
0908: return _width;
0909:
0910: }
0911:
0912: /**
0913: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
0914: */
0915:
0916: public void initColor() {
0917: _color1 = true;
0918: }
0919:
0920: /**
0921: * This method returns true if the specified row is on the current page.
0922: */
0923: public boolean isRowOnPage(int row) {
0924: int pageNo = row / _rowsPerPage;
0925: int currentPage = _firstRowOnPage / _rowsPerPage;
0926:
0927: return pageNo == currentPage;
0928: }
0929:
0930: public boolean processParms(Hashtable parms, int rowNo)
0931: throws Exception {
0932: if (!getVisible())
0933: return false;
0934:
0935: if (_ds == null)
0936: return false;
0937: //fc: 05/30/02 need to reprocess property expressions before doing process parms
0938: processPropertyExpressions(rowNo);
0939: int rowCount = _ds.getRowCount();
0940:
0941: for (int i = 0; i < getComponentCount(); i++) {
0942: if (getComponentType(i) != TYPE_ROW
0943: && getComponentType(i) != TYPE_GROUP_FOOTER
0944: && getComponentType(i) != TYPE_GROUP_HEADER) {
0945: HtmlComponent h = getComponent(i);
0946: if (h != null)
0947: if (h.processParms(parms, -1))
0948: _submit = h;
0949: }
0950: }
0951:
0952: int endRow = _firstRowOnPage + _rowsPerPage;
0953: if (endRow > rowCount)
0954: endRow = rowCount;
0955:
0956: for (int j = _firstRowOnPage; j < endRow; j++) {
0957: //fc: 10/18/02 need to reprocess property expressions before doing process parms for each row of Data Table.
0958: processPropertyExpressions(j);
0959: for (int i = 0; i < getComponentCount(); i++) {
0960: if (getComponentType(i) == TYPE_ROW
0961: || getComponentType(i) == TYPE_GROUP_HEADER
0962: || getComponentType(i) == TYPE_GROUP_FOOTER) {
0963: HtmlComponent h = getComponent(i);
0964: if (h != null)
0965: if (h.processParms(parms, j))
0966: _submit = h;
0967: }
0968: }
0969: }
0970:
0971: int noButtons = rowCount / _rowsPerPage;
0972: if (rowCount % _rowsPerPage > 0)
0973: noButtons++;
0974:
0975: Object sortName = parms.get(getFullName() + "ClickSortHidden");
0976: _clickSortComponent = null;
0977: if (sortName != null) {
0978: String[] items = (String[]) sortName;
0979: if (items[0] != null && items[0].trim().length() > 0) {
0980: _clickSortComponent = ((JspController) getPage())
0981: .getComponent(items[0]);
0982: _submit = this ;
0983: }
0984: }
0985:
0986: Object rpp = parms.get(getFullName() + "_rows_per_page_hidden");
0987: if (rpp != null) {
0988: String val = ((String[]) rpp)[0];
0989: if (val.equals("1")) {
0990: rpp = parms.get(getFullName() + "row_per_page_dd");
0991: _newRowsPerPage = new Integer(((String[]) rpp)[0])
0992: .intValue();
0993: _submit = this ;
0994: } else if (!val.equals("-1")) {
0995: _newRowsPerPage = new Integer(val).intValue();
0996: _submit = this ;
0997: }
0998: }
0999:
1000: String[] pageSubmitA = (String[]) parms.get(getFullName()
1001: + "_page_selector");
1002: String pageSubmit = "";
1003: if (pageSubmitA != null)
1004: pageSubmit = pageSubmitA[0];
1005:
1006: _newStartRow = -1;
1007: _newFirstButton = -1;
1008: if (parms.get(getFullName() + "_page_first") != null
1009: || parms.get(getFullName() + "_page_first.x") != null
1010: || pageSubmit.equals("first")) {
1011: _newFirstButton = 0;
1012: _newStartRow = 0;
1013: _submit = this ;
1014: } else if (parms.get(getFullName() + "_page_prior") != null
1015: || parms.get(getFullName() + "_page_prior.x") != null
1016: || pageSubmit.equals("prior")) {
1017: _newFirstButton = _firstSubmitButton
1018: - (_maxPageButtons == 0 ? 1 : _maxPageButtons);
1019: _submit = this ;
1020: if (_newFirstButton < 0)
1021: _newFirstButton = 0;
1022: _newStartRow = _rowsPerPage
1023: * (_newFirstButton
1024: + (_maxPageButtons == 0 ? 1
1025: : _maxPageButtons) - 1);
1026: } else if (parms.get(getFullName() + "_page_next") != null
1027: || parms.get(getFullName() + "_page_next.x") != null
1028: || pageSubmit.equals("next")) {
1029: _newFirstButton = _firstSubmitButton
1030: + (_maxPageButtons == 0 ? 1 : _maxPageButtons);
1031: _submit = this ;
1032: if ((_newFirstButton + _maxPageButtons) >= noButtons)
1033: _newFirstButton = (noButtons - (_maxPageButtons == 0 ? 1
1034: : _maxPageButtons));
1035: _newStartRow = _rowsPerPage * _newFirstButton;
1036: } else if (parms.get(getFullName() + "_page_last") != null
1037: || parms.get(getFullName() + "_page_last.x") != null
1038: || pageSubmit.equals("last")) {
1039: _submit = this ;
1040: _newFirstButton = (noButtons - (_maxPageButtons == 0 ? 1
1041: : _maxPageButtons));
1042: _newStartRow = _rowsPerPage * _newFirstButton;
1043: if (_newStartRow < 0)
1044: _newStartRow = 0;
1045: } else if (!pageSubmit.equals("")) {
1046: _newStartRow = _rowsPerPage * Integer.parseInt(pageSubmit);
1047: _submit = this ;
1048: } else {
1049: for (int i = _firstSubmitButton; (i < noButtons)
1050: && ((i - _firstSubmitButton) < _maxPageButtons); i++) {
1051: if (parms.get(getFullName() + "_page_" + i) != null
1052: || parms.get(getFullName() + "_page_" + i
1053: + ".x") != null) {
1054: _newStartRow = _rowsPerPage * i;
1055: _submit = this ;
1056: break;
1057: }
1058: }
1059: }
1060:
1061: //
1062: if (_submit == null) {
1063: _scroll = false;
1064: return false;
1065: } else {
1066: _scroll = _scrollOnSort;
1067: _didSubmit = true;
1068: return true;
1069: }
1070: }
1071:
1072: public void processPropertyExpressions(int row) {
1073: if (_propertyExpressions == null)
1074: return;
1075:
1076: ThreeObjectContainer c = null;
1077: Object comp = null;
1078: Method meth = null;
1079: DataStoreEvaluator eval = null;
1080:
1081: int propertyExpressionsSize = _propertyExpressions.size();
1082: for (int i = 0; i < propertyExpressionsSize; i++) {
1083: c = (ThreeObjectContainer) _propertyExpressions
1084: .elementAt(i);
1085: comp = c.getObject1();
1086: meth = (Method) c.getObject2();
1087: eval = (DataStoreEvaluator) c.getObject3();
1088: HtmlPage.executePropertyMethod(comp, meth, eval, row);
1089: }
1090: }
1091:
1092: /**
1093: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
1094: */
1095: public void resetCounters() {
1096: _nextTDFooterNo = 0;
1097: _nextTDHeaderNo = 0;
1098: _nextTDRowNo = 0;
1099: _nextTRFooterNo = 0;
1100: _nextTRHeaderNo = 0;
1101: _nextTRRowNo = 0;
1102: _nextTDGroupFooterNo = 0;
1103: _nextTDGroupHeaderNo = 0;
1104: _nextTRGroupFooterNo = 0;
1105: _nextTRGroupHeaderNo = 0;
1106: }
1107:
1108: /**
1109: * Sets the alignment for the Data Table.
1110: */
1111: public void setAlign(String newAlign) {
1112: _align = newAlign;
1113: }
1114:
1115: /**
1116: * Sets the background color for the table.
1117: */
1118: public void setBackgroundColor(String value) {
1119: _bgcolor = value;
1120: }
1121:
1122: /**
1123: * This method will set the base click sort column for the datastore. This column and direction will be appended to the sort column that the user clicked on.
1124: * @param column The column to sort on
1125: * @param dir int DataStoreBuffer.SORT_ASC or DataStoreBuffer.SORT_DES
1126: */
1127: public void setBaseClickSort(String column, int dir) {
1128: _baseSortColumn = _ds.getColumnIndex(column);
1129: _baseSortDir = dir;
1130: }
1131:
1132: /**
1133: * Sets the border width for the table.
1134: */
1135: public void setBorder(int border) {
1136: _border = border;
1137: }
1138:
1139: /**
1140: * Sets the background color for the table.
1141: */
1142: public void setBorderColor(String value) {
1143: _bordercolor = value;
1144: }
1145:
1146: /**
1147: * Use this method to set the columns that the Data Table will control break on.
1148: * @param cols An array of column numbers to break on.
1149: */
1150: public void setBreakColumns(int[] cols) {
1151: _breakColumns = cols;
1152: }
1153:
1154: /**
1155: * Use this method to set the columns that the Data Table will control break on.
1156: * @param cols An array of column names to break on.
1157: */
1158: public void setBreakColumns(String[] cols) {
1159:
1160: int[] colN = new int[cols.length];
1161:
1162: for (int i = 0; i < colN.length; i++) {
1163: colN[i] = _ds.getColumnIndex(cols[i]);
1164: if (colN[i] == -1) {
1165: MessageLog.writeInfoMessage(
1166: "***Column Not Found Setting Break Columns:"
1167: + cols[i] + "***", this );
1168: }
1169: }
1170: _breakColumns = colN;
1171: }
1172:
1173: /**
1174: * Use this method to set the columns that the Data Table will control break on.
1175: * @param col The column number to break on.
1176: */
1177: public void setBreakColumns(int col) {
1178: _breakColumns = new int[1];
1179: _breakColumns[0] = col;
1180: }
1181:
1182: /**
1183: * Use this method to set the columns that the Data Table will control break on.
1184: * @param col A column name to break on.
1185: */
1186: public void setBreakColumns(String col) {
1187: int colN = _ds.getColumnIndex(col);
1188: if (colN == -1) {
1189: MessageLog.writeInfoMessage(
1190: "***Column Name not Found Setting Break Columns:"
1191: + col + "***", this );
1192: }
1193: _breakColumns = new int[1];
1194: _breakColumns[0] = colN;
1195: }
1196:
1197: /**
1198: * This method is used by the framework to decide whether or not to generate the image or get it from cache. It should not be called directly.
1199: */
1200: public void setCacheKey(long key) {
1201: _cacheKey = key;
1202: }
1203:
1204: /**
1205: * Sets the cell padding for the table.
1206: */
1207: public void setCellPadding(int value) {
1208: _cellPadding = value;
1209: }
1210:
1211: /**
1212: * Sets the cell spacing for the table.
1213: */
1214: public void setCellSpacing(int value) {
1215: _cellSpacing = value;
1216: }
1217:
1218: /**
1219: * Sets whether or not the table headings will have underline links that sort the table
1220: * Creation date: (5/22/01 2:32:37 PM)
1221: * @param newClickSort java.lang.String
1222: */
1223: public void setClickSort(boolean newClickSort) {
1224: _clickSort = newClickSort;
1225: }
1226:
1227: /**
1228: * Sets the number of columns for the table.
1229: */
1230: public void setCols(int value) {
1231: _cols = value;
1232: }
1233:
1234: /**
1235: * Set the datastore buffer that will be used to generate the table.
1236: */
1237: public void setDataStoreBuffer(DataStoreBuffer ds) {
1238: _ds = ds;
1239: }
1240:
1241: /**
1242: * This method sets the first row displayed on the current page.
1243: */
1244: public void setFirstRowOnPage(int firstRowOnPage) {
1245: _firstRowOnPage = firstRowOnPage;
1246: }
1247:
1248: /**
1249: * Sets the groupby string for the datatable.
1250: */
1251: public void setGroupBy(java.lang.String newGroupBy) {
1252: _groupBy = newGroupBy;
1253: }
1254:
1255: /**
1256: * Sets the background color for the heading
1257: */
1258: public void setHeadingBackgroundColor(String value) {
1259: _defaultHeadingBackground = value;
1260: }
1261:
1262: /**
1263: * Sets the height for the datatable
1264: */
1265: public void setHeight(String val) {
1266: _height = val;
1267:
1268: }
1269:
1270: /**
1271: * Sets the horizontal margin for the table.
1272: */
1273: public void setHSpace(int val) {
1274: _hSpace = val;
1275: }
1276:
1277: /**
1278: * This method sets the maximum number of paging buttons to display.
1279: */
1280: public void setMaxPageButtons(int max) {
1281: _maxPageButtons = max;
1282: }
1283:
1284: /**
1285: * Sets the maximum number of paging buttons for the table.
1286: */
1287: public void setMaxPagingButtons(int max) {
1288: _maxPageButtons = max;
1289: }
1290:
1291: /**
1292: * This method should not be called directly. It is public so it can be called from com.salmonllc.jsp.tags.
1293: */
1294: public void setMaxTDColumns(int cols) {
1295: _maxTDCols = cols;
1296:
1297: }
1298:
1299: /**
1300: * This method will scroll to the first row on the current selected page
1301: */
1302: //public void setPage(int page) {
1303: // _firstRowOnPage = page * _rowsPerPage;
1304: // if (_maxPageButtons == 0)
1305: // _firstSubmitButton = page;
1306: //}
1307: /**
1308: * This method will scroll to the first row on the current selected page
1309: * It also adjusts the _firstSubmitButton to correctly set up the page
1310: * range below the table.
1311: */
1312: public void setPage(int page) {
1313:
1314: // Calculate first row on page
1315: _firstRowOnPage = page * _rowsPerPage;
1316:
1317: // Set our first submit button to be the page we are on
1318: int rowCount = _ds.getRowCount();
1319: int noButtons = rowCount / _rowsPerPage;
1320: if (rowCount % _rowsPerPage > 0)
1321: noButtons++;
1322:
1323: // Calculate an offset to the submit button so that we don't skew
1324: // the range of pages. Then apply offset if necessary. Also make sure
1325: // we adjust the first button at the high end of the page range
1326: //if necessary,
1327: _firstSubmitButton = page;
1328: int pageOffset = _firstSubmitButton
1329: % (_maxPageButtons == 0 ? 1 : _maxPageButtons);
1330:
1331: // Takes care of case where we are at the beginning of page range
1332: if (page < _maxPageButtons)
1333: _firstSubmitButton = 0;
1334:
1335: // Takes care of case where we are at the end of the page range
1336: else if (page + _maxPageButtons > noButtons)
1337: _firstSubmitButton = noButtons - _maxPageButtons;
1338:
1339: // All other cases
1340: else
1341: _firstSubmitButton -= pageOffset;
1342: }
1343:
1344: /**
1345: * Sets the type of paging buttons for the data table. Valid Types are PAGE_BUTTON_TYPE_SUBMIT, PAGE_BUTTON_TYPE_IMAGE, PAGE_BUTTON_TYPE_TEXT
1346: **/
1347:
1348: public void setPageButtonType(int type) {
1349: _pageButtonType = type;
1350: if (_pageButtonType == PAGE_BUTTON_TYPE_IMAGE)
1351: getPage().registerImageGenerator(getFullName(), this );
1352: if (_pageButtonType == PAGE_BUTTON_TYPE_SCROLLBAR)
1353: setRowsPerPage(9999999);
1354: }
1355:
1356: /**
1357: * This method sets the background color for the page button generated image
1358: */
1359: public void setPagingButtonBackgroundColor(Color c) {
1360: _backgroundColor = c;
1361: }
1362:
1363: /**
1364: * This method sets the bottom and right border color for the page button generated image
1365: */
1366: public void setPagingButtonBottomRightColor(Color c) {
1367: _bottomRightBorder = c;
1368: }
1369:
1370: /**
1371: * This method sets the Display Style for a generated image button. Valid Values are PAGE_BUTTON_STYLE_RECTANGLE and PAGE_BUTTON_STYLE_OVAL
1372: */
1373: public void setPagingButtonDisplayStyle(String style) {
1374: _style = style;
1375: }
1376:
1377: /**
1378: * This method sets the font used for dynamically generated page button images.
1379: */
1380: public void setPagingButtonFont(Font f) {
1381: _buttonFont = f;
1382: }
1383:
1384: /**
1385: * This method sets the height used for page button images
1386: */
1387: public void setPagingButtonHeight(int height) {
1388: _imageHeight = height;
1389: }
1390:
1391: /**
1392: * Sets the first background color for the table
1393: */
1394: public void setRowBackgroundColor1(String value) {
1395: _defaultRowBackground1 = value;
1396: }
1397:
1398: /**
1399: * Sets the second background color for rows in the table
1400: */
1401: public void setRowBackgroundColor2(String value) {
1402: _defaultRowBackground2 = value;
1403: }
1404:
1405: /**
1406: * This method sets the number of rows to display on one page of output. A value <= 0 will indicate no limit to the number of rows displayed.
1407: */
1408: public void setRowsPerPage(int rowsPerPage) {
1409: _rowsPerPage = rowsPerPage;
1410: _oldRowsPerPage = rowsPerPage;
1411: }
1412:
1413: /**
1414: * This method sets the anchor to scroll to when a paging button on the table is clicked. Set it to null for the top of the table.
1415: */
1416: public void setScrollAnchor(String anchor) {
1417: _scrollAnchor = anchor;
1418: }
1419:
1420: /**
1421: * Sets whether the datastore will build scrolling javascript when the user clicks on a column heading to sort or a paging button.
1422: */
1423: public void setScrollOnClickSort(boolean scroll) {
1424: _scrollOnSort = scroll;
1425: }
1426:
1427: /**
1428: * Sets whether rows per page selector is visible.
1429: */
1430: public void setSelRowsPerPage(boolean sel) {
1431: _rowPerPageSel = sel;
1432: }
1433:
1434: /**
1435: * This method sets the property theme for the component.
1436: * @param theme The theme to use.
1437: */
1438: public void setTheme(String theme) {
1439:
1440: Props prop = getPage().getPageProperties();
1441:
1442: _border = prop.getThemeIntProperty(theme,
1443: Props.DATA_TABLE_BORDER);
1444: _bgcolor = prop.getThemeProperty(theme,
1445: Props.DATA_TABLE_BACKGROUND_COLOR);
1446: _cellPadding = prop.getThemeIntProperty(theme,
1447: Props.DATA_TABLE_CELLPADDING);
1448: _cellSpacing = prop.getThemeIntProperty(theme,
1449: Props.DATA_TABLE_CELLSPACING);
1450:
1451: _defaultHeadingBackground = prop.getThemeProperty(theme,
1452: Props.DATA_TABLE_HEADING_BACKGROUND_COLOR);
1453: _defaultRowBackground1 = prop.getThemeProperty(theme,
1454: Props.DATA_TABLE_ROW_BACKGROUND_COLOR_1);
1455: _defaultRowBackground2 = prop.getThemeProperty(theme,
1456: Props.DATA_TABLE_ROW_BACKGROUND_COLOR_2);
1457:
1458: String cs = prop.getThemeProperty(theme,
1459: Props.DATA_TABLE_CLICK_SORT);
1460: _clickSort = (cs == null ? false : cs.toUpperCase().equals(
1461: "TRUE"));
1462: _scrollOnSort = prop.getThemeBooleanProperty(theme,
1463: Props.DATA_TABLE_SCROLL_ON_CLICK_SORT, true);
1464:
1465: _maxPageButtons = prop.getThemeIntProperty(theme,
1466: Props.DATA_TABLE_MAX_PAGE_BUTTONS);
1467: if (_maxPageButtons <= 0)
1468: _maxPageButtons = 10;
1469:
1470: // rows per page
1471: _rowsPerPage = prop.getThemeIntProperty(theme,
1472: Props.DATA_TABLE_ROWS_PER_PAGE);
1473: if (_rowsPerPage <= 0)
1474: _rowsPerPage = 20;
1475:
1476: // sr (11/27/01 1:54:34 PM)
1477: // added to make the datatable smart about when to show the rows per page dropdown
1478: _oldRowsPerPage = _rowsPerPage;
1479:
1480: //properties for paging buttons
1481: _fontString = prop.getThemeProperty(theme,
1482: Props.SUBMIT_IMAGE_FONT_FACE);
1483: if (_fontString == null)
1484: _fontString = "Helvetica";
1485: _fontSize = prop.getThemeIntProperty(theme,
1486: Props.SUBMIT_IMAGE_FONT_SIZE);
1487: if (_fontSize == -1)
1488: _fontSize = 12;
1489:
1490: _imageHeight = prop.getThemeIntProperty(theme,
1491: Props.SUBMIT_IMAGE_DEFAULT_HEIGHT);
1492:
1493: Color c = prop.getThemeColorProperty(theme,
1494: Props.SUBMIT_IMAGE_TEXT_COLOR);
1495: if (c != null)
1496: _textColor = c;
1497:
1498: c = prop.getThemeColorProperty(theme,
1499: Props.SUBMIT_IMAGE_BACKGROUND_COLOR);
1500: if (c != null)
1501: _backgroundColor = c;
1502:
1503: c = prop.getThemeColorProperty(theme,
1504: Props.SUBMIT_IMAGE_TOPLEFT_BORDER_COLOR);
1505: if (c != null)
1506: _topLeftBorder = c;
1507:
1508: c = prop.getThemeColorProperty(theme,
1509: Props.SUBMIT_IMAGE_BOTTOMRIGHT_BORDER_COLOR);
1510: if (c != null)
1511: _bottomRightBorder = c;
1512:
1513: c = prop.getThemeColorProperty(theme,
1514: Props.SUBMIT_IMAGE_TRANSPARENT_COLOR);
1515: if (c != null)
1516: _transparentColor = c;
1517:
1518: String style = prop.getThemeProperty(theme,
1519: Props.SUBMIT_IMAGE_STYLE);
1520: if (style != null) {
1521: if (style.toUpperCase().equals(PAGE_BUTTON_STYLE_OVAL))
1522: _style = PAGE_BUTTON_STYLE_OVAL;
1523: else
1524: _style = PAGE_BUTTON_STYLE_RECTANGLE;
1525: }
1526:
1527: String rowSelectRenderer = prop.getThemeProperty(theme,
1528: Props.DATA_TABLE_PAGE_SELECT_RENDERER);
1529: if (rowSelectRenderer != null)
1530: setPageSelectRenderer(rowSelectRenderer);
1531:
1532: String rowsPerPageRenderer = prop.getThemeProperty(theme,
1533: Props.DATA_TABLE_ROWS_PER_PAGE_RENDERER);
1534: if (rowsPerPageRenderer != null)
1535: setRowsPerPageRenderer(rowsPerPageRenderer);
1536:
1537: _theme = theme;
1538: }
1539:
1540: /**
1541: * Sets the vertical margin for the table.
1542: */
1543: public void setVSpace(int val) {
1544: _vSpace = val;
1545: }
1546:
1547: /**
1548: * Sets the width of the table
1549: */
1550: public void setWidth(String val) {
1551: _width = val;
1552:
1553: }
1554:
1555: /**
1556: * This method was created in VisualAge.
1557: * @param comp com.salmonllc.html.HtmlComponent
1558: */
1559: private void sortOnComponent(HtmlComponent comp) throws Exception {
1560: comp = findSortComponent(comp);
1561: if (comp == _sortComponent) {
1562: if (_sortDir == DataStore.SORT_ASC)
1563: _sortDir = DataStore.SORT_DES;
1564: else
1565: _sortDir = DataStore.SORT_ASC;
1566: } else
1567: _sortDir = DataStore.SORT_ASC;
1568: _sortComponent = comp;
1569: int col = 0, dir = 0;
1570: if (comp instanceof HtmlFormComponent) {
1571: int dsCol = ((HtmlFormComponent) comp).getColumnNumber();
1572: col = dsCol;
1573: _sortColumn = col;
1574: dir = _sortDir;
1575: } else if (comp instanceof HtmlText) {
1576: DataStoreEvaluator eval = ((HtmlText) comp)
1577: .getExpressionEvaluator();
1578: String exp = eval.getExpression();
1579: int index = -1;
1580: if (exp != null)
1581: index = _ds.getColumnIndex(exp);
1582: if (index > -1) {
1583: col = index;
1584: _sortColumn = col;
1585: dir = _sortDir;
1586: } else {
1587: if (_breakColumns != null) {
1588: Object cols[] = new Object[_breakColumns.length + 1];
1589: int dirs[] = new int[_breakColumns.length + 1];
1590: for (int i = 0; i < _breakColumns.length; i++) {
1591: cols[i] = new Integer(_breakColumns[i]);
1592: dirs[i] = DataStore.SORT_ASC;
1593: }
1594: cols[_breakColumns.length] = eval;
1595: dirs[_breakColumns.length] = _sortDir;
1596: _ds.sort(cols, dirs);
1597: } else
1598: _ds.sort(eval, _sortDir);
1599: return;
1600: }
1601: }
1602: if (_breakColumns != null) {
1603: int cols[] = new int[_breakColumns.length + 1];
1604: int dirs[] = new int[_breakColumns.length + 1];
1605: for (int i = 0; i < _breakColumns.length; i++) {
1606: cols[i] = _breakColumns[i];
1607: dirs[i] = DataStore.SORT_ASC;
1608: }
1609: cols[_breakColumns.length] = col;
1610: dirs[_breakColumns.length] = dir;
1611: _ds.sort(cols, dirs);
1612: } else {
1613: if (_baseSortColumn == -1)
1614: _ds.sort(col, dir);
1615: else {
1616: int cols[] = { col, _baseSortColumn };
1617: int dirs[] = { dir, _baseSortDir };
1618: _ds.sort(cols, dirs);
1619: }
1620: }
1621: }
1622:
1623: private void makeEnabledAndVisible() {
1624: if (_propertyExpressions == null)
1625: return;
1626: //sr 10-15-2000
1627: int propertyExpressionsSize = _propertyExpressions.size();
1628: ThreeObjectContainer c = null;
1629: Object comp = null;
1630: Method meth = null;
1631: //
1632: for (int i = 0; i < propertyExpressionsSize; i++) {
1633: c = (ThreeObjectContainer) _propertyExpressions
1634: .elementAt(i);
1635: comp = c.getObject1();
1636: meth = (Method) c.getObject2();
1637: Object[] res = new Object[1];
1638: res[0] = new Boolean(true);
1639: //
1640: try {
1641: if (meth.getName().equals("setVisible")
1642: || meth.getName().equals("setEnabled"))
1643: meth.invoke(comp, res);
1644: } catch (Exception e) {
1645: MessageLog.writeErrorMessage("makeEnabledAndVisible()",
1646: e, this );
1647: }
1648: }
1649: }
1650:
1651: /**
1652: * This method will remove all property expressions from the table
1653: */
1654: public void clearPropertyExpressions() {
1655: if (_propertyExpressions != null)
1656: _propertyExpressions.setSize(0);
1657: }
1658:
1659: /**
1660: * Updates the data table labels for the current language<br>
1661: * The language property file must have the following key structure<br>
1662: * JspDataTable.page.Page represents the "Page" in the "Page N of N" label.<br>
1663: * JspDataTable.page.Of represents the "of" in the "Page N of N" label.<br>
1664: * JspDataTable.rows.PerPage represents the "Rows displayed per page" label.<br>
1665: * JspDataTable.rows.Total represents the "Total Rows" label.<br>
1666: * Author: Claudio Pi Gamba<br>
1667: * Company: http://www.grupo-quanam.com<br>
1668: * Email: claudio.pi@quanam.com.uy<br>
1669: */
1670: public void updateLocale() {
1671: _updateLocale = true;
1672: }
1673:
1674: private void processLocaleInfo() {
1675: if (_updateLocale) {
1676: _updateLocale = false;
1677: LanguagePreferences p = getPage().getLanguagePreferences();
1678: String appName = getPage().getApplicationName();
1679: String descr = null;
1680: StringBuffer key = new StringBuffer(
1681: "JspDataTable.page.Page");
1682: descr = LanguageResourceFinder.getResource(appName, key
1683: .toString(), p);
1684: if (descr != null) {
1685: _pageLabel = descr;
1686: }
1687: key = new StringBuffer("JspDataTable.page.Of");
1688: descr = LanguageResourceFinder.getResource(appName, key
1689: .toString(), p);
1690: if (descr != null) {
1691: _pageOfLabel = descr;
1692: }
1693: key = new StringBuffer("JspDataTable.rows.PerPage");
1694: descr = LanguageResourceFinder.getResource(appName, key
1695: .toString(), p);
1696: if (descr != null) {
1697: _rowsPerPageLabel = descr;
1698: }
1699: key = new StringBuffer("JspDataTable.rows.Total");
1700: descr = LanguageResourceFinder.getResource(appName, key
1701: .toString(), p);
1702: if (descr != null) {
1703: _totalRowsLabel = descr;
1704: }
1705:
1706: }
1707: }
1708:
1709: /**
1710: * Sets a new render to draw the HTML for the table page selector
1711: */
1712: public void setPageSelectRenderer(DataTablePageSelectRenderer r) {
1713: _pageSelectRenderer = r;
1714: }
1715:
1716: /**
1717: * Sets a new render to draw the HTML for the rows per page selector
1718: */
1719: public void setRowsPerPageRenderer(DataTableRowsPerPageRenderer r) {
1720: _rowsPerPageRenderer = r;
1721: }
1722:
1723: /**
1724: * Sets a new render to draw the HTML for the table page selector, given the class name for the renderer
1725: */
1726: public void setPageSelectRenderer(String r) {
1727: if (r != null) {
1728: if (r.equalsIgnoreCase("null")
1729: || r.equalsIgnoreCase("default")) {
1730: _pageSelectRenderer = null;
1731: return;
1732: }
1733: }
1734: try {
1735: Class c = Class.forName(r);
1736: _pageSelectRenderer = (DataTablePageSelectRenderer) c
1737: .newInstance();
1738: } catch (Exception e) {
1739: MessageLog.writeErrorMessage("setRowSelectRenderer", e,
1740: this );
1741: }
1742: }
1743:
1744: /**
1745: * Sets a new render to draw the HTML for the rows per page selector
1746: */
1747: public void setRowsPerPageRenderer(String r) {
1748: if (r != null) {
1749: if (r.equalsIgnoreCase("null")
1750: || r.equalsIgnoreCase("default")) {
1751: _rowsPerPageRenderer = null;
1752: return;
1753: }
1754: }
1755: try {
1756: Class c = Class.forName(r);
1757: _rowsPerPageRenderer = (DataTableRowsPerPageRenderer) c
1758: .newInstance();
1759: } catch (Exception e) {
1760: MessageLog.writeErrorMessage("setRowsPerPageRenderer", e,
1761: this );
1762: }
1763: }
1764:
1765: /**
1766: * @return the default style sheet class for table rows
1767: */
1768: public String getRowStyleClassName1() {
1769: return _defaultRowStyleClassName1;
1770: }
1771:
1772: /**
1773: * @return the default style sheet class for table alternate rows
1774: */
1775: public String getRowStyleClassName2() {
1776: return _defaultRowStyleClassName2;
1777: }
1778:
1779: /**
1780: * @param string sets the default style sheet class for table rows
1781: */
1782: public void setRowStyleClassName1(String string) {
1783: _defaultRowStyleClassName1 = string;
1784: }
1785:
1786: /**
1787: * @param string sets the default style sheet class for table alternate rows
1788: */
1789: public void setRowStyleClassName2(String string) {
1790: _defaultRowStyleClassName2 = string;
1791: }
1792:
1793: /**
1794: * @return the default style sheet class for heading rows
1795: */
1796: public String getHeadingStyleClassName() {
1797: return _defaultHeadingStyleClassName;
1798: }
1799:
1800: /**
1801: * @param string sets the default style sheet class for heading rows
1802: */
1803: public void setHeadingStyleClassName(String string) {
1804: _defaultHeadingStyleClassName = string;
1805: }
1806:
1807: /**
1808: * framework method, do not call directly
1809: */
1810: public int getLastRenderedRow() {
1811: return _lastRenderedRow;
1812: }
1813:
1814: /**
1815: * framework method, do not call directly
1816: */
1817: public void setLastRenderedRow(int lastRenderedRow) {
1818: _lastRenderedRow = lastRenderedRow;
1819: }
1820:
1821: /**
1822: * @return Returns true if the component will generate THEAD, TBODY and TFOOT tags around the sections of the table.
1823: */
1824: public boolean getGenTHeadAndBody() {
1825: return _genTHeadAndBody;
1826: }
1827:
1828: /**
1829: * @param true if the component will generate THEAD, TBODY and TFOOT tags around the sections of the table.
1830: */
1831: public void setGenTHeadAndBody(boolean genTHeadAndBody) {
1832: _genTHeadAndBody = genTHeadAndBody;
1833: }
1834:
1835: /**
1836: * @return Returns the rowHighlighter used by this component.
1837: */
1838: public HtmlRowHighlighter getRowHighlighter() {
1839: return _rowHighlighter;
1840: }
1841:
1842: /**
1843: * @param Framework method, do not call directly. Instead add a rowhighlighter to the JSP.
1844: */
1845: public void setRowHighlighter(HtmlRowHighlighter rowHighlighter) {
1846: _rowHighlighter = rowHighlighter;
1847: }
1848:
1849: /**
1850: * @return Returns the alwaysShowGroupFooter.
1851: */
1852: public boolean getAlwaysShowGroupFooter() {
1853: return _alwaysShowGroupFooter;
1854: }
1855:
1856: /**
1857: * @param alwaysShowGroupFooter The alwaysShowGroupFooter to set.
1858: */
1859: public void setAlwaysShowGroupFooter(boolean alwaysShowGroupFooter) {
1860: _alwaysShowGroupFooter = alwaysShowGroupFooter;
1861: }
1862:
1863: /**
1864: * Framework method, do not call directly
1865: */
1866: public void add(HtmlComponent comp, int type) {
1867: if (comp instanceof JspDiv && type == TYPE_GROUP_HEADER)
1868: _alwaysShowGroupFooter = true;
1869: super.add(comp, type);
1870: }
1871: }
|