KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > customizers > common > BeanListMapping


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * ListMapping.java
21  *
22  * Created on January 9, 2004, 3:05 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common;
26
27 import java.util.List JavaDoc;
28 import java.util.ResourceBundle JavaDoc;
29 import java.text.MessageFormat JavaDoc;
30
31 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
32
33
34 /** Class that associates a list of properties owned by a CommonDDBean with a calculated
35  * string for display in a combobox or table.
36  *
37  * It is expected that the underlying bean and list referenced may be changed
38  * during this object's lifetime, and between calls to toString().
39  *
40  * @author Peter Williams
41  * @version %I%, %G%
42  */

43 public class BeanListMapping {
44     
45     // Standard resource bundle to use for non-property list fields
46
private static final ResourceBundle JavaDoc bundle = ResourceBundle.getBundle(
47         "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); // NOI18N
48

49     private static final String JavaDoc formatPattern = bundle.getString("LBL_SizeOfListText"); // NOI18N
50

51     private CommonDDBean theBean;
52     private String JavaDoc listPropertyName;
53     private String JavaDoc displayText;
54     private int listSize;
55
56     public BeanListMapping(CommonDDBean bean, String JavaDoc propertyName) {
57         theBean = bean;
58         listPropertyName = propertyName;
59         displayText = null;
60         listSize = 0;
61     }
62
63     public String JavaDoc toString() {
64         if(textOutOfDate()) {
65             buildDisplayText();
66         }
67         
68         return displayText;
69     }
70     
71     private void buildDisplayText() {
72         listSize = (theBean != null) ? theBean.size(listPropertyName) : 0;
73         Object JavaDoc [] args = { new Integer JavaDoc(listSize) };
74         displayText = MessageFormat.format(formatPattern, args);
75     }
76     
77     private boolean textOutOfDate() {
78         // Rebuild display Text if text is null or if size of list has changed.
79
if(displayText == null) {
80             return true;
81         }
82         
83         int newListSize = 0;
84         if(theBean != null) {
85             newListSize = theBean.size(listPropertyName);
86         }
87         
88         if(listSize != newListSize) {
89             return true;
90         }
91         
92         return false;
93     }
94     
95     public CommonDDBean getBean() {
96         return theBean;
97     }
98     
99     public String JavaDoc getListPropertyName() {
100         return listPropertyName;
101     }
102 }
103
Popular Tags