Source Code Cross Referenced for NameValueListModel.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » util » list » 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 » Content Management System » contelligent » de.finix.contelligent.client.util.list 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2006 C:1 Financial Services GmbH
003:         *
004:         * This software is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License Version 2.1, as published by the Free Software Foundation.
007:         *
008:         * This software is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011:         * Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public
014:         * License along with this library; if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016:         */
017:
018:        package de.finix.contelligent.client.util.list;
019:
020:        import java.util.ArrayList;
021:        import java.util.Collections;
022:        import java.util.Comparator;
023:        import java.util.Iterator;
024:        import java.util.List;
025:
026:        import javax.swing.AbstractListModel;
027:        import javax.swing.MutableComboBoxModel;
028:
029:        import de.finix.contelligent.client.i18n.Resources;
030:
031:        public class NameValueListModel extends AbstractListModel implements 
032:                MutableComboBoxModel {
033:
034:            public final static boolean SORT_DESCENDING = true;
035:
036:            public final static boolean SORT_ASCENDING = false;
037:
038:            private List<NameValuePair> nameValuePairs;
039:
040:            private NameValuePair selectedNameValuePair = null;
041:
042:            // helper
043:            final public static NameValueListModel buildEmptyNameValuePairs() {
044:                return new NameValueListModel();
045:            }
046:
047:            // helper
048:            final public static NameValueListModel buildNameValuePairs(
049:                    Object[] value, Object names[]) {
050:                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
051:                        value.length);
052:                for (int i = 0; i < value.length; i++) {
053:                    nameValuePairs.add(new NameValuePair(names[i], value[i]));
054:                }
055:                return new NameValueListModel(nameValuePairs);
056:            }
057:
058:            // helper
059:            final public static NameValueListModel buildNameValuePairs(
060:                    String[] valuesAsNames) {
061:                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
062:                        valuesAsNames.length);
063:                for (int i = 0; i < valuesAsNames.length; i++) {
064:                    nameValuePairs.add(new NameValuePair(valuesAsNames[i],
065:                            valuesAsNames[i]));
066:                }
067:                return new NameValueListModel(nameValuePairs);
068:            }
069:
070:            // helper
071:            final public static NameValueListModel buildNameValuePairs(
072:                    List valuesAsNames) {
073:                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
074:                        valuesAsNames.size());
075:                for (Iterator it = valuesAsNames.iterator(); it.hasNext();) {
076:                    String valueAsName = (String) it.next();
077:                    nameValuePairs.add(new NameValuePair(valueAsName,
078:                            valueAsName));
079:                }
080:                return new NameValueListModel(nameValuePairs);
081:            }
082:
083:            // helper
084:            final public static NameValueListModel buildLocaleNameValuePairs(
085:                    Object[] keys) {
086:                ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
087:                        keys.length);
088:                for (int i = 0; i < keys.length; i++) {
089:                    String key = (String) keys[i];
090:                    nameValuePairs.add(new NameValuePair(Resources
091:                            .getLocalString(key), key));
092:                }
093:                return new NameValueListModel(nameValuePairs);
094:            }
095:
096:            public NameValueListModel() {
097:                this (new ArrayList<NameValuePair>());
098:            }
099:
100:            public NameValueListModel(NameValueListModel model) {
101:                this (model.getData());
102:            }
103:
104:            public NameValueListModel(List<NameValuePair> nameValuePairs) {
105:                super ();
106:                this .nameValuePairs = nameValuePairs;
107:            }
108:
109:            public NameValueListModel(List<NameValuePair> nameValuePairs,
110:                    final boolean sortDescending) {
111:                super ();
112:                this .nameValuePairs = nameValuePairs;
113:                sort(sortDescending);
114:            }
115:
116:            public List<NameValuePair> getData() {
117:                return nameValuePairs;
118:            }
119:
120:            public NameValueListModel sort(final boolean sortDescending) {
121:                if (nameValuePairs != null
122:                        && ((NameValuePair) nameValuePairs.get(0)).name instanceof  String) {
123:                    Collections.sort(nameValuePairs,
124:                            new Comparator<NameValuePair>() {
125:                                public int compare(NameValuePair n1,
126:                                        NameValuePair n2) {
127:                                    String s1 = (String) n1.name;
128:                                    String s2 = (String) n2.name;
129:                                    return (sortDescending ? s1
130:                                            .compareToIgnoreCase(s2) : s2
131:                                            .compareToIgnoreCase(s1));
132:                                }
133:
134:                                public boolean equals(Object obj) {
135:                                    return super .equals(obj);
136:                                }
137:                            });
138:                }
139:                return this ;
140:            }
141:
142:            public NameValuePair getEntryByValue(Object value) {
143:                for (Iterator it = nameValuePairs.iterator(); it.hasNext();) {
144:                    NameValuePair nameValuePair = (NameValuePair) it.next();
145:                    if (value.equals(nameValuePair.value))
146:                        return nameValuePair;
147:                }
148:                return null;
149:            }
150:
151:            public NameValuePair getEntryByName(String name) {
152:                for (Iterator it = nameValuePairs.iterator(); it.hasNext();) {
153:                    NameValuePair nameValuePair = (NameValuePair) it.next();
154:                    if (name.equals(nameValuePair.name))
155:                        return nameValuePair;
156:                }
157:                return null;
158:            }
159:
160:            public final static class NameValuePair {
161:                public Object name;
162:
163:                public Object value;
164:
165:                public NameValuePair(Object name, Object value) {
166:                    this .name = name;
167:                    this .value = value;
168:                }
169:
170:                // used for selection
171:                public boolean equals(Object o) {
172:                    return (o != null && o instanceof  NameValuePair && value
173:                            .equals(((NameValuePair) o).value));
174:                }
175:
176:                public int hashCode() {
177:                    return value.hashCode();
178:                }
179:            }
180:
181:            // for AbstractListModel
182:
183:            public int getSize() {
184:                return nameValuePairs.size();
185:            }
186:
187:            public Object getElementAt(int i) {
188:                return nameValuePairs.get(i);
189:            }
190:
191:            // for ComboBoxModel
192:
193:            public Object getSelectedItem() {
194:                return selectedNameValuePair;
195:            }
196:
197:            public void setSelectedItem(Object nameValuePair) {
198:                selectedNameValuePair = (NameValuePair) nameValuePair;
199:                fireContentsChanged(this , -1, -1);
200:            }
201:
202:            // for MutableComboBoxModel
203:
204:            public void addElement(Object nameValuePair) {
205:                if (nameValuePair == null)
206:                    return;
207:                nameValuePairs.add((NameValuePair) nameValuePair);
208:                fireIntervalAdded(this , nameValuePairs.size() - 1,
209:                        nameValuePairs.size() - 1);
210:            }
211:
212:            public void insertElementAt(Object nameValuePair, int index) {
213:                if (nameValuePair == null)
214:                    return;
215:                nameValuePairs.add(index, (NameValuePair) nameValuePair);
216:                fireIntervalAdded(this , index, index);
217:            }
218:
219:            public void removeElement(Object nameValuePair) {
220:                if (nameValuePair == null)
221:                    return;
222:                removeElement(nameValuePair, nameValuePairs
223:                        .indexOf(nameValuePair));
224:            }
225:
226:            public void removeElementAt(int index) {
227:                removeElement(nameValuePairs.get(index), index);
228:            }
229:
230:            private void removeElement(Object nameValuePair, int index) {
231:                if (nameValuePair == null)
232:                    return;
233:                if (index < 0)
234:                    return;
235:                nameValuePairs.remove(index);
236:                if (selectedNameValuePair != null
237:                        && selectedNameValuePair.equals(nameValuePair)) {
238:                    selectedNameValuePair = null;
239:                }
240:                fireIntervalRemoved(this, index, index);
241:            }
242:
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.