Source Code Cross Referenced for UIDropDown.java in  » ERP-CRM-Financial » SourceTap-CRM » com » sourcetap » sfa » ui » 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 » ERP CRM Financial » SourceTap CRM » com.sourcetap.sfa.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * 
003:         * Copyright (c) 2004 SourceTap - www.sourcetap.com
004:         *
005:         *  The contents of this file are subject to the SourceTap Public License 
006:         * ("License"); You may not use this file except in compliance with the 
007:         * License. You may obtain a copy of the License at http://www.sourcetap.com/license.htm
008:         * Software distributed under the License is distributed on an  "AS IS"  basis,
009:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
010:         * the specific language governing rights and limitations under the License.
011:         *
012:         * The above copyright notice and this permission notice shall be included
013:         * in all copies or substantial portions of the Software.
014:         *
015:         */
016:
017:        package com.sourcetap.sfa.ui;
018:
019:        import java.util.ArrayList;
020:        import java.util.HashMap;
021:        import java.util.Iterator;
022:        import java.util.LinkedList;
023:        import java.util.List;
024:        import java.util.Map;
025:        import java.util.Vector;
026:
027:        import org.ofbiz.base.util.Debug;
028:        import org.ofbiz.entity.GenericDelegator;
029:        import org.ofbiz.entity.GenericEntityException;
030:        import org.ofbiz.entity.GenericValue;
031:
032:        import com.sourcetap.sfa.util.UserInfo;
033:
034:        /**
035:         * This class is used by the UI builder to display a drop down list on the screen.
036:         *
037:         * @author  <a href='mailto:steve_fowler@sourcetap.com'>Steve Fowler</a>
038:         * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
039:         */
040:        public class UIDropDown {
041:            public static final String module = UIDropDown.class.getName();
042:
043:            /**
044:             * Constructor
045:             */
046:            public UIDropDown() {
047:            }
048:
049:            /**
050:             * Return a list of values for a drop down using a UI Display Object defined in the data base.
051:             * This method should be overridden in a custom class for custom drop down population.  Note: This
052:             * method is only used when the screen is first drawn.  If the drop down list is updated dynamically, the
053:             * getDropDownValuesDynamic method is used.
054:             *
055:             * @see #getDropDownValuesDynamic(GenericDelegator, Map, UserInfo)
056:             *
057:             * @author  <a href='mailto:steve_fowler@telluridetechnologies.com'>Steve Fowler</a>
058:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
059:             *
060:             * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
061:             * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
062:             * @param orderDef List of fields defining the sort order of the drop down values
063:             * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
064:             * @param fieldInfo Reference to field info object containing attributes of the current field
065:             * @param userInfo Reference to user info object containing information about the currently logged-in user
066:             *
067:             * @return List of generic values to be displayed in the drop down.  This will be null if an error occurs.
068:             */
069:            public List getDropDownValues(GenericDelegator delegator,
070:                    UIDisplayObject uiDisplayObject, ArrayList orderDef,
071:                    Vector entityDetailsVector, UIFieldInfo fieldInfo,
072:                    UserInfo userInfo) {
073:                // Use the find method display attribute of the display object.
074:                if (uiDisplayObject.getAttribEntityFindMethod().equals("ALL")) {
075:                    // Find all entities.
076:                    try {
077:                        return delegator.findAllCache(uiDisplayObject
078:                                .getAttribEntity(), orderDef);
079:                    } catch (GenericEntityException e) {
080:                        Debug.logError("Error searching for drop down values: "
081:                                + e.getLocalizedMessage(), module);
082:
083:                        return null;
084:                    }
085:                } else if (uiDisplayObject.getAttribEntityFindMethod().equals(
086:                        "ATTRIBUTE_MATCH")) {
087:                    // Need to find only selected entities.
088:                    if (uiDisplayObject.getAttribEntityFindDef().trim().equals(
089:                            "")) {
090:                        // The find definition not specified. Can't do the find. Return empty List.
091:                        Debug
092:                                .logWarning(
093:                                        "Attribute ENTITY_FIND_DEF not specified in display object.",
094:                                        module);
095:
096:                        return null;
097:                    }
098:
099:                    // Decode the entity find definition into a hash map that can be passed
100:                    // to the findByAnd function.
101:                    Debug.logVerbose(
102:                            "About to call decodeEntityFindDef to decode find def '"
103:                                    + uiDisplayObject.getAttribEntityFindDef()
104:                                    + "'.", module);
105:
106:                    HashMap entityFindMap = UIUtility.decodeEntityFindDef(
107:                            uiDisplayObject.getAttribEntityFindDef(),
108:                            entityDetailsVector, fieldInfo.getUiAttribute()
109:                                    .getAttributeName());
110:
111:                    if (entityFindMap == null) {
112:
113:                        Debug.logError("Invalid ENTITY_FIND_DEF definition: '"
114:                                + uiDisplayObject.getAttribEntityFindDef()
115:                                + "'", module);
116:
117:                        return null;
118:                    }
119:
120:                    Debug.logVerbose(
121:                            "Finished calling decodeEntityFindDef to decode find def '"
122:                                    + uiDisplayObject.getAttribEntityFindDef()
123:                                    + "'.", module);
124:                    Debug.logVerbose("entityFindMap           -> "
125:                            + entityFindMap.toString(), module);
126:
127:                    try {
128:                        return delegator.findByAndCache(uiDisplayObject
129:                                .getAttribEntity(), entityFindMap, orderDef);
130:                    } catch (GenericEntityException e) {
131:                        Debug.logError(
132:                                "Error searching for drop down values by And: "
133:                                        + e.getLocalizedMessage(), module);
134:
135:                        return null;
136:                    }
137:                } else if (uiDisplayObject.getAttribEntityFindMethod().equals(
138:                        "CUSTOM_CLASS")) {
139:                    // There is a custom class built to find only selected entities to the drop down.
140:                    // The descendent object should take care of this.
141:                    Debug.logWarning("Method should be overriddent in class "
142:                            + uiDisplayObject.getAttribEntityFindDef() + "!",
143:                            module);
144:
145:                    return null;
146:                } else {
147:                    // Invalid find method.
148:                    // Just create a hidden field AND show the value as text in the table cell.
149:                    Debug.logWarning(
150:                            "[UIDropDown.displayField]: Invalid find method: '"
151:                                    + uiDisplayObject
152:                                            .getAttribEntityFindMethod() + "'",
153:                            module);
154:
155:                    return null;
156:                }
157:            }
158:
159:            /**
160:             * Looks up the read-only value for the field to be shown on the screen instead
161:             * of a drop down select because the mode is read-only.
162:             *
163:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
164:             *
165:             * @param fieldValue Value stored or to be stored in the data base. Used as the primary key to look up the value to be displayed.
166:             * @param attributeName Name of the attribute being displayed
167:             * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
168:             * @param entityDetailsVector Vector that holds one or more generic values from which the display value can be decoded
169:             * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
170:             *
171:             * @return Array containing the data value and display value.
172:             */
173:            public GenericValue getReadOnlyValue(String fieldValue,
174:                    String attributeName, UIDisplayObject uiDisplayObject,
175:                    Vector entityDetailsVector, GenericDelegator delegator) {
176:
177:                return UIUtility.getReadOnlyValue(fieldValue, attributeName,
178:                        uiDisplayObject, entityDetailsVector, delegator);
179:            }
180:
181:            /**
182:             * Return an array of data value/display value pairs to be passed to the getDisplayHtml
183:             * method.  In this root version of this method, the list of generic values returned by
184:             * the getDropDownValues is simlply converted to an array using the decodeValueArray
185:             * method.  However, this method may be overridden in the descendent if special processing
186:             * is needed, as may be the case when two different types of entities are to be combined
187:             * into the same drop list.
188:             *
189:             * @see #getDropDownValues(GenericDelegator, UIDisplayObject, ArrayList, Vector, UIFieldInfo, UserInfo)
190:             * @see #decodeValueArray(String, String, String, List)
191:             *
192:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
193:             *
194:             * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
195:             * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
196:             * @param orderDef List of fields defining the sort order of the drop down values
197:             * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
198:             * @param fieldInfo Reference to field info object containing attributes of the current field
199:             * @param userInfo Reference to user info object containing information about the currently logged-in user
200:             *
201:             * @return List of generic values to be displayed in the drop down.  This will be null if an error occurs.
202:             */
203:            public String[][] getValuePairArray(GenericDelegator delegator,
204:                    UIDisplayObject uiDisplayObject, ArrayList orderDef,
205:                    Vector entityDetailsVector, UIFieldInfo fieldInfo,
206:                    UserInfo userInfo) {
207:                return decodeValueArray(uiDisplayObject
208:                        .getAttribEntityValueDef(), uiDisplayObject
209:                        .getAttribEntityDisplayDef(), fieldInfo
210:                        .getUiAttribute().getAttributeName(),
211:                        getDropDownValues(delegator, uiDisplayObject, orderDef,
212:                                entityDetailsVector, fieldInfo, userInfo));
213:            }
214:
215:            /**
216:             * Return a data value/display value pair to be passed to the getSelectHtmlReadOnly
217:             * method.  In this root version of this method, the generic value returned by
218:             * the getReadOnlyValue method is simlply converted to an array using the decodeValue
219:             * method.  However, this method may be overridden in the descendent if special processing
220:             * is needed, as may be the case when two different types of entities are to be combined
221:             * into the same drop list.
222:             *
223:             * @see #getReadOnlyValue(String, String, UIDisplayObject, Vector, GenericDelegator)
224:             * @see #decodeValue(String, String, String, Object)
225:             * @see #getSelectHtmlReadOnly(String, String, String, UIDisplayObject, String[], GenericDelegator)
226:             *
227:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
228:             *
229:             * @param fieldValue Value of field being displayed
230:             * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
231:             * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
232:             * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
233:             * @param fieldInfo Reference to field info object containing attributes of the current field
234:             * @param userInfo Reference to user info object containing information about the currently logged-in user
235:             * @param linkGenericValue Generic value returned to calling method
236:             *
237:             * @return One-dimensional array with 2 elements containing the data value and the display value.
238:             */
239:            public String[] getValuePair(String fieldValue,
240:                    GenericDelegator delegator,
241:                    UIDisplayObject uiDisplayObject,
242:                    Vector entityDetailsVector, UIFieldInfo fieldInfo,
243:                    UserInfo userInfo, GenericValue linkGenericValue) {
244:                linkGenericValue = getReadOnlyValue(fieldValue, fieldInfo
245:                        .getUiAttribute().getAttributeName(), uiDisplayObject,
246:                        entityDetailsVector, delegator);
247:
248:                return decodeValue(uiDisplayObject.getAttribEntityValueDef(),
249:                        uiDisplayObject.getAttribEntityDisplayDef(), fieldInfo
250:                                .getUiAttribute().getAttributeName(),
251:                        linkGenericValue);
252:            }
253:
254:            /**
255:             * Return a list of values based on filter criteria.  This is used by the dynamic filtered drop downs
256:             * which are modified via DHTML.  This method must be overridden in a desdendent class.<BR><BR>Note: This method
257:             * is only used when the drop down is updated dynamically.
258:             * When the screen is first displayed, the getDropDownValues method is used.
259:             *
260:             * @see #getDropDownValues(GenericDelegator, UIDisplayObject, ArrayList, Vector, UIFieldInfo, UserInfo)
261:             *
262:             * @author  <a href='mailto:steve_fowler@sourcetap.com'>Steve Fowler</a>
263:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
264:             *
265:             * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
266:             * @param filterValues Map containing field/value pairs to be used for filtering the drop down list
267:             * @param userInfo Reference to user info object containing information about the currently logged-in user
268:             *
269:             * @return List of generic values to be displayed in the drop down.  This will be null if an error occurs.
270:             */
271:            public List getDropDownValuesDynamic(GenericDelegator delegator,
272:                    Map filterValues, UserInfo userInfo) {
273:                return new LinkedList();
274:            }
275:
276:            /**
277:             * Produces an HTML string to display the drop down on a web page being built by the UIWebScreenSection class.
278:             * If the screen is being displayed in read-only mode, this method looks up the specified name value using the
279:             * current value as the primary key, and displays the looked up name instead of a drop down.
280:             *
281:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
282:             *
283:             * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
284:             * @param protect Defines wether to show the current field in protected (read-only)_ mode
285:             * @param htmlName The name to be used for the current field in the HTML
286:             * @param fieldValue Value stored or to be stored in the data base
287:             * @param entityDetailsVector Vector of generic values containing the values to be displayed on the screen for all fields
288:             * @param fieldInfo Reference to field info object containing attributes of the current field
289:             * @param action Action string defining the current screen mode.  See UIScreenSection for possible values.
290:             * @param tabIndex Tab index (tab order) of the current field on the HTML form
291:             * @param userInfo Reference to user info object containing information about the currently logged-in user
292:             * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
293:             *
294:             * @return String containing the HTML text that will draw the current field on the web page
295:             *
296:             * @see com.sourcetap.sfa.ui.UIWebScreenSection
297:             */
298:            public String displayFieldHtml(UIDisplayObject uiDisplayObject,
299:                    boolean protect, String htmlName, String fieldValue,
300:                    Vector entityDetailsVector, UIFieldInfo fieldInfo,
301:                    String action, int tabIndex, UserInfo userInfo,
302:                    GenericDelegator delegator) {
303:                StringBuffer displayHtml = new StringBuffer();
304:
305:                // Build a drop down list.
306:                if (uiDisplayObject.getAttribFillMethod().equals("ENTITY")) {
307:                    // Need to build the list using entity data from the data base.
308:                    if (!protect) {
309:                        // Mode is not protected, so create a drop down.
310:                        Debug.logVerbose("Starting to create a drop down.",
311:                                module);
312:
313:                        if (uiDisplayObject.getAttribEntityValueDef().trim()
314:                                .equals("")) {
315:                            // Value definition not specified.
316:                            // Just create a hidden field AND show the value as text in the table cell.
317:                            displayHtml.append(UIWebUtility
318:                                    .displayFieldReadOnly(uiDisplayObject,
319:                                            htmlName, fieldValue, fieldValue,
320:                                            entityDetailsVector));
321:                            Debug
322:                                    .logWarning(
323:                                            "[UIDropDown.displayField]: Attribute ENTITY_VALUE_DEF not specified in display object.",
324:                                            module);
325:
326:                            return displayHtml.toString();
327:                        }
328:
329:                        if (uiDisplayObject.getAttribEntityDisplayDef().trim()
330:                                .equals("")) {
331:                            // Display definition not specified.
332:                            // Just create a hidden field AND show the value as text in the table cell.
333:                            displayHtml.append(UIWebUtility
334:                                    .displayFieldReadOnly(uiDisplayObject,
335:                                            htmlName, fieldValue, fieldValue,
336:                                            entityDetailsVector));
337:                            Debug
338:                                    .logWarning(
339:                                            "[UIDropDown.displayField]: Attribute ENTITY_DISPLAY_DEF not specified in display object.",
340:                                            module);
341:
342:                            return displayHtml.toString();
343:                        }
344:
345:                        ArrayList orderDef = null;
346:
347:                        if (!uiDisplayObject.getAttribEntityOrderDef().trim()
348:                                .equals("")) {
349:                            orderDef = new ArrayList();
350:                            orderDef.add(uiDisplayObject
351:                                    .getAttribEntityOrderDef());
352:                        }
353:
354:                        // Find the entities for the list, and put them in a 2-dimensional array
355:                        String[][] valuePairArray = getValuePairArray(
356:                                delegator, uiDisplayObject, orderDef,
357:                                entityDetailsVector, fieldInfo, userInfo);
358:
359:                        if (valuePairArray == null) {
360:                            // An error occurred while getting the drop down values.  Just show the field value as read-only.
361:                            displayHtml.append(UIWebUtility
362:                                    .displayFieldReadOnly(uiDisplayObject,
363:                                            htmlName, fieldValue, fieldValue,
364:                                            entityDetailsVector));
365:
366:                            return displayHtml.toString();
367:                        }
368:
369:                        boolean showMultiple = false;
370:
371:                        if (action.equals(UIScreenSection.ACTION_SHOW_QUERY)) {
372:                            // Show a multi-select list box if the screen is being displayed in query mode.
373:                            //showMultiple = true;
374:                            showMultiple = false; // changed due to creation of advanced query mode.
375:                        }
376:
377:                        // Append the HTML for the SELECT.
378:                        displayHtml.append(getSelectHtml(htmlName, tabIndex,
379:                                uiDisplayObject.getAttribSize(),
380:                                uiDisplayObject.getAttribDisabled(),
381:                                uiDisplayObject.getAttribClass(action,
382:                                        fieldInfo.getIsMandatory()),
383:                                uiDisplayObject.getAttribEmptyFirst(action),
384:                                uiDisplayObject.getAttribEventHandling(),
385:                                valuePairArray, fieldValue, showMultiple));
386:
387:                        if (fieldInfo.getIsMandatory()
388:                                && !action
389:                                        .equals(UIScreenSection.ACTION_SHOW_QUERY)
390:                                && !action
391:                                        .equals(UIScreenSection.ACTION_SHOW_QUERY_REPORT)
392:                                && !action
393:                                        .equals(UIScreenSection.ACTION_SHOW_REPORT)) {
394:                            displayHtml.append("*\n");
395:                        }
396:
397:                        return displayHtml.toString();
398:                    } else {
399:                        // User can't edit right now, so there's no point in showing the list. Just look up the
400:                        // the display value and show it.
401:                        GenericValue linkGenericValue = null;
402:                        String[] valuePair = getValuePair(fieldValue,
403:                                delegator, uiDisplayObject,
404:                                entityDetailsVector, fieldInfo, userInfo,
405:                                linkGenericValue);
406:
407:                        if (valuePair == null) {
408:                            // An error occurred while getting the read only value.  Just show the field value as read-only.
409:                            displayHtml.append(UIWebUtility
410:                                    .displayFieldReadOnly(uiDisplayObject,
411:                                            htmlName, fieldValue, fieldValue,
412:                                            new Vector()));
413:
414:                            return displayHtml.toString();
415:                        }
416:
417:                        displayHtml
418:                                .append(getSelectHtmlReadOnly(
419:                                        fieldValue,
420:                                        htmlName,
421:                                        fieldInfo.getUiAttribute()
422:                                                .getAttributeName(),
423:                                        uiDisplayObject,
424:                                        valuePair,
425:                                        UIWebUtility
426:                                                .translateAttribAnchorHrefDef(
427:                                                        uiDisplayObject
428:                                                                .getAttribAnchorHrefDef(),
429:                                                        entityDetailsVector,
430:                                                        fieldInfo
431:                                                                .getUiAttribute()
432:                                                                .getAttributeName()),
433:                                        UIWebUtility
434:                                                .translateAttribAnchorTarget(uiDisplayObject
435:                                                        .getAttribAnchorTarget()),
436:                                        delegator));
437:
438:                        return displayHtml.toString();
439:                    }
440:                } else if (uiDisplayObject.getAttribFillMethod()
441:                        .equals("FIXED")) {
442:                    // Build the list using the fixed values.
443:
444:                    // *** Not completed ***
445:                    displayHtml.append(UIWebUtility.displayFieldReadOnly(
446:                            uiDisplayObject, htmlName, fieldValue, fieldValue,
447:                            entityDetailsVector));
448:
449:                    return displayHtml.toString();
450:                } else {
451:                    // Invalid Fill Method.  Just create a hidden field AND show the value as text in the table cell.
452:                    Debug.logWarning(
453:                            "[UIDropDown.displayField()] Fill method for field "
454:                                    + htmlName + "("
455:                                    + uiDisplayObject.getDisplayObjectId()
456:                                    + ") is invalid: "
457:                                    + uiDisplayObject.getAttribFillMethod(),
458:                            module);
459:                    displayHtml.append(UIWebUtility.displayFieldReadOnly(
460:                            uiDisplayObject, htmlName, fieldValue, fieldValue,
461:                            entityDetailsVector));
462:
463:                    return displayHtml.toString();
464:                }
465:            }
466:
467:            /**
468:             * Produces an HTML string to display the drop down on a web page.
469:             * <P>
470:             * This method does not need a reference to the delegator since it does not connect to the data base.
471:             * The values are passed in the genericValueVectorList parameter.  This method also does not need
472:             * a reference to a UIDisplayObject or a UIFieldInfo, so it can be used separately from the UI Builder
473:             * if required.
474:             *
475:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
476:             *
477:             * @param htmlName The name to be used for the current field in the HTML
478:             * @param tabIndex Tab index (tab order) of the current field on the HTML form
479:             * @param attribSize String for the HTML SIZE attribute to be inserted into the < SELECT >
480:             * @param attribDisabled String for the HTML SIZE attribute to be inserted into the < SELECT >
481:             * @param attribClass String for the HTML CLASS attribute to be inserted into the < SELECT >
482:             * @param attribEmptyFirst String defining whether to include a blank option at the top of the select list
483:             * @param attribEventHandling String to be embedded in the < SELECT > for event handling.  Example: 'onChange="window.open(...)";'
484:             * @param selectPairArray Array containing pairs of values.  selectPair[0][0] contains the data value for the first row, and selectPair[0][1] contains the display value for the first row.
485:             * @param selectedValue Value stored or to be stored in the data base. Detemines which item in the list will be selected initially.
486:             * @param showMultiple Indicates whether to show the list as a list box and allow multiple items to be selected (true), or as a regular drop down list (false)
487:             *
488:             * @return String containing the HTML text that will draw the < SELECT > on the web page
489:             */
490:            public static String getSelectHtml(String htmlName, int tabIndex,
491:                    String attribSize, String attribDisabled,
492:                    String attribClass, String attribEmptyFirst,
493:                    String attribEventHandling, String[][] selectPairArray,
494:                    String selectedValue, boolean showMultiple) {
495:                StringBuffer displayHtml = new StringBuffer();
496:
497:                // Build the HTML for the SELECT.
498:                displayHtml.append("<SELECT NAME=\"" + htmlName
499:                        + "\" tabindex=\"" + tabIndex + "\" ");
500:                displayHtml
501:                        .append(UIWebUtility.translateAttribSize(attribSize));
502:                displayHtml.append(UIWebUtility
503:                        .translateAttribDisabled(attribDisabled));
504:                displayHtml.append(UIWebUtility
505:                        .translateAttribClass(attribClass));
506:                displayHtml.append(UIWebUtility
507:                        .translateAttribEventHandling(attribEventHandling));
508:
509:                if (showMultiple) {
510:                    displayHtml.append(" MULTIPLE");
511:                }
512:
513:                displayHtml.append(">\n");
514:
515:                if (attribEmptyFirst.equals("Y")) {
516:                    displayHtml.append("<OPTION VALUE=\"\"></OPTION>\n");
517:                }
518:
519:                // Loop through the value/display pairs and create the SELECT.
520:                for (int itemIndex = 0; itemIndex < selectPairArray.length; itemIndex++) {
521:                    String optionValue = selectPairArray[itemIndex][0];
522:                    String optionDisplay = selectPairArray[itemIndex][1];
523:
524:                    Debug.logVerbose("optionValue: " + optionValue, module);
525:                    Debug.logVerbose("optionDisplay: " + optionDisplay, module);
526:
527:                    displayHtml.append("<OPTION VALUE=\"" + optionValue + "\"");
528:
529:                    if (optionValue.equals(selectedValue)) {
530:                        displayHtml.append(" SELECTED");
531:                    }
532:
533:                    displayHtml.append(">" + optionDisplay + "</OPTION>\n");
534:                }
535:
536:                displayHtml.append("</SELECT>");
537:
538:                Debug.logVerbose("displayHtml: " + displayHtml.toString(),
539:                        module);
540:
541:                return displayHtml.toString();
542:            }
543:
544:            /**
545:             * Produces an HTML string to display the drop down on a web page in read-only mode.  The name is probably
546:             * a misnomer since the drop list is not actually produced.  Instead the display value for the selected item is displayed.
547:             * This avoids retrieving the list from the data base when the user won't be allowed to select from it anyway.
548:             *
549:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
550:             *
551:             * @param fieldValue Value stored or to be stored in the data base. Used as the primary key to look up the value to be displayed.
552:             * @param htmlName The name to be used for the current field in the HTML
553:             * @param attributeName Name of the attribute being displayed
554:             * @param uiDisplayObject Reference to a display object defined in the data base and attached to the field to be displayed by the UI builder
555:             * @param selectPair Array containing a pair of values.  selectPair[0] contains the data selectPair[1] contains the display value.
556:             * @param anchorHref String to be inserted as the HREF clause of an < A > tag
557:             * @param anchorTarget String to be inserted as the TARGET clause of an < A > tag
558:             * @param delegator Reference to the OFBIZ delegator being used to connect to the data base
559:             *
560:             * @return String containing the HTML text that will draw the < SELECT > on the web page
561:             */
562:            public static String getSelectHtmlReadOnly(String fieldValue,
563:                    String htmlName, String attributeName,
564:                    UIDisplayObject uiDisplayObject, String[] selectPair,
565:                    String anchorHref, String anchorTarget,
566:                    GenericDelegator delegator) {
567:                StringBuffer displayHtml = new StringBuffer();
568:
569:                Debug
570:                        .logVerbose(
571:                                "Starting to display the looked up value in place of a drop down in read only mode.",
572:                                module);
573:
574:                if (fieldValue.trim().equals("")) {
575:                    Debug.logVerbose("Field value is empty.", module);
576:
577:                    // Field value is empty. Just display an empty string, and create a hidden field.
578:                    displayHtml.append("<INPUT TYPE=\"HIDDEN\" NAME=\""
579:                            + htmlName + "\" VALUE='" + fieldValue + "'>\n");
580:
581:                    return displayHtml.toString();
582:                } else {
583:                    Debug
584:                            .logVerbose(
585:                                    "Field value has contents. About to create the findByAnd field map.",
586:                                    module);
587:
588:                    String optionValue = selectPair[0];
589:                    String optionDisplay = selectPair[1];
590:
591:                    // Create a hidden field AND show the decoded value as text in the table cell.
592:                    Debug.logVerbose("optionValue             -> "
593:                            + optionValue, module);
594:                    Debug.logVerbose("optionDisplay           -> "
595:                            + optionDisplay, module);
596:
597:                    displayHtml.append(UIWebUtility.displayFieldReadOnly(
598:                            uiDisplayObject, htmlName, fieldValue,
599:                            optionDisplay, anchorHref, anchorTarget));
600:
601:                    return displayHtml.toString();
602:                }
603:            }
604:
605:            /**
606:             * Converts a vector of generic values into a vector of data value/display value
607:             * pairs for a < SELECT >
608:             *
609:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
610:             *
611:             * @param attribEntityValueDef Defines how to decode the data value from a generic value
612:             * @param attribEntityDisplayDef Defines how to decode the display value from a generic value
613:             * @param currentAttributeName Name of the attribute on which the < SELECT > is being used (this is used to decode the #currentField tag in the decode definition)
614:             * @param genericValueVectorList List of vectors of generic values from which the values can be decoded.  Note: This must contain instances of the generic value of the linked entity listed in the drop down.
615:             *
616:             * @return Array of value/display pairs
617:             */
618:            public static String[][] decodeValueArray(
619:                    String attribEntityValueDef, String attribEntityDisplayDef,
620:                    String currentAttributeName, List genericValueVectorList) {
621:                if (genericValueVectorList == null) {
622:                    return null;
623:                }
624:
625:                // Create a 2-dimensional array to hold the value/display pairs.
626:                String[][] selectPairArray = new String[genericValueVectorList
627:                        .size()][2];
628:
629:                // Loop through the retrieved values and create value/display pairs
630:                Vector genericValueVector = null;
631:                int itemCount = 0;
632:                Iterator genericValueVectorListI = genericValueVectorList
633:                        .iterator();
634:
635:                while (genericValueVectorListI.hasNext()) {
636:                    // Get one row from the List.
637:                    Object object = genericValueVectorListI.next();
638:
639:                    // Get the values for the row and add them to the array.
640:                    selectPairArray[itemCount] = decodeValue(
641:                            attribEntityValueDef, attribEntityDisplayDef,
642:                            currentAttributeName, object);
643:
644:                    itemCount++;
645:                }
646:
647:                return selectPairArray;
648:            }
649:
650:            /**
651:             * Converts a generic value into a data value/display value pair for a < SELECT >
652:             *
653:             * @author  <a href='mailto:jnutting@sourcetap.com'>John Nutting</a>
654:             *
655:             * @param attribEntityValueDef Defines how to decode the data value from a generic value
656:             * @param attribEntityDisplayDef Defines how to decode the display value from a generic value
657:             * @param currentAttributeName Name of the attribute on which the < SELECT > is being used (this is used to decode the #currentField tag in the decode definition)
658:             * @param genericValueObject Generic value or vector of generic values from which the values can be decoded. Note: This must be or contain the generic value of the linked entity listed in the drop down.
659:             *
660:             * @return Array of value/display pairs
661:             */
662:            public static String[] decodeValue(String attribEntityValueDef,
663:                    String attribEntityDisplayDef, String currentAttributeName,
664:                    Object valueObject) {
665:                // Create a 1-dimensional array to hold the value/display pairs.
666:                String[] selectPair = new String[2];
667:                selectPair[0] = "";
668:                selectPair[1] = "";
669:
670:                if (valueObject == null) {
671:                    return selectPair;
672:                }
673:
674:                Vector genericValueVector = null;
675:
676:                if (valueObject.getClass().toString().indexOf("Vector") > 0) {
677:                    // The row has a vector of generic values in it already. Just use that vector.
678:                    genericValueVector = (Vector) valueObject;
679:
680:                    Debug.logVerbose(
681:                            "Generic value vector straight from object: "
682:                                    + genericValueVector.toString(), module);
683:                } else if (valueObject.getClass().toString().indexOf(
684:                        "GenericValue") > 0) {
685:                    // Object is a generic value. Add it to a new vector.
686:                    GenericValue genericValue = (GenericValue) valueObject;
687:                    genericValueVector = new Vector();
688:                    genericValueVector.add(genericValue);
689:
690:                    Debug.logVerbose(
691:                            "Generic value vector created from generic value: "
692:                                    + genericValueVector.toString(), module);
693:                } else {
694:                    Debug.logError(
695:                            "Object class must be vector or generic value, but is "
696:                                    + valueObject.getClass(), module);
697:
698:                    return selectPair;
699:                }
700:
701:                // Get the data value for the row
702:                selectPair[0] = UIUtility.decodeEntityDisplayDef(
703:                        attribEntityValueDef, genericValueVector,
704:                        currentAttributeName);
705:
706:                // Get the visible value for the row
707:                selectPair[1] = UIUtility.decodeEntityDisplayDef(
708:                        attribEntityDisplayDef, genericValueVector,
709:                        currentAttributeName);
710:
711:                return selectPair;
712:            }
713:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.