Source Code Cross Referenced for ListMultipleChoice.java in  » J2EE » wicket » wicket » markup » html » form » 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 » wicket » wicket.markup.html.form 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: ListMultipleChoice.java 462434 2006-10-03 22:41:33Z ivaynberg $
003:         * $Revision: 462434 $ $Date: 2006-10-04 00:41:33 +0200 (Wed, 04 Oct 2006) $
004:         * 
005:         * ==============================================================================
006:         * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007:         * use this file except in compliance with the License. You may obtain a copy of
008:         * the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014:         * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015:         * License for the specific language governing permissions and limitations under
016:         * the License.
017:         */
018:        package wicket.markup.html.form;
019:
020:        import java.util.ArrayList;
021:        import java.util.Collection;
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.StringTokenizer;
025:
026:        import wicket.markup.ComponentTag;
027:        import wicket.model.IModel;
028:        import wicket.util.convert.ConversionException;
029:        import wicket.util.string.AppendingStringBuffer;
030:        import wicket.util.string.Strings;
031:
032:        /**
033:         * A multiple choice list component.
034:         * 
035:         * @author Jonathan Locke
036:         * @author Johan Compagner
037:         * @author Martijn Dashorst
038:         */
039:        public class ListMultipleChoice extends AbstractChoice {
040:            private static final long serialVersionUID = 1L;
041:
042:            /** The default maximum number of rows to display. */
043:            private static int defaultMaxRows = 8;
044:
045:            /** The maximum number of rows to display. */
046:            private int maxRows = defaultMaxRows;
047:
048:            /**
049:             * Gets the default maximum number of rows to display.
050:             * 
051:             * @return Returns the defaultMaxRows.
052:             */
053:            protected static int getDefaultMaxRows() {
054:                return defaultMaxRows;
055:            }
056:
057:            /**
058:             * Sets the default maximum number of rows to display.
059:             * 
060:             * @param defaultMaxRows
061:             *            The defaultMaxRows to set.
062:             */
063:            protected static void setDefaultMaxRows(final int defaultMaxRows) {
064:                ListMultipleChoice.defaultMaxRows = defaultMaxRows;
065:            }
066:
067:            /**
068:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String)
069:             */
070:            public ListMultipleChoice(final String id) {
071:                super (id);
072:            }
073:
074:            /**
075:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String, List)
076:             */
077:            public ListMultipleChoice(final String id, final List choices) {
078:                super (id, choices);
079:            }
080:
081:            /**
082:             * Creates a multiple choice list with a maximum number of visible rows.
083:             * 
084:             * @param id
085:             *            component id
086:             * @param choices
087:             *            list of choices
088:             * @param maxRows
089:             *            the maximum number of visible rows.
090:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String, List)
091:             */
092:            public ListMultipleChoice(final String id, final List choices,
093:                    final int maxRows) {
094:                super (id, choices);
095:                this .maxRows = maxRows;
096:            }
097:
098:            /**
099:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
100:             *      List,IChoiceRenderer)
101:             */
102:            public ListMultipleChoice(final String id, final List choices,
103:                    final IChoiceRenderer renderer) {
104:                super (id, choices, renderer);
105:            }
106:
107:            /**
108:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
109:             *      IModel, List)
110:             */
111:            public ListMultipleChoice(final String id, IModel object,
112:                    final List choices) {
113:                super (id, object, choices);
114:            }
115:
116:            /**
117:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
118:             *      IModel, List,IChoiceRenderer)
119:             */
120:            public ListMultipleChoice(final String id, IModel object,
121:                    final List choices, final IChoiceRenderer renderer) {
122:                super (id, object, choices, renderer);
123:            }
124:
125:            /**
126:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
127:             *      IModel)
128:             */
129:            public ListMultipleChoice(String id, IModel choices) {
130:                super (id, choices);
131:            }
132:
133:            /**
134:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
135:             *      IModel,IModel)
136:             */
137:            public ListMultipleChoice(String id, IModel model, IModel choices) {
138:                super (id, model, choices);
139:            }
140:
141:            /**
142:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
143:             *      IModel,IChoiceRenderer)
144:             */
145:            public ListMultipleChoice(String id, IModel choices,
146:                    IChoiceRenderer renderer) {
147:                super (id, choices, renderer);
148:            }
149:
150:            /**
151:             * @see wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
152:             *      IModel, IModel,IChoiceRenderer)
153:             */
154:            public ListMultipleChoice(String id, IModel model, IModel choices,
155:                    IChoiceRenderer renderer) {
156:                super (id, model, choices, renderer);
157:            }
158:
159:            /**
160:             * Sets the number of visible rows in the listbox.
161:             * 
162:             * @param maxRows
163:             *            the number of visible rows
164:             * @return this
165:             */
166:            public final ListMultipleChoice setMaxRows(final int maxRows) {
167:                this .maxRows = maxRows;
168:                return this ;
169:            }
170:
171:            /**
172:             * @see FormComponent#getModelValue()
173:             */
174:            public final String getModelValue() {
175:                // Get the list of selected values
176:                final Collection selectedValues = (Collection) getModelObject();
177:                final AppendingStringBuffer buffer = new AppendingStringBuffer();
178:                if (selectedValues != null) {
179:                    final List choices = getChoices();
180:                    for (final Iterator iterator = selectedValues.iterator(); iterator
181:                            .hasNext();) {
182:                        final Object object = iterator.next();
183:
184:                        int index = choices.indexOf(object);
185:                        buffer.append(getChoiceRenderer().getIdValue(object,
186:                                index));
187:                        buffer.append(VALUE_SEPARATOR);
188:                    }
189:                }
190:                return buffer.toString();
191:            }
192:
193:            /**
194:             * @see wicket.markup.html.form.AbstractChoice#isSelected(Object,int,
195:             *      String)
196:             */
197:            protected final boolean isSelected(Object choice, int index,
198:                    String selected) {
199:                // Have a value at all?
200:                if (selected != null) {
201:                    // Loop through ids
202:                    for (final StringTokenizer tokenizer = new StringTokenizer(
203:                            selected, VALUE_SEPARATOR); tokenizer
204:                            .hasMoreTokens();) {
205:                        final String id = tokenizer.nextToken();
206:                        if (id.equals(getChoiceRenderer().getIdValue(choice,
207:                                index))) {
208:                            return true;
209:                        }
210:                    }
211:                }
212:                return false;
213:            }
214:
215:            /**
216:             * @see wicket.Component#onComponentTag(ComponentTag)
217:             */
218:            protected final void onComponentTag(final ComponentTag tag) {
219:                super .onComponentTag(tag);
220:                tag.put("multiple", "multiple");
221:
222:                if (!tag.getAttributes().containsKey("size")) {
223:                    tag.put("size", Math.min(maxRows, getChoices().size()));
224:                }
225:            }
226:
227:            /**
228:             * @see wicket.markup.html.form.FormComponent#convertValue(String[])
229:             */
230:            protected Object convertValue(String[] ids)
231:                    throws ConversionException {
232:                ArrayList selectedValues = new ArrayList();
233:
234:                // If one or more ids is selected
235:                if (ids != null && ids.length > 0 && !Strings.isEmpty(ids[0])) {
236:                    // Get values that could be selected
237:                    final List choices = getChoices();
238:
239:                    // Loop through selected indices
240:                    for (int i = 0; i < ids.length; i++) {
241:                        for (int index = 0; index < choices.size(); index++) {
242:                            // Get next choice
243:                            final Object choice = choices.get(index);
244:                            if (getChoiceRenderer().getIdValue(choice, index)
245:                                    .equals(ids[i])) {
246:                                selectedValues.add(choice);
247:                                break;
248:                            }
249:                        }
250:                    }
251:                }
252:                return selectedValues;
253:            }
254:
255:            /**
256:             * @see FormComponent#updateModel()
257:             */
258:            public void updateModel() {
259:                Collection selectedValues = (Collection) getModelObject();
260:                if (selectedValues != null) {
261:                    modelChanging();
262:                    selectedValues.clear();
263:                    selectedValues.addAll((Collection) getConvertedInput());
264:                    modelChanged();
265:                } else {
266:                    selectedValues = (Collection) getConvertedInput();
267:                    setModelObject(selectedValues);
268:                }
269:            }
270:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.