Source Code Cross Referenced for JspList.java in  » J2EE » Sofia » com » salmonllc » jsp » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.jsp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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/JspList.java $
0024:        //$Author: Len $
0025:        //$Revision: 39 $
0026:        //$Modtime: 11/09/04 1:23p $
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.Hashtable;
0034:        import java.util.Vector;
0035:
0036:        import com.salmonllc.html.*;
0037:        import com.salmonllc.properties.Props;
0038:        import com.salmonllc.sql.*;
0039:        import com.salmonllc.util.*;
0040:
0041:        /**
0042:         * This component will iterate through a datastore and for each row in the datastore, generate html for components contained in it. The list
0043:         * can render in a table (adds formatting) or not (you have to do all the formatting). If the list renders in a table, it can be difided into
0044:         * columns for newpaper style iteration.
0045:         */
0046:        public class JspList extends JspContainer implements  ImageGenerator {
0047:
0048:            public static final String TYPE_NEWSPAPER = "NEWSPAPER";
0049:            public static final String TYPE_STRAIGHT = "STRAIGHT";
0050:
0051:            public static final String PAGE_BUTTON_STYLE_RECTANGLE = "RECTANGLE";
0052:            public static final String PAGE_BUTTON_STYLE_OVAL = "OVAL";
0053:
0054:            public static final int PAGE_BUTTON_TYPE_SUBMIT = 0;
0055:            public static final int PAGE_BUTTON_TYPE_IMAGE = 1;
0056:            public static final int PAGE_BUTTON_TYPE_TEXT = 2;
0057:
0058:            private com.salmonllc.sql.DataStoreBuffer _ds;
0059:            private HtmlComponent _submit;
0060:            private int _fieldColumns;
0061:            private String _fieldName;
0062:            private Vector _propertyExpressions;
0063:            private String _width, _colWidth;
0064:            private String _fieldType = TYPE_NEWSPAPER;
0065:            private int _border = 0, _cellPadding = 0, _cellSpacing = 0;
0066:            private String _borderColor;
0067:            private boolean _useTable = true;
0068:
0069:            private boolean _useCache = true;
0070:            private long _cacheKey = 0;
0071:            private Color _textColor = Color.black;
0072:            private Color _backgroundColor = Color.lightGray;
0073:            private Color _topLeftBorder = Color.white;
0074:            private Color _bottomRightBorder = Color.gray;
0075:            private Color _transparentColor = Color.magenta;
0076:            private String _style = PAGE_BUTTON_STYLE_RECTANGLE;
0077:            private int _pageButtonType = PAGE_BUTTON_TYPE_SUBMIT;
0078:            private int _imageHeight = 20;
0079:            private String _imageURL;
0080:            private int _rowsPerPage = 999999;
0081:            private int _firstRowOnPage = 0;
0082:            private int _maxPageButtons = 10;
0083:            private int _firstSubmitButton = 0;
0084:            private boolean _rowPerPageSel = false;
0085:            private int _newRowsPerPage = -1;
0086:            private int _oldRowsPerPage = _rowsPerPage;
0087:            private int _newStartRow = -1;
0088:            private int _newFirstButton = -1;
0089:            private boolean _scrollOnSort;
0090:            private boolean _scroll;
0091:            private String _scrollAnchor;
0092:            private String _fontString;
0093:            private int _fontSize;
0094:            private Font _buttonFont;
0095:
0096:            private DataTablePageSelectRenderer _pageSelectRenderer;
0097:            private DataTableRowsPerPageRenderer _rowsPerPageRenderer;
0098:            private String _theme;
0099:
0100:            /**
0101:             * JspList constructor comment.
0102:             */
0103:            public JspList(String name, com.salmonllc.html.HtmlPage p) {
0104:                this (name, null, p);
0105:            }
0106:
0107:            /**
0108:             * JspList constructor comment.
0109:             */
0110:            public JspList(String name, String theme,
0111:                    com.salmonllc.html.HtmlPage p) {
0112:                super (name, p);
0113:                setTheme(theme);
0114:                _imageURL = generateImageURL();
0115:            }
0116:
0117:            /**
0118:             * This method will add a property expression to the HtmlDataTable. The property expression will automatically set a property value with the results of the passed expression.
0119:             * @param comp The component to set the property for
0120:             * @param propertyName The name of the property to set. The component must have a corresponding setProperty method or this method will throw a NoSuchMethodException
0121:             * @param expEval java.lang.String The datastore evaluator that evaluates the expression
0122:             * @exception java.lang.NoSuchMethodException The exception description.
0123:             * @exception com.salmonllc.sql.DataStoreException The exception description.
0124:             */
0125:            public void addPropertyExpression(Object comp, String propertyName,
0126:                    DataStoreEvaluator expEval) throws NoSuchMethodException,
0127:                    DataStoreException {
0128:                Class c = comp.getClass();
0129:                Method m[] = c.getMethods();
0130:                Method exe = null;
0131:                String name = "set" + propertyName;
0132:                Class parms[] = null;
0133:                for (int i = 0; i < m.length; i++) {
0134:                    if (name.equalsIgnoreCase(m[i].getName())) {
0135:                        parms = m[i].getParameterTypes();
0136:                        if (parms.length == 1) {
0137:                            exe = m[i];
0138:                            break;
0139:                        }
0140:                    }
0141:                }
0142:                if (exe == null)
0143:                    throw new NoSuchMethodException(
0144:                            "Couldn't find a set method for property:"
0145:                                    + propertyName);
0146:                ThreeObjectContainer t = new ThreeObjectContainer(comp, exe,
0147:                        expEval);
0148:                if (_propertyExpressions == null)
0149:                    _propertyExpressions = new Vector();
0150:                _propertyExpressions.addElement(t);
0151:            }
0152:
0153:            /**
0154:             * This method will add a property expression to the HtmlDataTable.
0155:             * The propExpression will be evaluated by the  evaluatePropertyExpression method
0156:             * @param comp The component to set the property for
0157:             * @param propertyName The name of the property to set. The component must have a corresponding setProperty method or this method will throw a NoSuchMethodException
0158:             * @param propExpression com.salmonllc.html.PropertyExpression The instance of PropertyExpression that should do the evaluating.
0159:             * @exception java.lang.NoSuchMethodException The exception description.
0160:             * @exception com.salmonllc.sql.DataStoreException The exception description.
0161:             */
0162:            public void addPropertyExpression(Object comp, String propertyName,
0163:                    DataStoreExpression propExpression)
0164:                    throws NoSuchMethodException, DataStoreException {
0165:                DataStoreEvaluator dse = new DataStoreEvaluator(_ds,
0166:                        propExpression);
0167:                addPropertyExpression(comp, propertyName, dse);
0168:            }
0169:
0170:            /**
0171:             * This method will add a property expression to the HtmlDataTable. The property expression will automatically set a property value with the results of the passed expression.
0172:             * @param comp The component to set the property for
0173:             * @param propertyName The name of the property to set. The component must have a corresponding setProperty method or this method will throw a NoSuchMethodException
0174:             * @param expression java.lang.String The datastore expression to evaluate
0175:             * @exception java.lang.NoSuchMethodException The exception description.
0176:             * @exception com.salmonllc.sql.DataStoreException The exception description.
0177:             */
0178:            public void addPropertyExpression(Object comp, String propertyName,
0179:                    String expression) throws NoSuchMethodException,
0180:                    DataStoreException {
0181:                DataStoreEvaluator dse = new DataStoreEvaluator(_ds, expression);
0182:                addPropertyExpression(comp, propertyName, dse);
0183:            }
0184:
0185:            /**
0186:             * This method will remove all property expressions from the list
0187:             */
0188:            public void clearPropertyExpressions() {
0189:                _propertyExpressions.setSize(0);
0190:            }
0191:
0192:            /**
0193:             *Generates the Html for the component. This method is called by the framework and should not be called directly
0194:             */
0195:            public void generateHTML(TagWriter t, Vector content)
0196:                    throws java.io.IOException {
0197:
0198:                if (content == null)
0199:                    return;
0200:
0201:                if (getColumns() <= 0)
0202:                    setColumns(1);
0203:                boolean useTable = _useTable;
0204:                if (getColumns() > 1)
0205:                    useTable = true;
0206:
0207:                StringBuffer buffer = new StringBuffer();
0208:                if (!t.getDreamWeaverConv()
0209:                        && !(getPage().getContentType() != null && getPage()
0210:                                .getContentType().endsWith(".wml"))) {
0211:                    buffer.append("<a name=\"" + getName()
0212:                            + "TableStart\"></a>");
0213:                }
0214:
0215:                if (useTable) {
0216:                    buffer.append("<table");
0217:                    if (getPage().getContentType() != null
0218:                            && getPage().getContentType().endsWith(".wml"))
0219:                        buffer.append(" columns=\"" + _fieldColumns + "\"");
0220:                    if (_cellPadding != -1) {
0221:                        buffer.append(" cellpadding=\"");
0222:                        buffer.append(new Integer(_cellPadding).toString());
0223:                        buffer.append("\"");
0224:                    }
0225:                    if (_cellSpacing != -1) {
0226:                        buffer.append(" cellspacing=\"");
0227:                        buffer.append(new Integer(_cellSpacing).toString());
0228:                        buffer.append("\"");
0229:                    }
0230:                    if (_border != -1) {
0231:                        buffer.append(" border=\"");
0232:                        buffer.append(new Integer(_border).toString());
0233:                        buffer.append("\"");
0234:                    }
0235:
0236:                    if (_borderColor != null) {
0237:                        buffer.append(" bordercolor=\"");
0238:                        buffer.append(_borderColor);
0239:                        buffer.append("\"");
0240:                    }
0241:                    if (_width != null) {
0242:                        buffer.append(" width=\"");
0243:                        buffer.append(_width);
0244:                        buffer.append("\"");
0245:                    }
0246:                    buffer.append(">");
0247:                    t.print(buffer.toString(), TagWriter.TYPE_BEGIN_TAG);
0248:                } else {
0249:                    if (!t.getDreamWeaverConv()
0250:                            && !(getPage().getContentType() != null && getPage()
0251:                                    .getContentType().endsWith(".wml")))
0252:                        t.print("<a name=\"" + getName() + "TableStart\"></a>",
0253:                                TagWriter.TYPE_BEGIN_TAG);
0254:                    else
0255:                        t.print("", TagWriter.TYPE_BEGIN_TAG);
0256:                }
0257:
0258:                int columns = getColumns();
0259:                int noOfRows = (int) Math.ceil((double) content.size()
0260:                        / (double) columns);
0261:
0262:                String width = _colWidth;
0263:                if (width == null)
0264:                    width = new Integer(100 / columns).toString() + "%";
0265:
0266:                for (int rows = 0; rows < noOfRows; rows++) {
0267:                    buffer.setLength(0);
0268:                    if (useTable)
0269:                        buffer.append("<tr>");
0270:                    for (int cols = 0; cols < columns; cols++) {
0271:                        if (useTable) {
0272:                            if ((getPage()).getContentType() != null
0273:                                    && (getPage()).getContentType().endsWith(
0274:                                            ".wml"))
0275:                                buffer.append("<td>");
0276:                            else
0277:                                buffer.append("<td valign=\"top\" width=\""
0278:                                        + width + "\">");
0279:                        }
0280:
0281:                        t.print(buffer.toString(),
0282:                                TagWriter.TYPE_INSERTED_CONTENT);
0283:                        if (_fieldType.equals(TYPE_NEWSPAPER))
0284:                            t.print(getValidContent(content, (cols * noOfRows)
0285:                                    + rows), TagWriter.TYPE_CONTENT);
0286:                        else
0287:                            t.print(getValidContent(content, (rows * columns)
0288:                                    + cols), TagWriter.TYPE_CONTENT);
0289:                        buffer.setLength(0);
0290:
0291:                        if (useTable)
0292:                            buffer.append("</td>");
0293:                    }
0294:                    if (useTable)
0295:                        buffer.append("</tr>");
0296:                    t.print(buffer.toString(), TagWriter.TYPE_INSERTED_CONTENT);
0297:                }
0298:
0299:                //paging buttons
0300:                buffer.setLength(0);
0301:                int rowCount = _ds == null ? 0 : _ds.getRowCount();
0302:                int rowsPerPage = _rowsPerPage;
0303:                if (rowCount > rowsPerPage) {
0304:                    if (_pageSelectRenderer == null) {
0305:                        if (_pageButtonType == PAGE_BUTTON_TYPE_SUBMIT)
0306:                            _pageSelectRenderer = DataTablePageSelectRenderer
0307:                                    .getSubmitButtonRenderer();
0308:                        else if (_pageButtonType == PAGE_BUTTON_TYPE_IMAGE)
0309:                            _pageSelectRenderer = DataTablePageSelectRenderer
0310:                                    .getImageButtonRenderer();
0311:                        else
0312:                            _pageSelectRenderer = DataTablePageSelectRenderer
0313:                                    .getLinkRenderer();
0314:                    }
0315:                    if (useTable)
0316:                        buffer.append("<tr><td valign=\"MIDDLE\" colspan=\""
0317:                                + columns + "\">");
0318:                    int noButtons = (rowCount / rowsPerPage);
0319:                    if (rowCount % rowsPerPage > 0)
0320:                        noButtons++;
0321:                    int page = (_firstRowOnPage / rowsPerPage) + 1;
0322:                    buffer.append(_pageSelectRenderer.generateRowSelector(this ,
0323:                            _theme, "Page", "of", page, _firstSubmitButton,
0324:                            noButtons, _maxPageButtons, _imageURL));
0325:                    buffer.append("</td></tr>");
0326:                }
0327:
0328:                if (_rowPerPageSel && rowCount > _oldRowsPerPage) {
0329:                    if (_rowsPerPageRenderer == null)
0330:                        _rowsPerPageRenderer = DataTableRowsPerPageRenderer
0331:                                .getDefaultRenderer();
0332:                    if (useTable)
0333:                        buffer.append("<tr><td valign=\"MIDDLE\" colspan=\""
0334:                                + columns + "\">");
0335:                    buffer.append(_rowsPerPageRenderer.generateRowSelector(
0336:                            this , _theme, "Total Items", "Items per page",
0337:                            null, rowsPerPage, rowCount));
0338:                    buffer.append("</td></tr>");
0339:                }
0340:                if (useTable)
0341:                    buffer.append("</table>");
0342:
0343:                t.print(buffer.toString(), TagWriter.TYPE_END_TAG);
0344:                makeEnabledAndVisible();
0345:            }
0346:
0347:            /**
0348:             * Gets the border thickness for the table.
0349:             */
0350:            public int getBorder() {
0351:                return _border;
0352:            }
0353:
0354:            /**
0355:             * Gets the border color for the table.
0356:             */
0357:            public String getBorderColor() {
0358:                return _borderColor;
0359:            }
0360:
0361:            /**
0362:             * Gets the cell padding for the table.
0363:             */
0364:            public int getCellPadding() {
0365:                return _cellPadding;
0366:            }
0367:
0368:            /**
0369:             * Gets the cell spacing for the table.
0370:             */
0371:            public int getCellSpacing() {
0372:                return _cellSpacing;
0373:            }
0374:
0375:            /**
0376:             * Returns the number of columns used in the list
0377:             */
0378:            public int getColumns() {
0379:                return _fieldColumns;
0380:            }
0381:
0382:            /**
0383:             * Returns the DataStoreBuffer used by the list
0384:             */
0385:            public com.salmonllc.sql.DataStoreBuffer getDataStore() {
0386:                return _ds;
0387:            }
0388:
0389:            /**
0390:             * Returns the name of the list
0391:             */
0392:            public java.lang.String getName() {
0393:                return _fieldName;
0394:            }
0395:
0396:            /**
0397:             * Returns the type of the list, used for sorting columns: TYPE_NEWSPAPER or TYPE_STRAIGHT
0398:             */
0399:            public java.lang.String getType() {
0400:                return _fieldType;
0401:            }
0402:
0403:            /**
0404:             * gets whether or not the component will us a table to generate it's html
0405:             */
0406:            public boolean getUseTable() {
0407:                return _useTable;
0408:            }
0409:
0410:            private String getValidContent(Vector content, int position) {
0411:
0412:                if (position > content.size() - 1) {
0413:                    return "";
0414:                }
0415:                return (String) content.elementAt(position);
0416:            }
0417:
0418:            private void makeEnabledAndVisible() {
0419:                if (_propertyExpressions == null)
0420:                    return;
0421:                //sr 10-15-2000
0422:                int propertyExpressionsSize = _propertyExpressions.size();
0423:                ThreeObjectContainer c = null;
0424:                Object comp = null;
0425:                Method meth = null;
0426:                //
0427:                for (int i = 0; i < propertyExpressionsSize; i++) {
0428:                    c = (ThreeObjectContainer) _propertyExpressions
0429:                            .elementAt(i);
0430:                    comp = c.getObject1();
0431:                    meth = (Method) c.getObject2();
0432:                    Object[] res = new Object[1];
0433:                    res[0] = new Boolean(true);
0434:                    //
0435:                    try {
0436:                        if (meth.getName().equals("setVisible")
0437:                                || meth.getName().equals("setEnabled"))
0438:                            meth.invoke(comp, res);
0439:                    } catch (Exception e) {
0440:                        MessageLog.writeErrorMessage("makeEnabledAndVisible()",
0441:                                e, this );
0442:                    }
0443:                }
0444:            }
0445:
0446:            /**
0447:             * This method will process the parms from a post for every component in the container.
0448:             */
0449:            public boolean processParms(Hashtable parms, int rowNo)
0450:                    throws Exception {
0451:                String compName = null;
0452:                try {
0453:
0454:                    if (!getVisible())
0455:                        return false;
0456:
0457:                    int rowCount = _ds.getRowCount();
0458:                    for (int j = 0; j < rowCount; j++) {
0459:                        for (int i = 0; i < getComponentCount(); i++) {
0460:                            if (getComponentType(i) != TYPE_ROW) {
0461:                                HtmlComponent h = getComponent(i);
0462:                                if (h != null)
0463:                                    if (h.processParms(parms, j))
0464:                                        _submit = h;
0465:                            }
0466:                        }
0467:                    }
0468:
0469:                    int noButtons = rowCount / _rowsPerPage;
0470:                    if (rowCount % _rowsPerPage > 0)
0471:                        noButtons++;
0472:
0473:                    Object rpp = parms.get(getFullName()
0474:                            + "_rows_per_page_hidden");
0475:                    if (rpp != null) {
0476:                        String val = ((String[]) rpp)[0];
0477:                        if (val.equals("1")) {
0478:                            rpp = parms.get(getFullName() + "row_per_page_dd");
0479:                            _newRowsPerPage = new Integer(((String[]) rpp)[0])
0480:                                    .intValue();
0481:                            _submit = this ;
0482:                        } else if (!val.equals("-1")) {
0483:                            _newRowsPerPage = new Integer(val).intValue();
0484:                            _submit = this ;
0485:                        }
0486:                    }
0487:
0488:                    String[] pageSubmitA = (String[]) parms.get(getFullName()
0489:                            + "_page_selector");
0490:                    String pageSubmit = "";
0491:                    if (pageSubmitA != null)
0492:                        pageSubmit = pageSubmitA[0];
0493:
0494:                    _newStartRow = -1;
0495:                    _newFirstButton = -1;
0496:                    if (parms.get(getFullName() + "_page_first") != null
0497:                            || parms.get(getFullName() + "_page_first.x") != null
0498:                            || pageSubmit.equals("first")) {
0499:                        _newFirstButton = 0;
0500:                        _newStartRow = 0;
0501:                        _submit = this ;
0502:                    } else if (parms.get(getFullName() + "_page_prior") != null
0503:                            || parms.get(getFullName() + "_page_prior.x") != null
0504:                            || pageSubmit.equals("prior")) {
0505:                        _newFirstButton = _firstSubmitButton
0506:                                - (_maxPageButtons == 0 ? 1 : _maxPageButtons);
0507:                        _submit = this ;
0508:                        if (_newFirstButton < 0)
0509:                            _newFirstButton = 0;
0510:                        _newStartRow = _rowsPerPage
0511:                                * (_newFirstButton
0512:                                        + (_maxPageButtons == 0 ? 1
0513:                                                : _maxPageButtons) - 1);
0514:                    } else if (parms.get(getFullName() + "_page_next") != null
0515:                            || parms.get(getFullName() + "_page_next.x") != null
0516:                            || pageSubmit.equals("next")) {
0517:                        _newFirstButton = _firstSubmitButton
0518:                                + (_maxPageButtons == 0 ? 1 : _maxPageButtons);
0519:                        _submit = this ;
0520:                        if ((_newFirstButton + _maxPageButtons) >= noButtons)
0521:                            _newFirstButton = (noButtons - (_maxPageButtons == 0 ? 1
0522:                                    : _maxPageButtons));
0523:                        _newStartRow = _rowsPerPage * _newFirstButton;
0524:                    } else if (parms.get(getFullName() + "_page_last") != null
0525:                            || parms.get(getFullName() + "_page_last.x") != null
0526:                            || pageSubmit.equals("last")) {
0527:                        _submit = this ;
0528:                        _newFirstButton = (noButtons - (_maxPageButtons == 0 ? 1
0529:                                : _maxPageButtons));
0530:                        _newStartRow = _rowsPerPage * _newFirstButton;
0531:                        if (_newStartRow < 0)
0532:                            _newStartRow = 0;
0533:                    } else if (!pageSubmit.equals("")) {
0534:                        _newStartRow = _rowsPerPage
0535:                                * Integer.parseInt(pageSubmit);
0536:                        _submit = this ;
0537:                    } else {
0538:                        for (int i = _firstSubmitButton; (i < noButtons)
0539:                                && ((i - _firstSubmitButton) < _maxPageButtons); i++) {
0540:                            if (parms.get(getFullName() + "_page_" + i) != null
0541:                                    || parms.get(getFullName() + "_page_" + i
0542:                                            + ".x") != null) {
0543:                                _newStartRow = _rowsPerPage * i;
0544:                                _submit = this ;
0545:                                break;
0546:                            }
0547:                        }
0548:                    }
0549:
0550:                    //
0551:                    if (_submit == null) {
0552:                        _scroll = false;
0553:                        return false;
0554:                    } else {
0555:                        _scroll = _scrollOnSort;
0556:                        return true;
0557:                    }
0558:
0559:                } catch (Exception e) {
0560:                    MessageLog.writeErrorMessage("processParms for " + compName
0561:                            + "\n", e, this );
0562:                    throw (e);
0563:                }
0564:            }
0565:
0566:            public void processPropertyExpressions(int row) {
0567:                if (_propertyExpressions == null)
0568:                    return;
0569:
0570:                ThreeObjectContainer c = null;
0571:                Object comp = null;
0572:                Method meth = null;
0573:                DataStoreEvaluator eval = null;
0574:
0575:                //
0576:                int propertyExpressionsSize = _propertyExpressions.size();
0577:                for (int i = 0; i < propertyExpressionsSize; i++) {
0578:                    c = (ThreeObjectContainer) _propertyExpressions
0579:                            .elementAt(i);
0580:                    comp = c.getObject1();
0581:                    meth = (Method) c.getObject2();
0582:                    eval = (DataStoreEvaluator) c.getObject3();
0583:                    HtmlPage.executePropertyMethod(comp, meth, eval, row);
0584:                }
0585:            }
0586:
0587:            /**
0588:             * Sets the border for the table.
0589:             */
0590:            public void setBorder(int border) {
0591:                _border = border;
0592:            }
0593:
0594:            /**
0595:             * Sets the border color for the table.
0596:             */
0597:            public void setBorderColor(String value) {
0598:                _borderColor = value;
0599:            }
0600:
0601:            /**
0602:             * Sets the cell padding for the table.
0603:             */
0604:            public void setCellPadding(int value) {
0605:                _cellPadding = value;
0606:            }
0607:
0608:            /**
0609:             * Sets the cell spacing for the table.
0610:             */
0611:            public void setCellSpacing(int value) {
0612:                _cellSpacing = value;
0613:            }
0614:
0615:            /**
0616:             * Sets the number of columns used to present this list
0617:             */
0618:            public void setColumns(int newColumns) {
0619:                _fieldColumns = newColumns;
0620:            }
0621:
0622:            /**
0623:             * Sets the width of each column in the list (multicolumn lists only)
0624:             */
0625:            public void setColumnWidth(java.lang.String width) {
0626:                _colWidth = width;
0627:            }
0628:
0629:            /**
0630:             * Sets the datastore that the list will iterate through to display its data
0631:             */
0632:            public void setDataStore(
0633:                    com.salmonllc.sql.DataStoreBuffer newDataStore) {
0634:                _ds = newDataStore;
0635:            }
0636:
0637:            /**
0638:             * Sets the name of the component
0639:             */
0640:            public void setName(java.lang.String newName) {
0641:                _fieldName = newName;
0642:            }
0643:
0644:            /**
0645:             * Sets the type of list for sorting purposes: TYPE_NEWSPAPER or TYPE_STRAIGHT. Newspaper will sort down then across, straight will sort across then down
0646:             */
0647:            public void setType(String newType) {
0648:                if (newType != null
0649:                        && (newType.toUpperCase().equals(TYPE_NEWSPAPER) || newType
0650:                                .toUpperCase().equals(TYPE_STRAIGHT)))
0651:                    _fieldType = newType;
0652:            }
0653:
0654:            /**
0655:             * Sets whether or not the component will us a table to generate it's html
0656:             */
0657:            public void setUseTable(boolean useTable) {
0658:                _useTable = useTable;
0659:            }
0660:
0661:            /**
0662:             * Sets the width of the list
0663:             */
0664:            public void setWidth(java.lang.String width) {
0665:                _width = width;
0666:            }
0667:
0668:            /**
0669:             * Sets a new render to draw the HTML for the table page selector
0670:             */
0671:            public void setPageSelectRenderer(DataTablePageSelectRenderer r) {
0672:                _pageSelectRenderer = r;
0673:            }
0674:
0675:            /**
0676:             * Sets a new render to draw the HTML for the rows per page selector
0677:             */
0678:            public void setRowsPerPageRenderer(DataTableRowsPerPageRenderer r) {
0679:                _rowsPerPageRenderer = r;
0680:            }
0681:
0682:            /**
0683:             * Sets a new render to draw the HTML for the table page selector, given the class name for the renderer
0684:             */
0685:            public void setPageSelectRenderer(String r) {
0686:                if (r != null) {
0687:                    if (r.equalsIgnoreCase("null")
0688:                            || r.equalsIgnoreCase("default")) {
0689:                        _pageSelectRenderer = null;
0690:                        return;
0691:                    }
0692:                }
0693:
0694:                try {
0695:                    Class c = Class.forName(r);
0696:                    _pageSelectRenderer = (DataTablePageSelectRenderer) c
0697:                            .newInstance();
0698:                } catch (Exception e) {
0699:                    MessageLog.writeErrorMessage("setRowSelectRenderer", e,
0700:                            this );
0701:                }
0702:            }
0703:
0704:            /**
0705:             * Sets a new render to draw the HTML for the rows per page selector
0706:             */
0707:            public void setRowsPerPageRenderer(String r) {
0708:                if (r != null) {
0709:                    if (r.equalsIgnoreCase("null")
0710:                            || r.equalsIgnoreCase("default")) {
0711:                        _rowsPerPageRenderer = null;
0712:                        return;
0713:                    }
0714:                }
0715:                try {
0716:                    Class c = Class.forName(r);
0717:                    _rowsPerPageRenderer = (DataTableRowsPerPageRenderer) c
0718:                            .newInstance();
0719:                } catch (Exception e) {
0720:                    MessageLog.writeErrorMessage("setRowsPerPageRenderer", e,
0721:                            this );
0722:                }
0723:            }
0724:
0725:            /**
0726:             * Returns the first row on the page displayed in the datatable.
0727:             */
0728:            public int getFirstRowOnPage() {
0729:                return _firstRowOnPage;
0730:            }
0731:
0732:            /**
0733:             * This method returns the page the row is on.
0734:             */
0735:            public int getPage(int row) {
0736:                return row / _rowsPerPage;
0737:            }
0738:
0739:            /**
0740:             * 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
0741:             **/
0742:
0743:            public int getPageButtonType() {
0744:                return _pageButtonType;
0745:            }
0746:
0747:            /**
0748:             * This method returns the background color of paging button images
0749:             */
0750:            public Color getPagingButtonBackgroundColor() {
0751:                return _backgroundColor;
0752:            }
0753:
0754:            /**
0755:             * This method returns the bottom right border color of paging button images
0756:             */
0757:            public Color getPagingButtonBottomRightColor() {
0758:                return _bottomRightBorder;
0759:            }
0760:
0761:            /**
0762:             * This method gets the Display Style for a generated page button image. Valid Values are PAGE_BUTTON_STYLE_RECTANGLE and PAGE_BUTTON_STYLE_OVAL
0763:             */
0764:            public String getPagingButtonDisplayStyle() {
0765:                return _style;
0766:            }
0767:
0768:            /**
0769:             * This method returns the font used for page button images
0770:             */
0771:            public Font getPagingButtonFont() {
0772:                if (_buttonFont == null)
0773:                    _buttonFont = new Font(_fontString, 0, _fontSize);
0774:                return _buttonFont;
0775:            }
0776:
0777:            /**
0778:             * This method returns the height used for page button images
0779:             */
0780:            public int getPagingButtonHeight() {
0781:                return _imageHeight;
0782:            }
0783:
0784:            /**
0785:             * This method returns the text color of page button images
0786:             */
0787:            public Color getPagingButtonTextColor() {
0788:                return _textColor;
0789:            }
0790:
0791:            /**
0792:             * 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.
0793:             */
0794:            public int getRowsPerPage() {
0795:                return _rowsPerPage;
0796:            }
0797:
0798:            /**
0799:             * Returns true if rows per page selector is visible.
0800:             */
0801:            public boolean getSelRowsPerPage() {
0802:                return _rowPerPageSel;
0803:            }
0804:
0805:            public boolean getUseCache() {
0806:                return _useCache;
0807:            }
0808:
0809:            /**
0810:             * This method returns true if the specified row is on the current page.
0811:             */
0812:            public boolean isRowOnPage(int row) {
0813:                int pageNo = row / _rowsPerPage;
0814:                int currentPage = _firstRowOnPage / _rowsPerPage;
0815:
0816:                return pageNo == currentPage;
0817:            }
0818:
0819:            public void generateImage(String img, OutputStream out)
0820:                    throws IOException {
0821:                //create an image to draw
0822:                ImageFactory fact = new ImageFactory();
0823:                Image i = null;
0824:
0825:                String source = img;
0826:                if (img.equals("first"))
0827:                    source = "<<";
0828:                else if (img.equals("last"))
0829:                    source = ">>";
0830:                else if (img.equals("next"))
0831:                    source = ">";
0832:                else if (img.equals("prior"))
0833:                    source = "<";
0834:                else
0835:                    source = new Integer((Integer.parseInt(img) + 1))
0836:                            .toString();
0837:
0838:                if (_style.equals(PAGE_BUTTON_STYLE_OVAL))
0839:                    i = fact.createOvalButton(_imageHeight,
0840:                            getPagingButtonFont(), source, _textColor,
0841:                            _backgroundColor, _topLeftBorder,
0842:                            _bottomRightBorder, _transparentColor, false,
0843:                            _enabled);
0844:                else
0845:                    i = fact.createRectangleButton(_imageHeight,
0846:                            getPagingButtonFont(), source, _textColor,
0847:                            _backgroundColor, _topLeftBorder,
0848:                            _bottomRightBorder, false, _enabled);
0849:
0850:                GifEncoder g = new GifEncoder(i, out, true, _transparentColor);
0851:                g.encode();
0852:
0853:            }
0854:
0855:            /**
0856:             * 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.
0857:             */
0858:            public void setCacheKey(long key) {
0859:                _cacheKey = key;
0860:            }
0861:
0862:            /**
0863:             * This method sets the first row displayed on the current page.
0864:             */
0865:            public void setFirstRowOnPage(int firstRowOnPage) {
0866:                _firstRowOnPage = firstRowOnPage;
0867:            }
0868:
0869:            /**
0870:             * This method sets the maximum number of paging buttons to display.
0871:             */
0872:            public void setMaxPageButtons(int max) {
0873:                _maxPageButtons = max;
0874:            }
0875:
0876:            /**
0877:             * Sets the maximum number of paging buttons for the table.
0878:             */
0879:            public void setMaxPagingButtons(int max) {
0880:                _maxPageButtons = max;
0881:            }
0882:
0883:            /**
0884:             * This method will scroll to the first row on the current selected page
0885:             */
0886:            public void setPage(int page) {
0887:                _firstRowOnPage = page * _rowsPerPage;
0888:                if (_maxPageButtons == 0)
0889:                    _firstSubmitButton = page;
0890:            }
0891:
0892:            /**
0893:             * 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
0894:             **/
0895:
0896:            public void setPageButtonType(int type) {
0897:                _pageButtonType = type;
0898:                if (_pageButtonType == PAGE_BUTTON_TYPE_IMAGE)
0899:                    ;
0900:                getPage().registerImageGenerator(getFullName(), this );
0901:
0902:            }
0903:
0904:            /**
0905:             * This method sets the background color for the page button generated image
0906:             */
0907:            public void setPagingButtonBackgroundColor(Color c) {
0908:                _backgroundColor = c;
0909:            }
0910:
0911:            /**
0912:             * This method sets the bottom and right border color for the page button generated image
0913:             */
0914:            public void setPagingButtonBottomRightColor(Color c) {
0915:                _bottomRightBorder = c;
0916:            }
0917:
0918:            /**
0919:             * This method sets the Display Style for a generated image button. Valid Values are PAGE_BUTTON_STYLE_RECTANGLE and PAGE_BUTTON_STYLE_OVAL
0920:             */
0921:            public void setPagingButtonDisplayStyle(String style) {
0922:                _style = style;
0923:            }
0924:
0925:            /**
0926:             * This method sets the font used for dynamically generated page button images.
0927:             */
0928:            public void setPagingButtonFont(Font f) {
0929:                _buttonFont = f;
0930:            }
0931:
0932:            /**
0933:             * This method sets the height used for page button images
0934:             */
0935:            public void setPagingButtonHeight(int height) {
0936:                _imageHeight = height;
0937:            }
0938:
0939:            /**
0940:             * 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.
0941:             */
0942:            public void setRowsPerPage(int rowsPerPage) {
0943:                _rowsPerPage = rowsPerPage;
0944:                _oldRowsPerPage = rowsPerPage;
0945:            }
0946:
0947:            /**
0948:             * 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.
0949:             */
0950:            public void setScrollAnchor(String anchor) {
0951:                _scrollAnchor = anchor;
0952:            }
0953:
0954:            /**
0955:             * Sets whether the list will build scrolling javascript when the user clicks on paging button.
0956:             */
0957:            public void setScrollOnPaging(boolean scroll) {
0958:                _scrollOnSort = scroll;
0959:            }
0960:
0961:            /**
0962:             * Sets whether rows per page selector is visible.
0963:             */
0964:            public void setSelRowsPerPage(boolean sel) {
0965:                _rowPerPageSel = sel;
0966:            }
0967:
0968:            public long getCacheKey() {
0969:                return _cacheKey;
0970:            }
0971:
0972:            /**
0973:             * 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.
0974:             */
0975:            public String getScrollAnchor() {
0976:                return _scrollAnchor;
0977:            }
0978:
0979:            /**
0980:             * Gets whether the build scrolling javascript when the user clicks on a paging button.
0981:             */
0982:            public boolean getScrollOnPaging() {
0983:                return _scrollOnSort;
0984:            }
0985:
0986:            /**
0987:             * This method sets the property theme for the component.
0988:             * @param theme The theme to use.
0989:             */
0990:            public void setTheme(String theme) {
0991:
0992:                Props prop = getPage().getPageProperties();
0993:
0994:                _scrollOnSort = prop.getThemeBooleanProperty(theme,
0995:                        Props.DATA_TABLE_SCROLL_ON_CLICK_SORT, true);
0996:                _maxPageButtons = -1;
0997:                prop.getThemeIntProperty(theme,
0998:                        Props.DATA_TABLE_MAX_PAGE_BUTTONS);
0999:                if (_maxPageButtons <= 0)
1000:                    _maxPageButtons = 10;
1001:
1002:                // rows per page
1003:                _oldRowsPerPage = _rowsPerPage;
1004:
1005:                //properties for paging buttons
1006:                _fontString = prop.getThemeProperty(theme,
1007:                        Props.SUBMIT_IMAGE_FONT_FACE);
1008:                if (_fontString == null)
1009:                    _fontString = "Helvetica";
1010:                _fontSize = prop.getThemeIntProperty(theme,
1011:                        Props.SUBMIT_IMAGE_FONT_SIZE);
1012:                if (_fontSize == -1)
1013:                    _fontSize = 12;
1014:
1015:                _imageHeight = prop.getThemeIntProperty(theme,
1016:                        Props.SUBMIT_IMAGE_DEFAULT_HEIGHT);
1017:
1018:                Color c = prop.getThemeColorProperty(theme,
1019:                        Props.SUBMIT_IMAGE_TEXT_COLOR);
1020:                if (c != null)
1021:                    _textColor = c;
1022:
1023:                c = prop.getThemeColorProperty(theme,
1024:                        Props.SUBMIT_IMAGE_BACKGROUND_COLOR);
1025:                if (c != null)
1026:                    _backgroundColor = c;
1027:
1028:                c = prop.getThemeColorProperty(theme,
1029:                        Props.SUBMIT_IMAGE_TOPLEFT_BORDER_COLOR);
1030:                if (c != null)
1031:                    _topLeftBorder = c;
1032:
1033:                c = prop.getThemeColorProperty(theme,
1034:                        Props.SUBMIT_IMAGE_BOTTOMRIGHT_BORDER_COLOR);
1035:                if (c != null)
1036:                    _bottomRightBorder = c;
1037:
1038:                c = prop.getThemeColorProperty(theme,
1039:                        Props.SUBMIT_IMAGE_TRANSPARENT_COLOR);
1040:                if (c != null)
1041:                    _transparentColor = c;
1042:
1043:                String style = prop.getThemeProperty(theme,
1044:                        Props.SUBMIT_IMAGE_STYLE);
1045:                if (style != null) {
1046:                    if (style.toUpperCase().equals(PAGE_BUTTON_STYLE_OVAL))
1047:                        _style = PAGE_BUTTON_STYLE_OVAL;
1048:                    else
1049:                        _style = PAGE_BUTTON_STYLE_RECTANGLE;
1050:                }
1051:
1052:                String rowSelectRenderer = prop.getThemeProperty(theme,
1053:                        Props.DATA_TABLE_PAGE_SELECT_RENDERER);
1054:                if (rowSelectRenderer != null)
1055:                    setPageSelectRenderer(rowSelectRenderer);
1056:
1057:                String rowsPerPageRenderer = prop.getThemeProperty(theme,
1058:                        Props.DATA_TABLE_ROWS_PER_PAGE_RENDERER);
1059:                if (rowsPerPageRenderer != null)
1060:                    setRowsPerPageRenderer(rowsPerPageRenderer);
1061:
1062:                _theme = theme;
1063:            }
1064:
1065:            public boolean executeEvent(int eventType) throws Exception {
1066:                if (eventType == HtmlComponent.EVENT_OTHER) {
1067:                    for (int i = 0; i < getComponentCount(); i++) {
1068:                        HtmlComponent h = getComponent(i);
1069:                        if (!h.executeEvent(eventType))
1070:                            return false;
1071:                    }
1072:                } else if (_submit != null
1073:                        && eventType == HtmlComponent.EVENT_SUBMIT) {
1074:                    if (_submit == this ) {
1075:                        if (_newRowsPerPage > -1) {
1076:                            _rowsPerPage = _newRowsPerPage;
1077:                            _firstSubmitButton = 0;
1078:                            _firstRowOnPage = 0;
1079:                            _newRowsPerPage = -1;
1080:                        }
1081:
1082:                        if (_newStartRow > -1)
1083:                            _firstRowOnPage = _newStartRow;
1084:                        if (_newFirstButton > -1)
1085:                            _firstSubmitButton = _newFirstButton;
1086:
1087:                        _submit = null;
1088:                        if (_scroll) {
1089:                            if (_scrollAnchor != null)
1090:                                getPage().scrollToItem(_scrollAnchor);
1091:                            else
1092:                                getPage()
1093:                                        .scrollToItem(getName() + "TableStart");
1094:                            _scroll = false;
1095:                        }
1096:                    } else {
1097:                        boolean retVal = _submit.executeEvent(eventType);
1098:                        _submit = null;
1099:                        return retVal;
1100:                    }
1101:                }
1102:                return true;
1103:            }
1104:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.