Source Code Cross Referenced for HtmlLookUpComponent.java in  » J2EE » Sofia » com » salmonllc » html » 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.html 
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.html;
0021:
0022:        /////////////////////////
0023:        //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlLookUpComponent.java $
0024:        //$Author: Dan $
0025:        //$Revision: 39 $
0026:        //$Modtime: 11/01/04 2:46p $
0027:        /////////////////////////
0028:
0029:        import java.io.PrintWriter;
0030:        import java.util.Vector;
0031:
0032:        import com.salmonllc.properties.Props;
0033:        import com.salmonllc.sql.DataStore;
0034:        import com.salmonllc.sql.DataStoreBuffer;
0035:        import com.salmonllc.sql.DataStoreEvaluator;
0036:        import com.salmonllc.sql.DataStoreException;
0037:        import com.salmonllc.sql.DataStoreExpression;
0038:        import com.salmonllc.util.MessageLog;
0039:
0040:        import com.salmonllc.html.events.*;
0041:        import com.salmonllc.jsp.JspController;
0042:        import com.salmonllc.jsp.Constants;
0043:        import com.salmonllc.jsp.JspDataTable;
0044:        import com.salmonllc.jsp.JspList;
0045:
0046:        import javax.servlet.http.HttpServletRequest;
0047:        import javax.servlet.http.HttpServletResponse;
0048:
0049:        /**
0050:         * This class implements a lookup component. It has an edit field and a zoom
0051:         * component to zoom to a list of possible values.
0052:         */
0053:        public class HtmlLookUpComponent extends HtmlComposite implements 
0054:                PageListener, SubmitListener {
0055:            protected DataStoreBuffer _ds = null;
0056:
0057:            private DataStoreBuffer _descDs;
0058:
0059:            /** reference to the edit box in the lookup comp */
0060:            private Object _editHandle;
0061:
0062:            private HtmlSubmitImage _browseImage;
0063:
0064:            private HtmlLink _browsePopupImageLink;
0065:
0066:            private HtmlImage _browsePopupImage;
0067:
0068:            private Object _browsePopupImageHandle;
0069:
0070:            private int _popupWidth = 300;
0071:
0072:            private int _popupHeight = 300;
0073:
0074:            private String _font;
0075:
0076:            private String _fontStartTag;
0077:
0078:            private String _fontEndTag;
0079:
0080:            private boolean _showDescription = true;
0081:
0082:            private boolean _editDescription = false;
0083:
0084:            private DataStoreEvaluator _descriptionEval;
0085:
0086:            private int _descriptionColumn = -1;
0087:
0088:            private String _descriptionDataSource;
0089:
0090:            /** reference to the browse image lookup comp */
0091:            private Object _browseImageHandle;
0092:
0093:            protected String _lookUpPageURL;
0094:
0095:            /** reference to the hidden description lookup comp */
0096:            private HtmlHiddenField _hiddenDescriptionHandle;
0097:
0098:            /**
0099:             * reference to a hidden field containing the key, used if _editDescription
0100:             * is true
0101:             */
0102:            private HtmlHiddenField _hiddenKeyHandle;
0103:            protected int _rowNo = -1;
0104:
0105:            protected String _extraParms;
0106:
0107:            private boolean _usePopup = false;
0108:            private boolean _useDiv = false;
0109:            private String _divBorderStyle = null;
0110:            private boolean _divScrolling = false;
0111:
0112:            /* Claudio Pi - 5/25/04 Added for modal popup windows */
0113:            private boolean _useModal = false;
0114:
0115:            /* Claudio Pi - 6/28/04 Added popup position */
0116:            private int _popupLeft = 0;
0117:
0118:            private int _popupTop = 0;
0119:
0120:            private String _popupPosition = Constants.POPUP_POSITION_CUSTOM;
0121:
0122:            public static final String PARAM_LISTFORM_SEARCH_FILTER_STRING = "ListFormSearchFilterString";
0123:
0124:            public static final String PARAM_LOOKUP_COMPONENT = "LookupComponentParam";
0125:
0126:            public static final String PARAM_LOOKUP_CONTROLLER = "LookupComponentControllerParam";
0127:
0128:            public static final String PARAM_LOOKUP_ROW = "LookupComponentRowParam";
0129:
0130:            public static final String PARAM_LOOKUP_VALUE = "LookupComponentRowValue";
0131:
0132:            private String _popupAttributes;
0133:
0134:            private Vector _popupURLLineValues;
0135:
0136:            private class FormComponentInfo {
0137:                String compName;
0138:                String attName;
0139:                boolean isInDataTable;
0140:            }
0141:
0142:            /**
0143:             * LookUp constructor.
0144:             * 
0145:             * @param name -
0146:             *            name of component
0147:             * @param p -
0148:             *            page the component will be associated with
0149:             */
0150:            public HtmlLookUpComponent(String name, HtmlPage p) {
0151:                this (name, null, p);
0152:
0153:            }
0154:
0155:            /**
0156:             * LookUp constructor.
0157:             * 
0158:             * @param name -
0159:             *            name of component
0160:             * @param lookup_page -
0161:             *            the page that will provide the lookup values
0162:             * @param p -
0163:             *            page the component will be associated with
0164:             */
0165:            public HtmlLookUpComponent(String name, String lookup_page,
0166:                    HtmlPage p) {
0167:                this (name, lookup_page, "../../Objectstore/Images/Browse.GIF",
0168:                        p);
0169:            }
0170:
0171:            /**
0172:             * LookUp constructor.
0173:             * 
0174:             * @param name -
0175:             *            name of component
0176:             * @param lookup_page -
0177:             *            the page that will provide the lookup values
0178:             * @param ds -
0179:             *            DataStore that is being used with this component
0180:             * @param tableName -
0181:             *            table name to bind to
0182:             * @param columnName -
0183:             *            column name to bind to
0184:             * @param dataType -
0185:             *            data type of the main edit field ( use DataStore.DATATYPE_*)
0186:             * @param pKey -
0187:             *            flag that signifies if the column is a primary key column
0188:             * @param p -
0189:             *            page the component will be associated with
0190:             */
0191:            public HtmlLookUpComponent(String name, String lookup_page,
0192:                    DataStore ds, String tableName, String columnName,
0193:                    int dataType, boolean pKey, HtmlPage p) { //	 HtmlLookUpComponent(String
0194:                // name,
0195:                // String
0196:                // lookup_page, String browseImage, DataStore ds,
0197:                // String tableName, String columnName, int dataType,
0198:                // boolean pKey, HtmlPage p)
0199:                this (name, lookup_page, "../../Objectstore/Images/Browse.GIF",
0200:                        ds, tableName, columnName, dataType, pKey, p);
0201:            }
0202:
0203:            /**
0204:             * LookUp constructor.
0205:             * 
0206:             * @param name -
0207:             *            name of component
0208:             * @param lookup_page -
0209:             *            the page that will provide the lookup values
0210:             * @param browseImage -
0211:             *            the browse image to use. default is a magnifying glass
0212:             * @param p -
0213:             *            page the component will be associated with
0214:             */
0215:            public HtmlLookUpComponent(String name, String lookup_page,
0216:                    String browseImage, HtmlPage p) {
0217:                //	 HtmlLookUpComponent(String name, String lookup_page, String
0218:                // browseImage, DataStore ds, String tableName, String columnName, int
0219:                // dataType, boolean pKey, HtmlPage p)
0220:                this (name, lookup_page, browseImage, null, null, null,
0221:                        DataStore.DATATYPE_INT, false, p);
0222:            }
0223:
0224:            /**
0225:             * LookUp constructor.
0226:             * 
0227:             * @param name -
0228:             *            name of component
0229:             * @param lookup_page -
0230:             *            the page that will provide the lookup values
0231:             * @param browseImage -
0232:             *            the browse image to use. default is a magnifying glass
0233:             * @param ds -
0234:             *            DataStore that is being used with this component
0235:             * @param tableName -
0236:             *            table name to bind to
0237:             * @param columnName -
0238:             *            column name to bind to
0239:             * @param dataType -
0240:             *            data type of the main edit field ( use DataStore.DATATYPE_*)
0241:             * @param pKey -
0242:             *            flag that signifies if the column is a primary key column
0243:             * @param p -
0244:             *            page the component will be associated with
0245:             */
0246:            public HtmlLookUpComponent(String name, String lookup_page,
0247:                    String browseImage, DataStore ds, String tableName,
0248:                    String columnName, int dataType, boolean pKey, HtmlPage p) {
0249:                super (name, p);
0250:
0251:                _hiddenDescriptionHandle = new HtmlHiddenField("hiddenDescr",
0252:                        null, p);
0253:                addCompositeComponent(_hiddenDescriptionHandle,
0254:                        DataStore.DATATYPE_STRING, false, null, null);
0255:                _hiddenKeyHandle = new HtmlHiddenField("hiddenKey", null, p);
0256:                addCompositeComponent(_hiddenKeyHandle,
0257:                        DataStore.DATATYPE_STRING, false, null, null);
0258:                _hiddenKeyHandle.setVisible(false);
0259:
0260:                setTheme(null);
0261:                p.addPageListener(this );
0262:
0263:                HtmlTextEdit edit = null;
0264:
0265:                if (ds == null) {
0266:                    edit = new HtmlTextEdit("_edit", p);
0267:                    _editHandle = addCompositeComponent(edit, dataType, false,
0268:                            null, null);
0269:                } else {
0270:                    _ds = ds;
0271:                    /** Don't add the same column twice to the data store. */
0272:                    if (_ds.getColumnIndex(tableName + "." + columnName) == -1) {
0273:                        if (_ds instanceof  DataStore)
0274:                            ((DataStore) _ds).addColumn(tableName, columnName,
0275:                                    dataType, pKey, true);
0276:                    }
0277:                    edit = new HtmlTextEdit(tableName + "_" + columnName, p);
0278:                    edit.setColumn(_ds, tableName + "." + columnName);
0279:
0280:                    _editHandle = addCompositeComponent(edit, dataType, true,
0281:                            tableName, columnName);
0282:                }
0283:
0284:                _browseImage = new HtmlSubmitImage("browseImage", browseImage,
0285:                        p);
0286:                _browseImage.addSubmitListener(this );
0287:                _browseImageHandle = addCompositeComponent(_browseImage,
0288:                        DATATYPE_ANY, false, null, null);
0289:
0290:                _browsePopupImage = new HtmlImage("browsPopupImage",
0291:                        browseImage, p);
0292:                _browsePopupImageLink = new HtmlLink("browsePopupImageLink",
0293:                        null, p);
0294:                _browsePopupImageLink.add(_browsePopupImage);
0295:                _browseImageHandle = addCompositeComponent(
0296:                        _browsePopupImageLink, DATATYPE_ANY, false, null, null);
0297:                _browsePopupImageLink.setVisible(false);
0298:
0299:                setLookUpPageURL(lookup_page);
0300:                setDescriptionFont(null);
0301:            }
0302:
0303:            /**
0304:             * Do not use this method in this class.
0305:             */
0306:            public void add(HtmlComponent comp) {
0307:                try {
0308:                    throw new Exception(
0309:                            " DO NOT USE: HtmlLookUpComponent.add. Use addLookupComp instead");
0310:                } catch (Exception e) {
0311:                    MessageLog
0312:                            .writeErrorMessage(
0313:                                    " DO NOT USE: HtmlLookUpComponent.add. Use addLookupComp instead",
0314:                                    e, this );
0315:                }
0316:            }
0317:
0318:            /**
0319:             * This method returns the browse image
0320:             * 
0321:             * @return HtmlTextEdit
0322:             */
0323:            public HtmlSubmitImage getBrowseImage() {
0324:                try {
0325:
0326:                    /** get the index of the browse image so we can replace it */
0327:                    int browseIndex = _componentsVec
0328:                            .indexOf(_browseImageHandle);
0329:                    if (browseIndex != -1) {
0330:                        return (HtmlSubmitImage) _componentsVec
0331:                                .elementAt(browseIndex);
0332:                    }
0333:                } catch (Exception e) {
0334:                    MessageLog.writeErrorMessage("getBrowseImage", e, this );
0335:                }
0336:                return null;
0337:            }
0338:
0339:            /**
0340:             * This method returns the edit filed
0341:             * 
0342:             * @return HtmlTextEdit
0343:             */
0344:            public HtmlTextEdit getEditField() {
0345:                try {
0346:
0347:                    /** get the index of the edit field so we can replace it */
0348:                    int editIndex = _componentsVec.indexOf(_editHandle);
0349:                    if (editIndex != -1) {
0350:                        return (HtmlTextEdit) _componentsVec
0351:                                .elementAt(editIndex);
0352:                    }
0353:                } catch (Exception e) {
0354:                    MessageLog.writeErrorMessage("getEditField", e, this );
0355:                }
0356:                return null;
0357:            }
0358:
0359:            /**
0360:             * This method returns the hidden description filed
0361:             * 
0362:             * @return HtmlTextEdit
0363:             */
0364:            public HtmlHiddenField getHiddenDescrField() {
0365:                try {
0366:
0367:                    /** get the index of the edit field so we can replace it */
0368:                    int editIndex = _componentsVec
0369:                            .indexOf(_hiddenDescriptionHandle);
0370:                    if (editIndex != -1) {
0371:                        return (HtmlHiddenField) _componentsVec
0372:                                .elementAt(editIndex);
0373:                    }
0374:                } catch (Exception e) {
0375:                    MessageLog
0376:                            .writeErrorMessage("getHiddenDescrField", e, this );
0377:                }
0378:                return null;
0379:            }
0380:
0381:            /**
0382:             * This method retuns the lookUp URL
0383:             * 
0384:             * @return String
0385:             */
0386:            public String getLookUpPageURL() {
0387:                return _lookUpPageURL;
0388:            }
0389:
0390:            /**
0391:             * This method returns the value of the text in the component.
0392:             * 
0393:             * @return String
0394:             */
0395:            public String getValue() {
0396:                return getEditField().getValue();
0397:            }
0398:
0399:            /**
0400:             * This method returns the description of the text in the component.
0401:             * 
0402:             * @return String
0403:             */
0404:            public String getDescription() {
0405:                return getHiddenDescrField().getValue();
0406:            }
0407:
0408:            public void pageRequested(PageEvent p) throws Exception {
0409:                HttpServletRequest req = p.getPage().getCurrentRequest();
0410:                String returnVal[] = req.getParameterValues(getFullName());
0411:                if (returnVal != null) {
0412:                    if (_editDescription)
0413:                        _hiddenKeyHandle.setValue(returnVal[0], _rowNo);
0414:                    else
0415:                        getEditField().setValue(returnVal[0], _rowNo);
0416:                }
0417:                HtmlPage pg = getPage();
0418:                if (pg instanceof  JspController)
0419:                    ((JspController) pg)
0420:                            .setRemoveFromQueryString(getFullName());
0421:
0422:                if (returnVal != null) {
0423:                    returnVal = req.getParameterValues("descReturn");
0424:                    if (returnVal != null) {
0425:                        if (_editDescription)
0426:                            getEditField().setValue(returnVal[0], _rowNo);
0427:                        if (_descDs != null && _descriptionColumn != -1) {
0428:                            if (_descDs.getColumnDataType(_descriptionColumn) == DataStoreBuffer.DATATYPE_STRING) {
0429:                                if (_rowNo == -1)
0430:                                    _rowNo = _descDs.getRow();
0431:                                _descDs.setString(_rowNo, _descriptionColumn,
0432:                                        returnVal[0]);
0433:                            }
0434:                        }
0435:                        if (pg instanceof  JspController)
0436:                            ((JspController) pg)
0437:                                    .setRemoveFromQueryString("descReturn");
0438:                    }
0439:                }
0440:
0441:            }
0442:
0443:            public void pageRequestEnd(PageEvent p) throws Exception {
0444:            }
0445:
0446:            public void pageSubmitEnd(PageEvent p) {
0447:            }
0448:
0449:            public void pageSubmitted(PageEvent p) {
0450:            }
0451:
0452:            /**
0453:             * Replaces the default browse image with one you specify
0454:             * 
0455:             * @param comp -
0456:             *            component that is replacing the browse image
0457:             * @param dataType -
0458:             *            data type of the component being replaced ( use
0459:             *            DataStore.DATATYPE_*)
0460:             * @param bound -
0461:             *            flag that signifies if the component is bound to a datastore
0462:             *            column
0463:             * @param table -
0464:             *            table component is bound to
0465:             * @param column -
0466:             *            column component is bound to
0467:             */
0468:            public void replaceBrowseImage(HtmlComponent comp, int dataType,
0469:                    boolean bound, String table, String column) {
0470:                try {
0471:
0472:                    /** get the index of the edit field so we can replace it */
0473:                    if (_usePopup) {
0474:                        int browseIndex = _componentsVec
0475:                                .indexOf(_browsePopupImageHandle);
0476:                        if (browseIndex != -1) {
0477:                            replaceCompositeComponent(comp,
0478:                                    _browsePopupImageHandle, dataType, bound,
0479:                                    table, column);
0480:                            _componentsVec.setElementAt(comp, browseIndex);
0481:                            comp.setParent(this );
0482:                            _browsePopupImageHandle = comp;
0483:                        }
0484:                    } else {
0485:                        int browseIndex = _componentsVec
0486:                                .indexOf(_browseImageHandle);
0487:                        if (browseIndex != -1) {
0488:                            replaceCompositeComponent(comp, _browseImageHandle,
0489:                                    dataType, bound, table, column);
0490:                            _componentsVec.setElementAt(comp, browseIndex);
0491:                            comp.setParent(this );
0492:                            _browseImageHandle = comp;
0493:                        }
0494:
0495:                    }
0496:                } catch (Exception e) {
0497:                    MessageLog.writeErrorMessage("replaceBrowseImage", e, this );
0498:                }
0499:            }
0500:
0501:            /**
0502:             * Replaces the default edit field with one you specify
0503:             * 
0504:             * @param comp -
0505:             *            component that is replacing the edit field
0506:             * @param dataType -
0507:             *            data type of the component being replaced ( use
0508:             *            DataStore.DATATYPE_*)
0509:             * @param bound -
0510:             *            flag that signifies if the component is bound to a datastore
0511:             *            column
0512:             * @param table -
0513:             *            table component is bound to
0514:             * @param column -
0515:             *            column component is bound to
0516:             */
0517:            public void replaceEdit(HtmlComponent comp, int dataType,
0518:                    boolean bound, String table, String column) {
0519:                try {
0520:
0521:                    /** get the index of the edit field so we can replace it */
0522:                    int editIndex = _componentsVec.indexOf(_editHandle);
0523:                    if (editIndex != -1) {
0524:                        replaceCompositeComponent(comp, _editHandle, dataType,
0525:                                bound, table, column);
0526:                        comp.setParent(this );
0527:                        _editHandle = comp;
0528:                    }
0529:                } catch (Exception e) {
0530:                    MessageLog.writeErrorMessage("replaceEdit", e, this );
0531:                }
0532:            }
0533:
0534:            /**
0535:             * Sets the column in the DataStore that this field binds to
0536:             */
0537:
0538:            public void setColumn(DataStoreBuffer ds, int columnNo) {
0539:                if (!_editDescription)
0540:                    getEditField().setColumn(ds, columnNo);
0541:                else
0542:                    _hiddenKeyHandle.setColumn(ds, columnNo);
0543:                _ds = ds;
0544:            }
0545:
0546:            /**
0547:             * Sets the column in the DataStore that this field binds to
0548:             */
0549:
0550:            public void setColumn(DataStoreBuffer ds, String columnName) {
0551:                if (!_editDescription)
0552:                    getEditField().setColumn(ds, columnName);
0553:                else
0554:                    _hiddenKeyHandle.setColumn(ds, columnName);
0555:                _ds = ds;
0556:            }
0557:
0558:            /**
0559:             * Sets the flag for ability to respond to user input (true = does respond).
0560:             * 
0561:             * @param enabled
0562:             *            boolean
0563:             */
0564:            public void setEnabled(boolean enabled) {
0565:                super .setEnabled(enabled);
0566:                if (_editHandle instanceof  HtmlFormComponent)
0567:                    ((HtmlFormComponent) _editHandle).setEnabled(enabled);
0568:                if (_usePopup)
0569:                    _browsePopupImageLink.setVisible(enabled);
0570:                else
0571:                    _browseImage.setVisible(enabled);
0572:            }
0573:
0574:            /**
0575:             * This method will append the extra parms string to the url when the user
0576:             * clicks the submit image.
0577:             */
0578:            public void setExtraParms(String extraParms) {
0579:                _extraParms = extraParms;
0580:            }
0581:
0582:            /**
0583:             * This method was created in VisualAge.
0584:             * 
0585:             * @param newValue
0586:             *            String
0587:             */
0588:            public void setLookUpPageURL(String newValue) {
0589:                _lookUpPageURL = translateSiteMapURL(newValue);
0590:            }
0591:
0592:            /**
0593:             * Sets the value in the edit field.
0594:             */
0595:            public void setValue(String newValue) {
0596:                getEditField().setValue(newValue);
0597:            }
0598:
0599:            public boolean submitPerformed(SubmitEvent e) throws Exception {
0600:                /** redirect to lookupPageURL?returnto=parentPage&comp=nameofComponent */
0601:                /** open new page */
0602:                _rowNo = e.getRow();
0603:                String rowURL = "";
0604:                if (_rowNo != -1)
0605:                    rowURL = "&rowNo=" + _rowNo;
0606:
0607:                HttpServletResponse resp = e.getPage().getCurrentResponse();
0608:                String URL = _lookUpPageURL;
0609:                if (_lookUpPageURL != null && _lookUpPageURL.indexOf("?") == -1)
0610:                    URL += "?returnTo=" + e.getPage().getPageName() + "&comp="
0611:                            + getFullName() + rowURL;
0612:                else
0613:                    URL += "&returnTo=" + e.getPage().getPageName() + "&comp="
0614:                            + getFullName() + rowURL;
0615:
0616:                String sCurrentValue = null;
0617:
0618:                //Try to get the text that is already entered to the text edit box. We
0619:                // will use this value in the list form to filter the results.
0620:                if (_rowNo != -1)
0621:                    sCurrentValue = getEditField().getValue(_rowNo);
0622:                else
0623:                    sCurrentValue = getEditField().getValue();
0624:
0625:                if (sCurrentValue != null && sCurrentValue.length() > 0)
0626:                    URL += "&" + PARAM_LISTFORM_SEARCH_FILTER_STRING + "="
0627:                            + sCurrentValue;
0628:
0629:                if (_extraParms != null)
0630:                    URL += "&" + _extraParms;
0631:                resp.sendRedirect(URL);
0632:                return false;
0633:            }
0634:
0635:            /*
0636:             * (non-Javadoc)
0637:             * 
0638:             * @see com.salmonllc.html.HtmlComponent#generateHTML(java.io.PrintWriter,
0639:             *      int, int)
0640:             */
0641:            public void generateHTML(PrintWriter p, int rowStart, int rowEnd)
0642:                    throws Exception {
0643:                generatePopupHtml(rowStart);
0644:                boolean editReadOnly = setEditReadOnly(rowStart);
0645:                super .generateHTML(p, rowStart, rowEnd);
0646:                getEditField().setReadOnly(editReadOnly);
0647:                generateDivHtml(p, rowStart);
0648:            }
0649:
0650:            /*
0651:             * (non-Javadoc)
0652:             * 
0653:             * @see com.salmonllc.html.HtmlComponent#generateHTML(java.io.PrintWriter,
0654:             *      int)
0655:             */
0656:            public void generateHTML(PrintWriter p, int rowNo) throws Exception {
0657:                generatePopupHtml(rowNo);
0658:                boolean editReadOnly = setEditReadOnly(rowNo);
0659:                super .generateHTML(p, rowNo);
0660:                getEditField().setReadOnly(editReadOnly);
0661:                generateDivHtml(p, rowNo);
0662:
0663:            }
0664:
0665:            private boolean setEditReadOnly(int rowNo) {
0666:                boolean ret = getEditField().getReadOnly();
0667:                if (_editDescription)
0668:                    getEditField().setOnChange(
0669:                            getFormString() + _hiddenKeyHandle.getFullName()
0670:                                    + (rowNo != -1 ? "_" + rowNo : "")
0671:                                    + ".value=''");
0672:                return ret;
0673:            }
0674:
0675:            private void generateDivHtml(PrintWriter p, int rowNo)
0676:                    throws DataStoreException {
0677:                if (!_showDescription)
0678:                    return;
0679:                if (_editDescription)
0680:                    return;
0681:                p.print(_fontStartTag);
0682:                p.print("<span id=\"div");
0683:                p.print(getFullName());
0684:                if (rowNo != -1)
0685:                    p.print("_" + rowNo);
0686:                p.print("\">");
0687:                if (_descriptionEval != null) {
0688:                    if (rowNo == -1)
0689:                        rowNo = _descriptionEval.getDataStore().getRow();
0690:                    Object o = _descriptionEval.evaluateRow(rowNo);
0691:                    if (o != null) {
0692:                        p.print(o);
0693:                        _hiddenDescriptionHandle.setValue(o.toString());
0694:                    } else {
0695:                        _hiddenDescriptionHandle.setValue(null);
0696:                    }
0697:                } else {
0698:                    //Take the description from the hidden field value
0699:                    p.print(_hiddenDescriptionHandle.getValue() == null ? ""
0700:                            : _hiddenDescriptionHandle.getValue());
0701:                }
0702:                p.print("</span>");
0703:                p.print(_fontEndTag);
0704:            }
0705:
0706:            private String generatePopupHtml(int row) {
0707:                if (_showDescription && _editHandle instanceof  HtmlTextEdit) {
0708:                    String rowNo = row == -1 ? "" : "_" + row;
0709:                    ((HtmlTextEdit) _editHandle)
0710:                            .setOnChange("var theSpan=document.getElementById(\'div"
0711:                                    + getFullName()
0712:                                    + rowNo
0713:                                    + "'); if (theSpan) theSpan.innerHTML=''; "
0714:                                    + getHiddenDescrFieldFullName(row)
0715:                                    + ".value='';");
0716:                }
0717:
0718:                if (_usePopup) {
0719:                    if (_visible && _enabled) {
0720:                        StringBuffer jsPopupVars = new StringBuffer();
0721:
0722:                        if (_editHandle != null) {
0723:                            jsPopupVars.append("obj=");
0724:                            jsPopupVars.append(this .getFormString());
0725:                            jsPopupVars.append(((HtmlComponent) _editHandle)
0726:                                    .getFullName());
0727:                            jsPopupVars
0728:                                    .append(((row == -1) ? "" : ("_" + row)));
0729:                            jsPopupVars.append(";");
0730:                        }
0731:
0732:                        String urlParms = PARAM_LOOKUP_CONTROLLER
0733:                                + "=$jsp$"
0734:                                + ((JspController) this .getPage())
0735:                                        .getSessionKey() + "&"
0736:                                + PARAM_LOOKUP_COMPONENT + "=" + this .getName()
0737:                                + "&" + PARAM_LOOKUP_ROW + "=" + row;
0738:
0739:                        jsPopupVars.append("url='");
0740:                        String lookupPageURL = getLookUpPageURL();
0741:                        jsPopupVars.append(lookupPageURL);
0742:                        if (lookupPageURL != null
0743:                                && lookupPageURL.indexOf("?") == -1)
0744:                            jsPopupVars.append("?");
0745:                        else
0746:                            jsPopupVars.append("&");
0747:                        jsPopupVars.append(urlParms);
0748:                        jsPopupVars.append("&" + PARAM_LOOKUP_VALUE
0749:                                + "='+escape(obj.value)");
0750:                        //pass any values from other components on the page if necessary
0751:                        if (_popupURLLineValues != null) {
0752:                            for (int i = 0; i < _popupURLLineValues.size(); i++) {
0753:                                FormComponentInfo inf = (FormComponentInfo) _popupURLLineValues
0754:                                        .elementAt(i);
0755:                                jsPopupVars.append("+'&");
0756:                                jsPopupVars.append(inf.attName);
0757:                                jsPopupVars.append("='+escape(");
0758:                                jsPopupVars.append(inf.compName);
0759:                                if (inf.isInDataTable)
0760:                                    jsPopupVars.append("_" + row);
0761:                                jsPopupVars.append(".value)");
0762:                            }
0763:                        }
0764:                        //add extra parms to the component
0765:                        if (_extraParms != null)
0766:                            jsPopupVars.append("+" + _extraParms);
0767:                        jsPopupVars.append(";");
0768:                        HtmlScriptGenerator gen = new HtmlScriptGenerator(
0769:                                (JspController) getPage());
0770:                        if (_useDiv)
0771:                            jsPopupVars.append(gen.generatePopupDivScript(
0772:                                    "url", getPopupPosition(), getPopupTop(),
0773:                                    getPopupLeft(), getPopupWidth(),
0774:                                    getPopupHeight(), _useModal,
0775:                                    _divBorderStyle, (_divScrolling ? "auto"
0776:                                            : "no"),
0777:                                    (HtmlComponent) _editHandle, row));
0778:                        else
0779:                            jsPopupVars.append(gen.generateOpenPopupScript(
0780:                                    "url", getPopupPosition(), getPopupTop(),
0781:                                    getPopupLeft(), getPopupWidth(),
0782:                                    getPopupHeight(), _useModal,
0783:                                    _popupAttributes,
0784:                                    (HtmlComponent) _editHandle, row));
0785:
0786:                        _browsePopupImageLink.setHref("javascript:"
0787:                                + jsPopupVars);
0788:                        return jsPopupVars.toString();
0789:                    }
0790:
0791:                }
0792:                return null;
0793:            }
0794:
0795:            /**
0796:             * @return
0797:             */
0798:            public boolean getUsePopup() {
0799:                return _usePopup;
0800:            }
0801:
0802:            /**
0803:             * @param b
0804:             */
0805:            public void setUsePopup(boolean b, boolean useModal) {
0806:                _usePopup = b;
0807:                /* Claudio Pi - 5/25/04 Added for modal popup windows */
0808:                _useModal = useModal;
0809:
0810:                if (_usePopup) {
0811:                    _browseImage.setVisible(false);
0812:                    _browsePopupImageLink.setVisible(true);
0813:                } else {
0814:                    _browseImage.setVisible(true);
0815:                    _browsePopupImageLink.setVisible(false);
0816:                }
0817:            }
0818:
0819:            /**
0820:             * @return
0821:             */
0822:            public int getPopupHeight() {
0823:                return _popupHeight;
0824:            }
0825:
0826:            /**
0827:             * @return
0828:             */
0829:            public int getPopupWidth() {
0830:                return _popupWidth;
0831:            }
0832:
0833:            /**
0834:             * @param i
0835:             */
0836:            public void setPopupHeight(int i) {
0837:                _popupHeight = i;
0838:            }
0839:
0840:            /**
0841:             * @param i
0842:             */
0843:            public void setPopupWidth(int i) {
0844:                _popupWidth = i;
0845:            }
0846:
0847:            public void setDisplayFormat(String format) {
0848:                getEditField().setDisplayFormat(format);
0849:            }
0850:
0851:            public void setDisplayFormatLocaleKey(String key) {
0852:                getEditField().setDisplayFormatLocaleKey(key);
0853:
0854:            }
0855:
0856:            /**
0857:             * This method can be used by controllers of lookup popup windows to find
0858:             * the current value in the lookup component
0859:             */
0860:            public static String getParentLookupValue(JspController cont) {
0861:                String value = cont
0862:                        .getParameter(HtmlLookUpComponent.PARAM_LOOKUP_VALUE);
0863:                if (value != null && value.trim().length() == 0)
0864:                    value = null;
0865:
0866:                return value;
0867:            }
0868:
0869:            /**
0870:             * This method can be used by controllers of lookup popup windows to find
0871:             * the display format the lookup component
0872:             */
0873:            public static String getParentLookupFormat(JspController cont) {
0874:                String value = null;
0875:                String callingController = cont
0876:                        .getParameter(HtmlLookUpComponent.PARAM_LOOKUP_CONTROLLER);
0877:                if (callingController != null) {
0878:                    try {
0879:                        JspController otherCont = (JspController) cont
0880:                                .getSession().getAttribute(callingController);
0881:                        if (otherCont != null) {
0882:                            HtmlLookUpComponent luComp = (HtmlLookUpComponent) otherCont
0883:                                    .getComponent(cont
0884:                                            .getParameter(HtmlLookUpComponent.PARAM_LOOKUP_COMPONENT));
0885:                            value = luComp.getEditField().getDisplayFormat();
0886:                        }
0887:                    } catch (Exception ex) {
0888:                    }
0889:                }
0890:                return value;
0891:            }
0892:
0893:            /**
0894:             * This method can be used by controllers of lookup popup windows to find
0895:             * the max length of the lookup component
0896:             */
0897:            public static int getParentLookupMaxLength(JspController cont) {
0898:                int value = 0;
0899:                String callingController = cont
0900:                        .getParameter(HtmlLookUpComponent.PARAM_LOOKUP_CONTROLLER);
0901:                if (callingController != null) {
0902:                    try {
0903:                        JspController otherCont = (JspController) cont
0904:                                .getSession().getAttribute(callingController);
0905:                        if (otherCont != null) {
0906:                            HtmlLookUpComponent luComp = (HtmlLookUpComponent) otherCont
0907:                                    .getComponent(cont
0908:                                            .getParameter(HtmlLookUpComponent.PARAM_LOOKUP_COMPONENT));
0909:                            value = luComp.getEditField().getMaxLength();
0910:                        }
0911:                    } catch (Exception ex) {
0912:                    }
0913:                }
0914:                return value;
0915:            }
0916:
0917:            /**
0918:             * This method will load the font start and end tags from the page
0919:             * properties object.See the Constants at the top of the class for valid
0920:             * values to pass to this method.
0921:             */
0922:            public void setDescriptionFont(String font) {
0923:                _font = font;
0924:                Props props = getPage().getPageProperties();
0925:
0926:                if (_font != null) {
0927:                    _fontStartTag = props.getProperty(_font + Props.TAG_START);
0928:                    _fontEndTag = props.getProperty(_font + Props.TAG_END);
0929:                } else {
0930:                    _fontStartTag = props.getProperty(HtmlText.FONT_DEFAULT
0931:                            + Props.TAG_START);
0932:                    _fontEndTag = props.getProperty(HtmlText.FONT_DEFAULT
0933:                            + Props.TAG_END);
0934:                }
0935:
0936:            }
0937:
0938:            /**
0939:             * @return true if a description should be shown next to the field
0940:             */
0941:            public boolean getShowDescription() {
0942:                return _showDescription;
0943:            }
0944:
0945:            /**
0946:             * set to true if a description should be shown next to the field
0947:             */
0948:            public void setShowDescription(boolean b) {
0949:                _showDescription = b;
0950:            }
0951:
0952:            /*
0953:             * Sets an expression for the description of the field being looked up
0954:             */
0955:            public void setDescriptionExpression(DataStoreBuffer ds, String exp)
0956:                    throws DataStoreException {
0957:                int index = ds.getColumnIndex(exp);
0958:
0959:                if (!_editDescription) {
0960:                    _descriptionEval = new DataStoreEvaluator(ds, exp);
0961:                    if (index != -1)
0962:                        _descriptionColumn = index;
0963:                    _showDescription = true;
0964:                    _descDs = ds;
0965:                } else if (index != -1)
0966:                    getEditField().setColumn(ds, index);
0967:
0968:            }
0969:
0970:            /*
0971:             * Sets an expression for the description of the field being looked up
0972:             */
0973:            public void setDescriptionExpression(DataStoreBuffer ds,
0974:                    DataStoreExpression exp) throws DataStoreException {
0975:                if (!_editDescription) {
0976:                    _descriptionEval = new DataStoreEvaluator(ds, exp);
0977:                    _showDescription = true;
0978:                    _descDs = ds;
0979:                }
0980:            }
0981:
0982:            /**
0983:             * @return the datasource string for the description column of the lookup
0984:             */
0985:            public String getDescriptionDataSource() {
0986:                return _descriptionDataSource;
0987:            }
0988:
0989:            /**
0990:             * @sets the datasource string for the description column of the lookup
0991:             */
0992:            public void setDescriptionDataSource(String string) {
0993:                _descriptionDataSource = string;
0994:            }
0995:
0996:            public int getPopupLeft() {
0997:                return _popupLeft;
0998:            }
0999:
1000:            public void setPopupLeft(int _popupLeft) {
1001:                this ._popupLeft = _popupLeft;
1002:            }
1003:
1004:            public int getPopupTop() {
1005:                return _popupTop;
1006:            }
1007:
1008:            public void setPopupTop(int _popupTop) {
1009:                this ._popupTop = _popupTop;
1010:            }
1011:
1012:            public String getPopupPosition() {
1013:                return _popupPosition;
1014:            }
1015:
1016:            public void setPopupPosition(String _popupPosition) {
1017:                this ._popupPosition = _popupPosition;
1018:            }
1019:
1020:            public String getEditFieldFullName(int rowNum) {
1021:                String editFieldFullName = null;
1022:                String formString = null;
1023:                if (getPage() != null) {
1024:                    editFieldFullName = getEditField().getFullName();
1025:                    if (rowNum > -1)
1026:                        editFieldFullName += "_" + rowNum;
1027:                    formString = getEditField().getFormString();
1028:                }
1029:
1030:                if (editFieldFullName == null)
1031:                    return null;
1032:                else
1033:                    return formString + editFieldFullName;
1034:            }
1035:
1036:            public String getHiddenDescrFieldFullName(int rowNum) {
1037:                String hiddenDescrFullName = null;
1038:                String formString = null;
1039:                if (getPage() != null) {
1040:                    hiddenDescrFullName = getHiddenDescrField().getFullName();
1041:                    if (rowNum > -1)
1042:                        hiddenDescrFullName += "_" + rowNum;
1043:                    formString = getEditField().getFormString();
1044:                }
1045:
1046:                if (hiddenDescrFullName == null)
1047:                    return null;
1048:                else
1049:                    return formString + hiddenDescrFullName;
1050:            }
1051:
1052:            public String getHiddenKeyFieldFullName(int rowNum) {
1053:                String hiddenKeyFullName = null;
1054:                String formString = null;
1055:                if (getPage() != null) {
1056:                    hiddenKeyFullName = _hiddenKeyHandle.getFullName();
1057:                    if (rowNum > -1)
1058:                        hiddenKeyFullName += "_" + rowNum;
1059:                    formString = getEditField().getFormString();
1060:                }
1061:
1062:                if (hiddenKeyFullName == null)
1063:                    return null;
1064:                else
1065:                    return formString + hiddenKeyFullName;
1066:            }
1067:
1068:            public String getDivFullName(int rowNum) {
1069:                HtmlLookUpComponent luComp = this ;
1070:                String luName = luComp.getFullName();
1071:                if (rowNum > -1)
1072:                    luName += "_" + rowNum;
1073:                return "div" + luName;
1074:            }
1075:
1076:            /**
1077:             * @return Returns the popupAttributes if this lookup uses a popup window
1078:             *         (see javascript window.open for list of available attributes)".
1079:             */
1080:            public String getPopupAttributes() {
1081:                return _popupAttributes;
1082:            }
1083:
1084:            /**
1085:             * @param popupAttributes
1086:             *            The popupAttributes to set if this lookup uses a popup window
1087:             *            (see javascript window.open for list of available
1088:             *            attributes)"..
1089:             */
1090:            public void setPopupAttributes(String popupAttributes) {
1091:                _popupAttributes = popupAttributes;
1092:            }
1093:
1094:            /*
1095:             * (non-Javadoc)
1096:             * 
1097:             * @see com.salmonllc.html.HtmlComponent#setTheme(java.lang.String)
1098:             */
1099:            public void setTheme(String theme) {
1100:                Props p = getPage().getPageProperties();
1101:                _popupAttributes = p.getThemeProperty(theme,
1102:                        Props.LOOKUP_COMPONENT_POPUPATTRIBUTES);
1103:
1104:                _lookUpPageURL = p.getThemeProperty(theme,
1105:                        Props.LOOKUP_COMPONENT_URL);
1106:                _usePopup = p.getThemeBooleanProperty(theme,
1107:                        Props.LOOKUP_COMPONENT_USEPOPUP, false);
1108:                _useModal = p.getThemeBooleanProperty(theme,
1109:                        Props.LOOKUP_COMPONENT_POPUPMODAL, false);
1110:                _popupWidth = p.getThemeIntProperty(theme,
1111:                        Props.LOOKUP_COMPONENT_POPUPWIDTH, 300);
1112:                _popupHeight = p.getThemeIntProperty(theme,
1113:                        Props.LOOKUP_COMPONENT_POPUPHEIGHT, 300);
1114:                _popupTop = p.getThemeIntProperty(theme,
1115:                        Props.LOOKUP_COMPONENT_POPUPTOP, 0);
1116:                _popupLeft = p.getThemeIntProperty(theme,
1117:                        Props.LOOKUP_COMPONENT_POPUPLEFT, 0);
1118:                _popupPosition = p.getThemeProperty(theme,
1119:                        Props.LOOKUP_COMPONENT_POPUPPOSITION,
1120:                        Constants.POPUP_POSITION_CUSTOM);
1121:                _useDiv = p.getThemeBooleanProperty(theme,
1122:                        Props.LOOKUP_COMPONENT_POPUPDIV, false);
1123:                _divBorderStyle = p.getThemeProperty(theme,
1124:                        Props.LOOKUP_COMPONENT_POPUPDIVBORDERSTYLE);
1125:                setEditDescription(p.getThemeBooleanProperty(theme,
1126:                        Props.LOOKUP_COMPONENT_EDITDESCRIPTION));
1127:                super .setTheme(theme);
1128:
1129:            }
1130:
1131:            /**
1132:             * @return Returns whether or not the description is editable. If the
1133:             *         description is editable, the key field will not be displayed, but
1134:             *         will be set by the lookup.
1135:             */
1136:            public boolean getEditDescription() {
1137:                return _editDescription;
1138:            }
1139:
1140:            /**
1141:             * @param editDescription
1142:             *            Sets whether or not the description is editable. If the
1143:             *            description is editable, the key field will not be displayed,
1144:             *            but will be set by the lookup.
1145:             */
1146:            public void setEditDescription(boolean editDescription) {
1147:                _editDescription = editDescription;
1148:                _hiddenKeyHandle.setVisible(editDescription);
1149:            }
1150:
1151:            /**
1152:             * @return Returns the useDiv flag to indicate if a popup should open in a div.
1153:             */
1154:            public boolean getUseDiv() {
1155:                return _useDiv;
1156:            }
1157:
1158:            /**
1159:             * @param useDiv The useDiv to set.
1160:             */
1161:            public void setUseDiv(boolean useDiv) {
1162:                _useDiv = useDiv;
1163:            }
1164:
1165:            /**
1166:             * @return Returns the divBorderStyle.
1167:             */
1168:            public String getDivBorderStyle() {
1169:                return _divBorderStyle;
1170:            }
1171:
1172:            /**
1173:             * @param divBorderStyle For popups that open in divs sets the border style (CSS) for the div border default  is: 1px solid black.
1174:             */
1175:            public void setDivBorderStyle(String divBorderStyle) {
1176:                _divBorderStyle = divBorderStyle;
1177:            }
1178:
1179:            /**
1180:             * @return Returns the divScrolling.
1181:             */
1182:            public boolean getDivScrolling() {
1183:                return _divScrolling;
1184:            }
1185:
1186:            /**
1187:             * @param divScrolling For popus that open in divs, whether or not a scrollbar will be present for overflow
1188:             */
1189:            public void setDivScrolling(boolean divScrolling) {
1190:                _divScrolling = divScrolling;
1191:            }
1192:
1193:            /**
1194:             * Add a form component value to the url line of a popup request
1195:             * @param comp The component to get the value from
1196:             * @param requestParmName The name of the parameter to add to the URL line
1197:             */
1198:            public void addFormComponentValueToPopup(HtmlComponent comp,
1199:                    String requestParmName) {
1200:                if (comp == null)
1201:                    return;
1202:                if (_popupURLLineValues == null)
1203:                    _popupURLLineValues = new Vector();
1204:
1205:                boolean isInDataTable = false;
1206:                HtmlComponent parent = comp.getParent();
1207:                while (parent != null) {
1208:                    if (parent instanceof  JspDataTable
1209:                            || parent instanceof  JspList
1210:                            || parent instanceof  HtmlDataTable) {
1211:                        isInDataTable = true;
1212:                        break;
1213:                    }
1214:                    parent = parent.getParent();
1215:                }
1216:
1217:                if (comp instanceof  HtmlLookUpComponent)
1218:                    comp = ((HtmlLookUpComponent) comp).getEditField();
1219:                String name = comp.getFormString() + comp.getFullName();
1220:                FormComponentInfo inf = new FormComponentInfo();
1221:                inf.attName = requestParmName;
1222:                inf.compName = name;
1223:                inf.isInDataTable = isInDataTable;
1224:                _popupURLLineValues.add(inf);
1225:            }
1226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.