Source Code Cross Referenced for JspDetailFormDisplayBox.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:        import com.salmonllc.html.*;
0023:        import com.salmonllc.html.events.*;
0024:        import com.salmonllc.localizer.LanguagePreferences;
0025:        import com.salmonllc.localizer.LanguageResourceFinder;
0026:        import com.salmonllc.properties.Props;
0027:        import com.salmonllc.sql.*;
0028:        import com.salmonllc.util.MessageLog;
0029:
0030:        import javax.servlet.http.HttpServletRequest;
0031:        import java.io.IOException;
0032:        import java.sql.SQLException;
0033:        import java.util.Enumeration;
0034:
0035:        /**
0036:         * An extended version of the display box with addional functionality for building detail forms
0037:         *
0038:         */
0039:        public class JspDetailFormDisplayBox extends JspFormDisplayBox
0040:                implements  SubmitListener {
0041:            public static final int MODE_LIST_ON_PAGE = 0;
0042:            public static final int MODE_LIST_OFF_PAGE = 1;
0043:            private String _validatorName;
0044:            private DataStoreBuffer _ds;
0045:            private String _dataStoreName;
0046:            private HtmlSubmitButton _addButton, _saveButton, _cancelButton,
0047:                    _deleteButton;
0048:            private String _saveButtonAccessKey, _addButtonAccessKey,
0049:                    _cancelButtonAccessKey, _deleteButtonAccessKey,
0050:                    _saveButtonCaption, _addButtonCaption,
0051:                    _cancelButtonCaption, _deleteButtonCaption;
0052:            private JspListFormDisplayBox _listForm;
0053:            private String _listFormName;
0054:            private int _mode;
0055:            private HtmlSubmitButton _okToEditButton, _okToDeleteButton,
0056:                    _okToCancelButton, _okToAddButton, _cancelMessageButton;
0057:            private HtmlContainer _okToEdit, _okToDelete, _okToCancel,
0058:                    _okToAdd;
0059:            private String _okToAddQuestion = "Warning, adding a new item will cause unsaved changes to be lost. Continue?";
0060:            private String _okToEditQuestion = "Warning, editing this item will cause unsaved changes to be lost. Continue?";
0061:            private String _okToDeleteQuestion = "Confirm Delete?";
0062:            private String _okToCancelQuestion = "Are you sure you want to cancel these changes?";
0063:            private String _dirtyDataError = "Can't do save. The row has already been modified or deleted by another user. Please reload the data and try your changes again. ";
0064:            private boolean _confirmDelete = true;
0065:            private DataStoreRow _listSelectedRow;
0066:            private String _returnTo;
0067:            private JspDetailFormDisplayBox _this  = this ;
0068:            private boolean _displayOnly = false;
0069:            private boolean _reloadRowAfterSave = true;
0070:            private HtmlHiddenField _okToEditValue;
0071:            private HtmlHiddenField _okToDeleteValue;
0072:            private HtmlHiddenField _okToCancelValue;
0073:            private HtmlHiddenField _okToAddValue;
0074:
0075:            private class CancelAction implements  SubmitListener,
0076:                    ValueChangedListener {
0077:                public boolean submitPerformed(SubmitEvent e) throws Exception {
0078:                    doCancel();
0079:                    return true;
0080:                }
0081:
0082:                public boolean valueChanged(ValueChangedEvent e)
0083:                        throws Exception {
0084:                    if (_okToCancelValue.getValue() != null
0085:                            && _okToCancelValue.getValue().equals("1")) {
0086:                        doCancel();
0087:                    }
0088:                    return true;
0089:                }
0090:            }
0091:
0092:            private class EditAction implements  SubmitListener,
0093:                    ValueChangedListener {
0094:                public boolean submitPerformed(SubmitEvent e) throws Exception {
0095:                    doEdit();
0096:                    return true;
0097:                }
0098:
0099:                public boolean valueChanged(ValueChangedEvent e)
0100:                        throws Exception {
0101:                    if (_okToEditValue.getValue() != null
0102:                            && _okToEditValue.getValue().equals("1")) {
0103:                        doEdit();
0104:                    }
0105:                    return true;
0106:                }
0107:            }
0108:
0109:            private class DeleteAction implements  SubmitListener,
0110:                    ValueChangedListener {
0111:                public boolean submitPerformed(SubmitEvent e) throws Exception {
0112:                    doDelete();
0113:                    return true;
0114:                }
0115:
0116:                public boolean valueChanged(ValueChangedEvent e)
0117:                        throws Exception {
0118:                    if (_okToDeleteValue.getValue() != null
0119:                            && _okToDeleteValue.getValue().equals("1")) {
0120:                        doDelete();
0121:                    }
0122:                    return true;
0123:                }
0124:            }
0125:
0126:            private class AddAction implements  SubmitListener,
0127:                    ValueChangedListener {
0128:                public boolean submitPerformed(SubmitEvent e) throws Exception {
0129:                    doAdd();
0130:                    return true;
0131:                }
0132:
0133:                public boolean valueChanged(ValueChangedEvent e)
0134:                        throws Exception {
0135:                    if (_okToAddValue.getValue() != null
0136:                            && _okToAddValue.getValue().equals("1")) {
0137:                        doAdd();
0138:                    }
0139:                    return true;
0140:                }
0141:            }
0142:
0143:            private class CancelMessageAction implements  SubmitListener {
0144:                public boolean submitPerformed(SubmitEvent e) throws Exception {
0145:                    scrollToMe();
0146:                    return true;
0147:                }
0148:            }
0149:
0150:            private class LocalPageListener implements  PageListener {
0151:                private boolean[] _oldButtonsVisible;
0152:                private boolean[] _oldEnabled;
0153:
0154:                public void pageRequested(PageEvent p) throws Exception {
0155:                    String displayOnly = getPage().getCurrentRequest()
0156:                            .getParameter("displayOnly");
0157:                    String mode = getPage().getCurrentRequest().getParameter(
0158:                            "mode");
0159:                    String listPage = getPage().getCurrentRequest()
0160:                            .getParameter("listPage");
0161:                    _displayOnly = false;
0162:                    _oldEnabled = null;
0163:                    _oldButtonsVisible = null;
0164:                    if (_mode == MODE_LIST_OFF_PAGE) {
0165:                        if (mode == null || mode.equalsIgnoreCase("add")) {
0166:                            _oldButtonsVisible = getButtonsVisible();
0167:                            _deleteButton.setVisible(false);
0168:                        }
0169:                    }
0170:                    if (displayOnly != null
0171:                            && displayOnly.equalsIgnoreCase("true")) {
0172:                        _displayOnly = true;
0173:                        _oldButtonsVisible = getButtonsVisible();
0174:                        boolean cancelVis = _cancelButton.getVisible();
0175:                        for (int i = 0; i < _buttons.size(); i++)
0176:                            ((HtmlSubmitButton) _buttons.get(i))
0177:                                    .setVisible(false);
0178:                        if (listPage != null)
0179:                            _cancelButton.setVisible(cancelVis);
0180:                        _oldEnabled = new boolean[getComponentCount()];
0181:                        for (int i = 0; i < getComponentCount(); i++) {
0182:                            Object o = getComponent(i);
0183:                            if (o instanceof  HtmlFormComponent) {
0184:                                HtmlFormComponent comp = (HtmlFormComponent) o;
0185:                                _oldEnabled[i] = comp.getEnabled();
0186:                                comp.setEnabled(false);
0187:                            }
0188:                        }
0189:                    }
0190:
0191:                    if (!getPage().isReferredByCurrentPage()
0192:                            && _mode == MODE_LIST_OFF_PAGE) {
0193:                        HttpServletRequest r = getPage().getCurrentRequest();
0194:                        if (listPage != null)
0195:                            _returnTo = listPage;
0196:
0197:                        if (mode == null)
0198:                            mode = "add";
0199:                        if (mode.equalsIgnoreCase("edit")) {
0200:                            String id[] = r.getParameterValues("id");
0201:                            if (_ds instanceof  DataStore) {
0202:                                String tableList[] = _ds.getTableList(false);
0203:                                if (id != null) {
0204:                                    StringBuffer where = new StringBuffer();
0205:                                    for (int i = 0; i < id.length; i++) {
0206:                                        String parm = id[i];
0207:                                        int pos = parm.indexOf(":");
0208:                                        if (pos > -1) {
0209:                                            String table = parm.substring(0,
0210:                                                    pos);
0211:                                            String crit = parm
0212:                                                    .substring(pos + 1);
0213:                                            for (int j = 0; j < tableList.length; j++) {
0214:                                                if (table
0215:                                                        .equalsIgnoreCase(tableList[j])) {
0216:                                                    if (where.length() != 0)
0217:                                                        where.append(" AND ");
0218:                                                    where.append(crit);
0219:                                                    break;
0220:                                                }
0221:                                            }
0222:                                        }
0223:                                    }
0224:                                    if (where.length() > 0) {
0225:                                        doDataStoreRetrieve(where.toString());
0226:                                        if (!_ds.gotoFirst())
0227:                                            _ds.insertRow();
0228:                                        HtmlFormComponent comp = findFirstFormComponent(_this );
0229:                                        if (comp != null)
0230:                                            comp.setFocus();
0231:                                    }
0232:                                }
0233:                            } else if (_ds instanceof  BeanDataStore) {
0234:                                if (id != null) {
0235:                                    doDataStoreRetrieve(id[0]);
0236:                                    if (!_ds.gotoFirst())
0237:                                        _ds.insertRow();
0238:                                    HtmlFormComponent comp = findFirstFormComponent(_this );
0239:                                    if (comp != null)
0240:                                        comp.setFocus();
0241:                                }
0242:                            }
0243:                        } else {
0244:                            doAdd();
0245:                        }
0246:                    }
0247:                }
0248:
0249:                public void pageRequestEnd(PageEvent p) throws Exception {
0250:                    if (_oldButtonsVisible != null) {
0251:                        for (int i = 0; i < _buttons.size(); i++)
0252:                            ((HtmlSubmitButton) _buttons.get(i))
0253:                                    .setVisible(_oldButtonsVisible[i]);
0254:                    }
0255:                    if (_oldEnabled != null) {
0256:                        for (int i = 0; i < getComponentCount(); i++) {
0257:                            if (getComponent(i) instanceof  HtmlFormComponent)
0258:                                ((HtmlFormComponent) getComponent(i))
0259:                                        .setEnabled(_oldEnabled[i]);
0260:                        }
0261:                    }
0262:                }
0263:
0264:                public void pageSubmitEnd(PageEvent p) {
0265:                }
0266:
0267:                public void pageSubmitted(PageEvent p) {
0268:                }
0269:            }
0270:
0271:            public JspDetailFormDisplayBox(String name, HtmlPage page) {
0272:                this (name, null, page);
0273:
0274:            }
0275:
0276:            public JspDetailFormDisplayBox(String name, String theme,
0277:                    HtmlPage page) {
0278:                super (name, theme, page);
0279:
0280:                _addButton = new HtmlSubmitButton(name + "addButton", "Add",
0281:                        theme, page);
0282:                _saveButton = new HtmlSubmitButton(name + "saveButton", "Save",
0283:                        theme, page);
0284:                _deleteButton = new HtmlSubmitButton(name + "cancelButton",
0285:                        "Delete", theme, page);
0286:                _cancelButton = new HtmlSubmitButton(name + "deleteButton",
0287:                        "Cancel", theme, page);
0288:
0289:                _addButton.addSubmitListener(this );
0290:                _saveButton.addSubmitListener(this );
0291:                _deleteButton.addSubmitListener(this );
0292:                _buttons.add(_saveButton);
0293:                _buttons.add(_addButton);
0294:                _buttons.add(_deleteButton);
0295:                add(_addButton, TYPE_COMP);
0296:                add(_saveButton, TYPE_COMP);
0297:                add(_deleteButton, TYPE_COMP);
0298:                _cancelButton.addSubmitListener(this );
0299:                _buttons.add(_cancelButton);
0300:                add(_cancelButton, TYPE_COMP);
0301:
0302:                _okToEdit = new HtmlContainer("dfoktoeditquestion", page);
0303:                _okToDelete = new HtmlContainer("dfoktodeletequestion", page);
0304:                _okToCancel = new HtmlContainer("dfoktocancelquestion", page);
0305:                _okToAdd = new HtmlContainer("dfoktoaddquestion", page);
0306:
0307:                EditAction editAction = new EditAction();
0308:                CancelAction cancelAction = new CancelAction();
0309:                DeleteAction deleteAction = new DeleteAction();
0310:                AddAction addAction = new AddAction();
0311:
0312:                _cancelMessageButton = new MessageButton(getPage(),
0313:                        "dfcancelmessage", _cancelButtonCap,
0314:                        new CancelMessageAction());
0315:                _okToEditButton = new MessageButton(getPage(),
0316:                        "dfoktoeditmessage", _okButtonCap, editAction);
0317:                _okToCancelButton = new MessageButton(getPage(),
0318:                        "dfoktocancelmessage", _okButtonCap, cancelAction);
0319:                _okToDeleteButton = new MessageButton(getPage(),
0320:                        "dfoktodeletemessage", _okButtonCap, deleteAction);
0321:                _okToAddButton = new MessageButton(getPage(),
0322:                        "dfoktoaddmessage", _okButtonCap, addAction);
0323:
0324:                _okToEditValue = new HtmlHiddenField("jsoktoeditvalue", "0",
0325:                        page);
0326:                _okToEditValue.addValueChangedListener(editAction);
0327:                add(_okToEditValue, TYPE_COMP);
0328:                _hidden.add(_okToEditValue);
0329:
0330:                _okToCancelValue = new HtmlHiddenField("jsoktocancelvalue",
0331:                        "0", page);
0332:                _okToCancelValue.addValueChangedListener(cancelAction);
0333:                add(_okToCancelValue, TYPE_COMP);
0334:                _hidden.add(_okToCancelValue);
0335:
0336:                _okToDeleteValue = new HtmlHiddenField("jsoktodeletevalue",
0337:                        "0", page);
0338:                _okToDeleteValue.addValueChangedListener(deleteAction);
0339:                add(_okToDeleteValue, TYPE_COMP);
0340:                _hidden.add(_okToDeleteValue);
0341:
0342:                _okToAddValue = new HtmlHiddenField("jsoktoaddvalue", "0", page);
0343:                _okToAddValue.addValueChangedListener(addAction);
0344:                add(_okToAddValue, TYPE_COMP);
0345:                _hidden.add(_okToAddValue);
0346:
0347:                _okToAdd.add(_okToAddButton);
0348:                _okToAdd.add(_cancelMessageButton);
0349:
0350:                _okToEdit.add(_okToEditButton);
0351:                _okToEdit.add(_cancelMessageButton);
0352:
0353:                _okToDelete.add(_okToDeleteButton);
0354:                _okToDelete.add(_cancelMessageButton);
0355:
0356:                _okToCancel.add(_okToCancelButton);
0357:                _okToCancel.add(_cancelMessageButton);
0358:
0359:                _messageButtons.add(_okToDeleteButton);
0360:                _messageButtons.add(_okToEditButton);
0361:                _messageButtons.add(_okToCancelButton);
0362:                _messageButtons.add(_okToAddButton);
0363:                _messageButtons.add(_cancelMessageButton);
0364:
0365:                setUpButtons();
0366:            }
0367:
0368:            /**
0369:             *Called by the tag handler to set the name of the validator. The autoBindComponents will lookup the name of the component and attach it to this one or try to discover it if the name is null
0370:             */
0371:            public void setValidatorName(String name) {
0372:                _validatorName = name;
0373:            }
0374:
0375:            /**
0376:             *Called by the tag handler to set the name of the ListForm. The autoBindComponents will lookup the name of the component and attach it to this one or try to discover it if the name is null
0377:             */
0378:            public void setListFormName(String name) {
0379:                _listFormName = name;
0380:            }
0381:
0382:            /**
0383:             *Called by the tag handler to set the name of the DataStore used by the DetailForm. The autoBindComponents will lookup the name of the component and attach it to this one or try to discover it if the name is null
0384:             */
0385:            public void setDataStoreName(String string) {
0386:                _dataStoreName = string;
0387:            }
0388:
0389:            /**
0390:             * Binds various components to the component based on their names passed to the constructor. CriteriaBuilder, CriteriaValidator and ListForm. This method is called by the framework and should not be called directly.
0391:             */
0392:            public void autoBindComponents() throws Exception {
0393:		JspController cont = (JspController) getPage();
0394:
0395:		//get the datastore for this component
0396:		if (getDataSource() != null)
0397:			_ds = cont.getDataSource(getDataSource());
0398:		else {
0399:			//find the first component in the container bound to a datastore and use that instead
0400:			Enumeration enum = getComponents();
0401:			while (enum.hasMoreElements()) {
0402:				Object o = enum.nextElement();
0403:				if (o instanceof  HtmlFormComponent) {
0404:					DataStoreBuffer ds = ((HtmlFormComponent) o).getBoundDataStore();
0405:					if (ds != null) {
0406:						_ds = ds;
0407:						break;
0408:					}
0409:				}
0410:			}
0411:		}
0412:
0413:		//get the validator
0414:		if (_validatorName != null)
0415:			_validator = (HtmlValidatorText) cont.getComponent(_validatorName);
0416:		else {
0417:			//see if there is a validator for this datastore
0418:			Enumeration enum = cont.getComponents();
0419:			while (enum.hasMoreElements()) {
0420:				Object o = enum.nextElement();
0421:				if (o instanceof  HtmlValidatorText) {
0422:					HtmlValidatorText test = (HtmlValidatorText) o;
0423:					if (test.getDataStore() == _ds) {
0424:						_validator = test;
0425:						break;
0426:					}
0427:				}
0428:			}
0429:		}
0430:		//if the validator is null, build one from the validation rules in the model
0431:		if (_validator == null && _ds != null) {
0432:			boolean hasRules = false;
0433:			for (int i = 0; i < _ds.getColumnCount(); i++) {
0434:				if (_ds.getValidationRulesForColumn(i) != null) {
0435:					hasRules = true;
0436:					break;
0437:				}
0438:			}
0439:			if (hasRules) {
0440:				_validator = new HtmlValidatorText(getName() + "validator", cont);
0441:				_validator.setBreaksBefore(0);
0442:				_validator.setBreaksAfter(2);
0443:				_validator.setDataStore(_ds);
0444:				_validator.importRules(_ds);
0445:				_validator.setUseJavaScript(false);
0446:				_validator.setMultipleErrorsOK(true);
0447:				_validator.setAddFocusLinksToErrors(true);
0448:				_validatorBuiltInternally = true;
0449:				add(_validator, TYPE_COMP);
0450:			}
0451:		}
0452:
0453:		if (_validator == null) {
0454:			_validator = new HtmlValidatorText(getName() + "validator", cont);
0455:			_validator.setBreaksBefore(0);
0456:			_validator.setBreaksAfter(2);
0457:			_validatorBuiltInternally = true;
0458:			add(_validator, TYPE_COMP);
0459:		} else if (_saveButton != null)
0460:			_validator.addSubmitToListenTo(_saveButton);
0461:
0462:		//figure out what the list form is for this component
0463:		if (_listFormName != null)
0464:			_listForm = (JspListFormDisplayBox) cont.getComponent(_listFormName);
0465:		else {
0466:			Enumeration enum = cont.getComponents();
0467:			while (enum.hasMoreElements()) {
0468:				Object o = enum.nextElement();
0469:				if (o instanceof  JspListFormDisplayBox) {
0470:					_listForm = (JspListFormDisplayBox) o;
0471:					break;
0472:				}
0473:			}
0474:		}
0475:
0476:		if (_listForm != null)
0477:			_mode = MODE_LIST_ON_PAGE;
0478:		else
0479:			_mode = MODE_LIST_OFF_PAGE;
0480:
0481:		getPage().addPageListener(new LocalPageListener());
0482:
0483:	}
0484:
0485:            /**
0486:             * Sets the save button visible or not
0487:             */
0488:            public void setSaveButtonVisible(boolean visible) {
0489:                if (_saveButton != null)
0490:                    _saveButton.setVisible(visible);
0491:            }
0492:
0493:            /**
0494:             * Sets the text to display on the save button
0495:             */
0496:            public void setSaveButtonCaption(String caption) {
0497:                if (_saveButton != null)
0498:                    _saveButton.setDisplayName(caption);
0499:            }
0500:
0501:            /**
0502:             * Sets the add button visible or not
0503:             */
0504:            public void setAddButtonVisible(boolean visible) {
0505:                if (_addButton != null)
0506:                    _addButton.setVisible(visible);
0507:            }
0508:
0509:            /**
0510:             * Sets the add button visible or not
0511:             */
0512:            public void setAddButtonCaption(String caption) {
0513:                if (_addButton != null)
0514:                    _addButton.setDisplayName(caption);
0515:            }
0516:
0517:            /**
0518:             * Sets the delete button visible or not
0519:             */
0520:            public void setDeleteButtonVisible(boolean visible) {
0521:                if (_deleteButton != null)
0522:                    _deleteButton.setVisible(visible);
0523:            }
0524:
0525:            /**
0526:             * Sets the delete button visible or not
0527:             */
0528:            public void setDeleteButtonCaption(String caption) {
0529:                if (_deleteButton != null)
0530:                    _deleteButton.setDisplayName(caption);
0531:            }
0532:
0533:            /**
0534:             * Sets the cancel button visible or not
0535:             */
0536:            public void setCancelButtonVisible(boolean visible) {
0537:                if (_cancelButton != null)
0538:                    _cancelButton.setVisible(visible);
0539:            }
0540:
0541:            /**
0542:             * Sets the delete button visible or not
0543:             */
0544:            public void setCancelButtonCaption(String caption) {
0545:                if (_cancelButton != null)
0546:                    _cancelButton.setDisplayName(caption);
0547:            }
0548:
0549:            /**
0550:             * Returns the save button visible or not
0551:             */
0552:            public boolean isSaveButtonVisible() {
0553:                if (_saveButton == null)
0554:                    return false;
0555:                else
0556:                    return _saveButton.getVisible();
0557:            }
0558:
0559:            /**
0560:             * Returns the text to display on the save button
0561:             */
0562:            public String getSaveButtonCaption() {
0563:                if (_saveButton == null)
0564:                    return null;
0565:                else
0566:                    return _saveButton.getDisplayName();
0567:            }
0568:
0569:            /**
0570:             * Return the add button visible or not
0571:             */
0572:            public boolean isAddButtonVisible() {
0573:                if (_addButton == null)
0574:                    return false;
0575:                else
0576:                    return _addButton.getVisible();
0577:            }
0578:
0579:            /**
0580:             * Returns the add button visible or not
0581:             */
0582:            public String getAddButtonCaption() {
0583:                if (_addButton == null)
0584:                    return null;
0585:                else
0586:                    return _addButton.getDisplayName();
0587:            }
0588:
0589:            /**
0590:             * Return the delete button visible or not
0591:             */
0592:            public boolean isDeleteButtonVisible() {
0593:                if (_deleteButton == null)
0594:                    return false;
0595:                else
0596:                    return _deleteButton.getVisible();
0597:            }
0598:
0599:            /**
0600:             * Returns the delete button caption
0601:             */
0602:            public String getDeleteButtonCaption() {
0603:                if (_deleteButton == null)
0604:                    return null;
0605:                else
0606:                    return _deleteButton.getDisplayName();
0607:            }
0608:
0609:            /**
0610:             * Return the cancel button visible or not
0611:             */
0612:            public boolean isCancelButtonVisible() {
0613:                if (_cancelButton == null)
0614:                    return false;
0615:                else
0616:                    return _cancelButton.getVisible();
0617:            }
0618:
0619:            /**
0620:             * Returns the cancel button caption
0621:             */
0622:            public String getCancelButtonCaption() {
0623:                if (_cancelButton == null)
0624:                    return null;
0625:                else
0626:                    return _cancelButton.getDisplayName();
0627:            }
0628:
0629:            /**
0630:             * Returns the font style for the buttons
0631:             */
0632:            public String getButtonFontStyle() {
0633:                if (_saveButton == null)
0634:                    return null;
0635:                else
0636:                    return _saveButton.getButtonFontStyle();
0637:            }
0638:
0639:            /**
0640:             * Returns the background color for the buttons
0641:             */
0642:            public String getButtonBgColor() {
0643:                if (_saveButton == null)
0644:                    return null;
0645:                else
0646:                    return _saveButton.getButtonBgColor();
0647:            }
0648:
0649:            /**
0650:             * Adds a button to the display box
0651:             */
0652:            public void addButton(HtmlSubmitButton b) {
0653:                _buttons.add(b);
0654:                add(b, TYPE_COMP);
0655:            }
0656:
0657:            /**
0658:             * Updates the display box button labels for the current language<br>
0659:             * The language property file must have the following key structure<br>
0660:             * FormDisplayBox.add represents the caption for the add button.<br>
0661:             * FormDisplayBox.save represents the caption for the save button.<br>
0662:             * FormDisplayBox.delete represents the caption for the delete button.<br>
0663:             * FormDisplayBox.cancel represents the caption for the cancel button.<br>
0664:             * FormDisplayBox.ok represents the caption for the ok button.<br>
0665:             * FormDisplayBox.undo represents the caption for the ok button.<br>
0666:             * DetailFormDisplayBox.editQuestion represents the question asked when the user wants to edit a row and there is unsaved data on the current row.<br>
0667:             * DetailFormDisplayBox.cancelQuestion represents the question asked when the user wants to cancel changes in a row.<br>
0668:             * DetailFormDisplayBox.addQuestion represents the question asked when the user wants to add a row and there is unsaved data on the current row.<br>
0669:             * DetailFormDisplayBox.deleteQuestion represents the confirm delete question.
0670:             **/
0671:            public void updateLocale() {
0672:                super .updateLocale();
0673:            }
0674:
0675:            protected void processLocaleInfo() {
0676:                if (_updateLocale) {
0677:                    _updateLocale = false;
0678:                    LanguagePreferences p = getPage().getLanguagePreferences();
0679:                    String appName = getPage().getApplicationName();
0680:                    String descr = null;
0681:                    String key = "FormDisplayBox.add";
0682:                    descr = LanguageResourceFinder.getResource(appName, key, p);
0683:                    if (descr != null)
0684:                        _addButtonCaption = descr;
0685:
0686:                    descr = null;
0687:                    key = "FormDisplayBox.save";
0688:                    descr = LanguageResourceFinder.getResource(appName, key, p);
0689:                    if (descr != null)
0690:                        _saveButtonCaption = descr;
0691:
0692:                    descr = null;
0693:                    key = "FormDisplayBox.cancel";
0694:                    descr = LanguageResourceFinder.getResource(appName, key, p);
0695:                    if (descr != null)
0696:                        _cancelButtonCaption = descr;
0697:
0698:                    descr = null;
0699:                    key = "FormDisplayBox.delete";
0700:                    descr = LanguageResourceFinder.getResource(appName, key, p);
0701:                    if (descr != null)
0702:                        _deleteButtonCaption = descr;
0703:
0704:                    descr = null;
0705:                    key = "DetailFormDisplayBox.addQuestion";
0706:                    descr = LanguageResourceFinder.getResource(appName, key, p);
0707:                    if (descr != null)
0708:                        _okToAddQuestion = descr;
0709:
0710:                    descr = null;
0711:                    key = "DetailFormDisplayBox.editQuestion";
0712:                    descr = LanguageResourceFinder.getResource(appName, key, p);
0713:                    if (descr != null)
0714:                        _okToEditQuestion = descr;
0715:
0716:                    descr = null;
0717:                    key = "DetailFormDisplayBox.cancelQuestion";
0718:                    descr = LanguageResourceFinder.getResource(appName, key, p);
0719:                    if (descr != null)
0720:                        _okToCancelQuestion = descr;
0721:
0722:                    descr = null;
0723:                    key = "DetailFormDisplayBox.deleteQuestion";
0724:                    descr = LanguageResourceFinder.getResource(appName, key, p);
0725:                    if (descr != null)
0726:                        _okToDeleteQuestion = descr;
0727:
0728:                    super .processLocaleInfo();
0729:                }
0730:            }
0731:
0732:            /**
0733:             * @return the location for displaying the buttons
0734:             */
0735:            public int getButtonDisplayLocation() {
0736:                return _buttonDisplayLocation;
0737:            }
0738:
0739:            /**
0740:             * Sets the display location for a button. Valid values are BUTTON_DISPLAY_IN_HEADER and BUTTON_DISPLAY_BOX_BELOW_TABLE
0741:             */
0742:            public void setButtonDisplayLocation(int loc) {
0743:                _buttonDisplayLocation = loc;
0744:            }
0745:
0746:            /**
0747:             * framework method, do not call directly
0748:             */
0749:            public boolean submitPerformed(SubmitEvent e) throws Exception {
0750:                if (e.getComponent() == _addButton)
0751:                    tryAdd();
0752:                else if (e.getComponent() == _saveButton)
0753:                    doSave();
0754:                else if (e.getComponent() == _cancelButton) {
0755:                    tryCancel();
0756:                } else if (e.getComponent() == _deleteButton) {
0757:                    tryDelete();
0758:                }
0759:                return true;
0760:            }
0761:
0762:            /**
0763:             * This method gets fired when the user clicks the cancel button. Subclasses can override it to customize behavior
0764:             */
0765:            public void doCancel() throws Exception {
0766:                if (_mode == MODE_LIST_OFF_PAGE)
0767:                    returnToListPage(false);
0768:                else if (getPageDataStoresStatus() == DataStoreBuffer.STATUS_NEW
0769:                        || getPageDataStoresStatus() == DataStoreBuffer.STATUS_NEW_MODIFIED) {
0770:                    try {
0771:                        doDelete();
0772:                    } catch (Exception e) {
0773:                    }
0774:                    return;
0775:                }
0776:                undoChanges();
0777:                scrollToMe();
0778:            }
0779:
0780:            /**
0781:             * This method gets fired when the user clicks the delete button. Subclasses can override it to customize behavior
0782:             */
0783:            public void doDelete() throws Exception {
0784:                _ds.deleteRow();
0785:                doDataStoreUpdate();
0786:                if (_mode == MODE_LIST_ON_PAGE) {
0787:                    if (_listForm != null && _listForm.getDataStore() != _ds) {
0788:                        //different datastores on list and detail
0789:                        DataStoreBuffer listDs = _listForm.getDataStore();
0790:                        if (_listSelectedRow != null) {
0791:                            for (int i = 0; i < listDs.getRowCount(); i++) {
0792:                                if (listDs.getDataStoreRow(i,
0793:                                        DataStoreBuffer.BUFFER_STANDARD)
0794:                                        .getDSDataRow() == _listSelectedRow
0795:                                        .getDSDataRow()) {
0796:                                    listDs.removeRow(i);
0797:                                    break;
0798:                                }
0799:                            }
0800:                        }
0801:                        if (listDs.getRowCount() == 0)
0802:                            setVisible(false);
0803:                        else {
0804:                            if (listDs.getRow() == -1)
0805:                                listDs.gotoRow(listDs.getRowCount() - 1);
0806:                            _listForm.setRowToEdit(listDs.getRow());
0807:                            doEdit();
0808:                        }
0809:                    } else {
0810:                        //list and detail share the same datastore
0811:                        if (_ds.getRowCount() == 0)
0812:                            setVisible(false);
0813:                        else
0814:                            scrollToMe();
0815:                    }
0816:                    syncListFormPage();
0817:                } else {
0818:                    returnToListPage(true);
0819:                }
0820:            }
0821:
0822:            /**
0823:             * This method gets fired when the user clicks the add button. Subclasses can override it to customize behavior
0824:             */
0825:            public void doAdd() {
0826:                if (_mode == MODE_LIST_ON_PAGE && _listForm != null) {
0827:                    DataStoreBuffer listDs = _listForm.getDataStore();
0828:                    DataStoreBuffer ds = getDataStore();
0829:                    if (listDs == ds && ds != null) {
0830:                        //same datastore on list and detail
0831:                        if (ds.getRowCount() > 0
0832:                                && (ds.getRowStatus() == DataStoreBuffer.STATUS_NEW))
0833:                            return;
0834:
0835:                        if (ds.getRowStatus() == DataStoreBuffer.STATUS_NEW_MODIFIED)
0836:                            ds.deleteRow();
0837:                        if (isDataModified())
0838:                            undoChanges();
0839:
0840:                        ds.insertRow();
0841:                        if (_listForm.getDataTable() != null) {
0842:                            JspDataTable tab = _listForm.getDataTable();
0843:                            if (!tab.isRowOnPage(ds.getRowCount() - 1))
0844:                                tab.setPage(tab.getPage(ds.getRowCount() - 1));
0845:                        }
0846:                        HtmlFormComponent comp = findFirstFormComponent(this );
0847:                        if (comp != null)
0848:                            comp.setFocus();
0849:                        scrollToMe();
0850:
0851:                    } else if (_ds != null) {
0852:                        //different datastores on list and detail
0853:                        if (listDs != null)
0854:                            listDs.clearSelectedRow();
0855:                        _listSelectedRow = null;
0856:                        _ds.reset();
0857:                        _ds.insertRow();
0858:                        HtmlFormComponent comp = findFirstFormComponent(this );
0859:                        if (comp != null)
0860:                            comp.setFocus();
0861:                        scrollToMe();
0862:                    }
0863:                    setVisible(true);
0864:                } else {
0865:                    _listSelectedRow = null;
0866:                    _ds.reset();
0867:                    _ds.insertRow();
0868:                    HtmlFormComponent comp = findFirstFormComponent(this );
0869:                    if (comp != null)
0870:                        comp.setFocus();
0871:                    scrollToMe();
0872:                }
0873:            }
0874:
0875:            /**
0876:             * Tries to do an add, but firsts checks for unsaved data
0877:             */
0878:            public void tryAdd() {
0879:                if (isDataModified()) {
0880:                    scrollToMe();
0881:                    if (getValidator().getUseAlertsForErrors()) {
0882:                        addConfirmScript(_okToAddQuestion, _okToAddValue);
0883:                    } else {
0884:                        _validator.setErrorMessage(_okToAddQuestion, null, -1,
0885:                                _okToAdd);
0886:                    }
0887:                } else {
0888:                    doAdd();
0889:                }
0890:            }
0891:
0892:            /**
0893:             * Tries to do an edit, but firsts checks for unsaved data
0894:             */
0895:            public void tryEdit() throws SQLException, DataStoreException,
0896:                    Exception {
0897:                if (isDataModified()) {
0898:                    scrollToMe();
0899:                    if (getValidator().getUseAlertsForErrors()) {
0900:                        addConfirmScript(_okToEditQuestion, _okToEditValue);
0901:                    } else {
0902:                        _validator.setErrorMessage(_okToEditQuestion, null, -1,
0903:                                _okToEdit);
0904:                    }
0905:                } else {
0906:                    doEdit();
0907:                }
0908:            }
0909:
0910:            /**
0911:             * Tries to do a cancel, but firsts checks for unsaved data
0912:             */
0913:            public void tryCancel() throws Exception {
0914:                if (!_displayOnly && isDataModified()) {
0915:                    scrollToMe();
0916:                    if (getValidator().getUseAlertsForErrors()) {
0917:                        addConfirmScript(_okToCancelQuestion, _okToCancelValue);
0918:                    } else {
0919:                        _validator.setErrorMessage(_okToCancelQuestion, null,
0920:                                -1, _okToCancel);
0921:                    }
0922:                } else {
0923:                    doCancel();
0924:                }
0925:            }
0926:
0927:            /**
0928:             * Tries to do an delete, but firsts checks with the user
0929:             */
0930:            public void tryDelete() throws Exception {
0931:                if (_confirmDelete
0932:                        && getPageDataStoresStatus() != DataStoreBuffer.STATUS_NEW) {
0933:                    scrollToMe();
0934:                    if (getValidator().getUseAlertsForErrors()) {
0935:                        addConfirmScript(_okToDeleteQuestion, _okToDeleteValue);
0936:                    } else {
0937:                        _validator.setErrorMessage(_okToDeleteQuestion, null,
0938:                                -1, _okToDelete);
0939:                    }
0940:                } else {
0941:                    doDelete();
0942:                }
0943:            }
0944:
0945:            /**
0946:             * This method gets fired when the user clicks the save button. Subclasses can override it to customize behavior
0947:             */
0948:            public void doSave() throws Exception {
0949:                if ((_listForm != null && _listForm.getDataStore() != _ds)
0950:                        || _mode == MODE_LIST_OFF_PAGE) {
0951:                    if (getPageDataStoresStatus() == DataStoreBuffer.STATUS_NEW) {
0952:                        doCancel();
0953:                        return;
0954:                    }
0955:                }
0956:                if (getDataStore() != null) {
0957:                    DataStoreBuffer dsb = getDataStore();
0958:                    try {
0959:                        doDataStoreUpdate();
0960:                    } catch (DirtyDataException ex) {
0961:                        if (_validator != null)
0962:                            _validator.addErrorMessage(_dirtyDataError);
0963:                    } catch (DataStoreException ex) {
0964:                        if (_validator != null)
0965:                            _validator.addErrorMessage(ex.getMessage(),
0966:                                    ((JspController) getPage())
0967:                                            .getBoundComponent(_ds, ex
0968:                                                    .getColumn()), ex.getRow());
0969:                    } catch (Exception ex) {
0970:                        if (_validator != null)
0971:                            _validator.addErrorMessage(ex.getMessage());
0972:                    }
0973:                }
0974:
0975:                if (_mode == MODE_LIST_ON_PAGE) {
0976:                    if (_reloadRowAfterSave) {
0977:                        if (_ds instanceof  DataStore)
0978:                            ((DataStore) _ds).reloadRow(_ds.getRow());
0979:                    }
0980:
0981:                    if (_listForm != null && _listForm.getDataStore() != _ds) {
0982:                        DataStoreRow source = _ds.getDataStoreRow(_ds.getRow(),
0983:                                DataStoreBuffer.BUFFER_STANDARD);
0984:                        if (_listSelectedRow != null)
0985:                            source.copyTo(_listSelectedRow);
0986:                        else {
0987:                            _listSelectedRow = _listForm.getDataStore()
0988:                                    .getDataStoreRow(
0989:                                            _listForm.getDataStore()
0990:                                                    .insertRow(),
0991:                                            DataStoreBuffer.BUFFER_STANDARD);
0992:                            source.copyTo(_listSelectedRow);
0993:                        }
0994:                        DataStoreBuffer dsb = _listForm.getDataStore();
0995:                        if (dsb != null && dsb instanceof  DataStore) {
0996:                            if (_reloadRowAfterSave) {
0997:                                dsb
0998:                                        .setRowStatus(DataStoreBuffer.STATUS_NOT_MODIFIED);
0999:                                ((DataStore) dsb).reloadRow();
1000:                            }
1001:                        }
1002:                    }
1003:
1004:                    syncListFormPage();
1005:                } else
1006:                    returnToListPage(true);
1007:            }
1008:
1009:            /**
1010:             * This method gets fired when the user clicks on a row in a list form. Subclasses can override it to customize behavior
1011:             */
1012:            public void doEdit() throws SQLException, DataStoreException,
1013:                    Exception {
1014:                if (_listForm != null) {
1015:                    if (_listForm.getDataStore() == _ds) {
1016:                        if (isDataModified()) {
1017:                            if (getPageDataStoresStatus() == DataStoreBuffer.STATUS_MODIFIED)
1018:                                undoChanges();
1019:                            else if (getPageDataStoresStatus() == DataStoreBuffer.STATUS_NEW_MODIFIED
1020:                                    || getPageDataStoresStatus() == DataStoreBuffer.STATUS_NEW)
1021:                                _ds.removeRow();
1022:                        }
1023:                        _ds.gotoRow(_listForm.getRowToEdit());
1024:                        setVisible(true);
1025:                        getPage().scrollToItem(getFullName() + "scrollToMe");
1026:                        HtmlFormComponent comp = findFirstFormComponent(this );
1027:                        if (comp != null)
1028:                            comp.setFocus();
1029:                    } else {
1030:                        DataStoreBuffer listDs = _listForm.getDataStore();
1031:                        int row = _listForm.getRowToEdit();
1032:                        if (listDs instanceof  DataStore
1033:                                && _ds instanceof  DataStore) {
1034:                            String table[] = _ds.getTableList(true);
1035:                            String where = null;
1036:                            for (int i = 0; i < table.length; i++) {
1037:                                String snippet = ((DataStore) listDs)
1038:                                        .buildCriteriaStringForRow(row,
1039:                                                table[i]);
1040:                                if (snippet != null) {
1041:                                    if (where == null)
1042:                                        where = snippet;
1043:                                    else
1044:                                        where += " and " + snippet;
1045:                                }
1046:                            }
1047:                            doDataStoreRetrieve(where);
1048:                        } else if (listDs instanceof  BeanDataStore) {
1049:                            String crit = ((BeanDataStore) listDs)
1050:                                    .buildCriteriaStringForRow(row);
1051:                            doDataStoreRetrieve(crit);
1052:                        }
1053:                        _ds.gotoFirst();
1054:                        listDs.gotoRow(row);
1055:                        _listSelectedRow = listDs.getDataStoreRow(row,
1056:                                DataStoreBuffer.BUFFER_STANDARD);
1057:                        getPage().scrollToItem(getFullName() + "scrollToMe");
1058:                        HtmlFormComponent comp = findFirstFormComponent(this );
1059:                        if (comp != null)
1060:                            comp.setFocus();
1061:
1062:                    }
1063:                }
1064:            }
1065:
1066:            /**
1067:             * returns the criteria validator the component is using to validate entered criteria
1068:             */
1069:            public HtmlValidatorText getValidator() {
1070:                return _validator;
1071:            }
1072:
1073:            /**
1074:             * @return
1075:             */
1076:            public DataStoreBuffer getDataStore() {
1077:                return _ds;
1078:            }
1079:
1080:            /**
1081:             * Set the access key for the add button
1082:             */
1083:            public void setAddButtonAccessKey(String key) {
1084:                _addButton.setAccessKey(key);
1085:            }
1086:
1087:            /**
1088:             * Set the access key for the save button
1089:             */
1090:            public void setSaveButtonAccessKey(String key) {
1091:                _saveButton.setAccessKey(key);
1092:            }
1093:
1094:            /**
1095:             * Set the access key for the delete button
1096:             */
1097:            public void setDeleteButtonAccessKey(String key) {
1098:                _deleteButton.setAccessKey(key);
1099:            }
1100:
1101:            /**
1102:             * Set the access key for the cancel button
1103:             */
1104:            public void setCancelButtonAccessKey(String key) {
1105:                _deleteButton.setAccessKey(key);
1106:            }
1107:
1108:            /**
1109:             * Sets the theme for the component
1110:             */
1111:            public void setTheme(String theme) {
1112:                super .setTheme(theme);
1113:                Props props = getPage().getPageProperties();
1114:                _saveButtonCaption = props.getThemeProperty(theme,
1115:                        Props.DETAIL_FORM_DISPLAY_BOX_SAVE_BUTTON_CAPTION);
1116:                _saveButtonAccessKey = props.getThemeProperty(theme,
1117:                        Props.DETAIL_FORM_DISPLAY_BOX_SAVE_BUTTON_ACCESS_KEY);
1118:                _addButtonCaption = props.getThemeProperty(theme,
1119:                        Props.DETAIL_FORM_DISPLAY_BOX_ADD_BUTTON_CAPTION);
1120:                _addButtonAccessKey = props.getThemeProperty(theme,
1121:                        Props.DETAIL_FORM_DISPLAY_BOX_ADD_BUTTON_ACCESS_KEY);
1122:                _deleteButtonCaption = props.getThemeProperty(theme,
1123:                        Props.DETAIL_FORM_DISPLAY_BOX_DELETE_BUTTON_CAPTION);
1124:                _deleteButtonAccessKey = props.getThemeProperty(theme,
1125:                        Props.DETAIL_FORM_DISPLAY_BOX_DELETE_BUTTON_ACCESS_KEY);
1126:                _cancelButtonCaption = props.getThemeProperty(theme,
1127:                        Props.DETAIL_FORM_DISPLAY_BOX_CANCEL_BUTTON_CAPTION);
1128:                _cancelButtonAccessKey = props.getThemeProperty(theme,
1129:                        Props.DETAIL_FORM_DISPLAY_BOX_CANCEL_BUTTON_ACCESS_KEY);
1130:
1131:                String st = props.getThemeProperty(theme,
1132:                        Props.DETAIL_FORM_DISPLAY_BOX_BUTTON_LOCATION);
1133:                if (st != null) {
1134:                    if (st.equalsIgnoreCase("BELOW_TABLE"))
1135:                        setButtonDisplayLocation(BUTTON_DISPLAY_BELOW_TABLE);
1136:                    else if (st.equalsIgnoreCase("IN_HEADER"))
1137:                        setButtonDisplayLocation(BUTTON_DISPLAY_IN_HEADER);
1138:                }
1139:                st = props.getThemeProperty(theme,
1140:                        Props.DETAIL_FORM_DISPLAY_BOX_BOTTOM_BUTTON_ALIGN);
1141:                if (st != null)
1142:                    setBottomButtonAlign(st);
1143:                setUpButtons();
1144:            }
1145:
1146:            protected void setUpButtons() {
1147:                super .setUpButtons();
1148:                if (_saveButton != null) {
1149:                    if (_saveButtonCaption != null)
1150:                        _saveButton.setDisplayName(_saveButtonCaption);
1151:                    if (_saveButtonAccessKey != null)
1152:                        _saveButton.setAccessKey(_saveButtonAccessKey);
1153:                }
1154:                if (_addButton != null) {
1155:                    if (_addButtonCaption != null)
1156:                        _addButton.setDisplayName(_addButtonCaption);
1157:                    if (_addButtonAccessKey != null)
1158:                        _addButton.setAccessKey(_addButtonAccessKey);
1159:                }
1160:                if (_cancelButton != null) {
1161:                    if (_cancelButtonCaption != null)
1162:                        _cancelButton.setDisplayName(_cancelButtonCaption);
1163:                    if (_cancelButtonAccessKey != null)
1164:                        _cancelButton.setAccessKey(_cancelButtonAccessKey);
1165:                }
1166:                if (_deleteButton != null) {
1167:                    if (_deleteButtonCaption != null)
1168:                        _deleteButton.setDisplayName(_deleteButtonCaption);
1169:                    if (_deleteButtonAccessKey != null)
1170:                        _deleteButton.setAccessKey(_deleteButtonAccessKey);
1171:                }
1172:                if (_okToAddButton != null && _okButtonCap != null)
1173:                    _okToAddButton.setDisplayName(_okButtonCap);
1174:                if (_okToDeleteButton != null && _okButtonCap != null)
1175:                    _okToDeleteButton.setDisplayName(_okButtonCap);
1176:                if (_okToCancelButton != null && _okButtonCap != null)
1177:                    _okToCancelButton.setDisplayName(_okButtonCap);
1178:                if (_okToEditButton != null && _okButtonCap != null)
1179:                    _okToEditButton.setDisplayName(_okButtonCap);
1180:                if (_cancelMessageButton != null && _cancelButtonCap != null)
1181:                    _cancelMessageButton.setDisplayName(_cancelButtonCap);
1182:            }
1183:
1184:            /**
1185:             * Returns true if the data in the detail has been modified
1186:             */
1187:            public boolean isDataModified() {
1188:                int stat = getPageDataStoresStatus();
1189:
1190:                if (stat == DataStoreBuffer.STATUS_MODIFIED)
1191:                    return true;
1192:                else if (stat == DataStoreBuffer.STATUS_NEW_MODIFIED)
1193:                    return true;
1194:                else if (stat == DataStoreBuffer.STATUS_NEW)
1195:                    return true;
1196:                else
1197:                    return false;
1198:            }
1199:
1200:            private void scrollToMe() {
1201:                getPage().scrollToItem(getFullName() + "scrollToMe");
1202:            }
1203:
1204:            /**
1205:             * @return whether or not the form will confirm deletes
1206:             */
1207:            public boolean getConfirmDelete() {
1208:                return _confirmDelete;
1209:            }
1210:
1211:            /**
1212:             * sets whether or not the form will confirm deletes
1213:             */
1214:            public void setConfirmDelete(boolean b) {
1215:                _confirmDelete = b;
1216:            }
1217:
1218:            /**
1219:             * @return the question asked when tryAdd() is called with modified data in the form
1220:             */
1221:            public String getOkToAddQuestion() {
1222:                return _okToAddQuestion;
1223:            }
1224:
1225:            /**
1226:             * @return the question asked when tryCancel() is called with modified data in the form
1227:             */
1228:            public String getOkToCancelQuestion() {
1229:                return _okToCancelQuestion;
1230:            }
1231:
1232:            /**
1233:             * @return the question asked if confirmDelete is true and the user tries to delete a row
1234:             */
1235:            public String getOkToDeleteQuestion() {
1236:                return _okToDeleteQuestion;
1237:            }
1238:
1239:            /**
1240:             * @return the question asked when tryEdit() is called with modified data in the form
1241:             */
1242:            public String getOkToEditQuestion() {
1243:                return _okToEditQuestion;
1244:            }
1245:
1246:            /**
1247:             * set the question asked when tryAdd() is called with modified data in the form
1248:             **/
1249:            public void setOkToAddQuestion(String string) {
1250:                _okToAddQuestion = string;
1251:            }
1252:
1253:            /**
1254:             * set the question asked when tryCancel() is called with modified data in the form
1255:             **/
1256:            public void setOkToCancelQuestion(String string) {
1257:                _okToCancelQuestion = string;
1258:            }
1259:
1260:            /**
1261:             * sets the question asked if confirmDelete is true and the user tries to delete a row
1262:             */
1263:            public void setOkToDeleteQuestion(String string) {
1264:                _okToDeleteQuestion = string;
1265:            }
1266:
1267:            /**
1268:             * set the question asked when tryEdit() is called with modified data in the form
1269:             **/
1270:            public void setOkToEditQuestion(String string) {
1271:                _okToEditQuestion = string;
1272:            }
1273:
1274:            /**
1275:             * @return the operation mode of the component. Valid values are MODE_LIST_OFF_PAGE and MODE_LIST_ON_PAGE.
1276:             */
1277:            public int getMode() {
1278:                return _mode;
1279:            }
1280:
1281:            /**
1282:             * Sets the operational mode of the component. Valid values are MODE_LIST_OFF_PAGE and MODE_LIST_ON_PAGE.
1283:             */
1284:            public void setMode(int i) {
1285:                _mode = i;
1286:            }
1287:
1288:            private void syncListFormPage() {
1289:                //check to see if the datatable now is beyond the last row. If so adjust the page
1290:                if (_listForm != null && _listForm.getDataTable() != null) {
1291:                    DataStoreBuffer listFormDs = _listForm.getDataStore();
1292:                    JspDataTable listFormDataTable = _listForm.getDataTable();
1293:                    if (listFormDs != null && listFormDataTable != null) {
1294:                        if (listFormDs.getRow() != -1) {
1295:                            if (!listFormDataTable.isRowOnPage(listFormDs
1296:                                    .getRow())) {
1297:                                listFormDataTable.setPage(listFormDataTable
1298:                                        .getPage(listFormDs.getRow()));
1299:                            }
1300:                        }
1301:                    }
1302:                }
1303:            }
1304:
1305:            public void returnToListPage(boolean refresh) {
1306:                if (_mode == MODE_LIST_OFF_PAGE && _returnTo != null) {
1307:                    String ret = _returnTo;
1308:                    if (refresh)
1309:                        ret += "?refresh=true";
1310:                    try {
1311:                        getPage().getCurrentResponse().sendRedirect(ret);
1312:                    } catch (IOException e) {
1313:                        MessageLog.writeErrorMessage("returnToListPage", e,
1314:                                this );
1315:                    }
1316:                }
1317:            }
1318:
1319:            /**
1320:             * Override this method in subclasses to change the way the datastore is updated
1321:             */
1322:            public void doDataStoreUpdate() throws Exception {
1323:                DataStoreBuffer ds = getDataStore();
1324:                if (ds instanceof  DataStore)
1325:                    ((DataStore) ds).update();
1326:                else if (ds instanceof  BeanDataStore)
1327:                    ((BeanDataStore) ds).update();
1328:            }
1329:
1330:            /**
1331:             * Override this method in subclasses to change the way the datastore is retrieved
1332:             */
1333:            public void doDataStoreRetrieve(String where) throws Exception {
1334:                if (where != null && where.length() == 0)
1335:                    where = null;
1336:                DataStoreBuffer ds = getDataStore();
1337:                if (ds instanceof  DataStore)
1338:                    ((DataStore) ds).retrieve(where);
1339:                else if (ds instanceof  BeanDataStore)
1340:                    ((BeanDataStore) ds).retrieve(where);
1341:            }
1342:
1343:            /**
1344:             * @return the Add button used by this component
1345:             */
1346:            public HtmlSubmitButton getAddButton() {
1347:                return _addButton;
1348:            }
1349:
1350:            /**
1351:             * @return the Cancelbutton used by this component
1352:             */
1353:            public HtmlSubmitButton getCancelButton() {
1354:                return _cancelButton;
1355:            }
1356:
1357:            /**
1358:             * @return the Delete button used by this component
1359:             */
1360:            public HtmlSubmitButton getDeleteButton() {
1361:                return _deleteButton;
1362:            }
1363:
1364:            /**
1365:             * @return the Save button used by this component
1366:             */
1367:            public HtmlSubmitButton getSaveButton() {
1368:                return _saveButton;
1369:            }
1370:
1371:            /**
1372:             * @return true if the row will be reloaded from the database after a save
1373:             */
1374:            public boolean getReloadRowAfterSave() {
1375:                return _reloadRowAfterSave;
1376:            }
1377:
1378:            /**
1379:             * Set to true to have the row reloaded from the database after a save
1380:             */
1381:            public void setReloadRowAfterSave(boolean b) {
1382:                _reloadRowAfterSave = b;
1383:            }
1384:
1385:            /**
1386:             * Adds a button to the display box at the specified position.
1387:             */
1388:            public void addButton(int i, HtmlSubmitButton b) {
1389:                _buttons.add(i, b);
1390:                add(b, TYPE_COMP);
1391:
1392:            }
1393:
1394:            /**
1395:             * Restores the detail form to the state it was when it was first loaded.
1396:             */
1397:            public void undoChanges() {
1398:                if (getPageDataStoresStatus() == DataStoreBuffer.STATUS_NOT_MODIFIED)
1399:                    return;
1400:                else
1401:                    _ds.undoChanges(_ds.getRow());
1402:            }
1403:
1404:            /**
1405:             * This method returns a status flag for the datastores related with this detail form.
1406:             * Override if you have more than one datastore in your page (ie other datastores besides the one of the detail form).
1407:             */
1408:            public int getPageDataStoresStatus() {
1409:                return _ds.getRowStatus();
1410:            }
1411:
1412:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.