001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.wicket.markup.html.form;
018:
019: import java.util.List;
020:
021: import org.apache.wicket.markup.ComponentTag;
022: import org.apache.wicket.model.IModel;
023:
024: /**
025: * Essentially a drop down choice that doesn't drop down. Instead, it scrolls
026: * and displays a given number of rows.
027: *
028: * @author Jonathan Locke
029: * @author Johan Compagner
030: * @author Eelco Hillenius
031: */
032: public class ListChoice extends DropDownChoice {
033: private static final long serialVersionUID = 1L;
034:
035: /** The default maximum number of rows to display. */
036: private static int defaultMaxRows = 8;
037:
038: /** The maximum number of rows to display. */
039: private int maxRows;
040:
041: /**
042: * Gets the default maximum number of rows to display.
043: *
044: * @return Returns the defaultMaxRows.
045: */
046: protected static int getDefaultMaxRows() {
047: return defaultMaxRows;
048: }
049:
050: /**
051: * Sets the default maximum number of rows to display.
052: *
053: * @param defaultMaxRows
054: * The defaultMaxRows to set.
055: */
056: protected static void setDefaultMaxRows(final int defaultMaxRows) {
057: ListChoice.defaultMaxRows = defaultMaxRows;
058: }
059:
060: /**
061: * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String)
062: */
063: public ListChoice(final String id) {
064: this (id, null, (List) null, null, defaultMaxRows);
065: }
066:
067: /**
068: * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
069: * List)
070: */
071: public ListChoice(final String id, final List choices) {
072: this (id, null, choices, null, defaultMaxRows);
073: }
074:
075: /**
076: * @param id
077: * See Component
078: * @param choices
079: * The collection of values in the list
080: * @param renderer
081: * See AbstractChoice
082: * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
083: * List,IChoiceRenderer)
084: */
085: public ListChoice(final String id, final List choices,
086: final IChoiceRenderer renderer) {
087: this (id, null, choices, renderer, defaultMaxRows);
088: }
089:
090: /**
091: * @param id
092: * See Component
093: * @param model
094: * See Component
095: * @param choices
096: * The collection of values in the list
097: * @see DropDownChoice#DropDownChoice(String, IModel, List)
098: */
099: public ListChoice(final String id, final IModel model,
100: final List choices) {
101: this (id, model, choices, null, defaultMaxRows);
102: }
103:
104: /**
105: * @param id
106: * See Component
107: * @param model
108: * See Component
109: * @param choices
110: * The collection of values in the list
111: * @param maxRows
112: * Maximum number of rows to show
113: * @see DropDownChoice#DropDownChoice(String, IModel, List)
114: */
115: public ListChoice(final String id, final IModel model,
116: final List choices, final int maxRows) {
117: this (id, model, choices, null, maxRows);
118: }
119:
120: /**
121: * @param id
122: * See Component
123: * @param model
124: * See Component
125: * @param choices
126: * The collection of values in the list
127: * @param renderer
128: * See AbstractChoice
129: * @see DropDownChoice#DropDownChoice(String, IModel, List)
130: */
131: public ListChoice(final String id, final IModel model,
132: final List choices, final IChoiceRenderer renderer) {
133: this (id, model, choices, renderer, defaultMaxRows);
134: }
135:
136: /**
137: * @param id
138: * See Component
139: * @param model
140: * See Component
141: * @param choices
142: * The collection of values in the list
143: * @param renderer
144: * See AbstractChoice
145: * @param maxRows
146: * Maximum number of rows to show
147: * @see DropDownChoice#DropDownChoice(String, IModel, List)
148: */
149: public ListChoice(final String id, final IModel model,
150: final List choices, final IChoiceRenderer renderer,
151: final int maxRows) {
152: super (id, model, choices, renderer);
153: this .maxRows = maxRows;
154: }
155:
156: /**
157: * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
158: * IModel)
159: */
160: public ListChoice(String id, IModel choices) {
161: this (id, null, choices, null, defaultMaxRows);
162: }
163:
164: /**
165: * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
166: * IModel,IModel)
167: */
168: public ListChoice(String id, IModel model, IModel choices) {
169: this (id, model, choices, null, defaultMaxRows);
170: }
171:
172: /**
173: * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
174: * IModel,IChoiceRenderer)
175: */
176: public ListChoice(String id, IModel choices,
177: IChoiceRenderer renderer) {
178: this (id, null, choices, renderer, defaultMaxRows);
179: }
180:
181: /**
182: * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
183: * IModel, IModel,IChoiceRenderer)
184: */
185: public ListChoice(String id, IModel model, IModel choices,
186: IChoiceRenderer renderer) {
187: this (id, model, choices, renderer, defaultMaxRows);
188: }
189:
190: /**
191: * @see org.apache.wicket.markup.html.form.AbstractChoice#AbstractChoice(String,
192: * IModel, IModel,IChoiceRenderer)
193: */
194: public ListChoice(String id, IModel model, IModel choices,
195: IChoiceRenderer renderer, int maxRows) {
196: super (id, model, choices, renderer);
197: this .maxRows = maxRows;
198: }
199:
200: /**
201: * Gets the maximum number of rows to display.
202: *
203: * @return the maximum number of rows to display
204: */
205: public final int getMaxRows() {
206: return maxRows;
207: }
208:
209: /**
210: * Sets the maximum number of rows to display.
211: *
212: * @param maxRows
213: * the maximum number of rows to display
214: * @return This
215: */
216: public final ListChoice setMaxRows(int maxRows) {
217: this .maxRows = maxRows;
218: return this ;
219: }
220:
221: /**
222: * @see org.apache.wicket.Component#onComponentTag(ComponentTag)
223: */
224: protected final void onComponentTag(final ComponentTag tag) {
225: super .onComponentTag(tag);
226: if (!tag.getAttributes().containsKey("size")) {
227: tag.put("size", maxRows);
228: }
229: }
230:
231: /**
232: * @see org.apache.wicket.markup.html.form.FormComponent#supportsPersistence()
233: */
234: protected final boolean supportsPersistence() {
235: return true;
236: }
237: }
|