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 */
017package org.apache.wicket.markup.html.form;
018
019/**
020 * A Javascript-based "Select All" checkbox component that works with {@link CheckBoxMultipleChoice}
021 * . By default, clicking on any of the controlled checkboxes automatically updates the state of the
022 * "select all" checkbox. Override {@link AbstractCheckSelector#wantAutomaticUpdate()} to change
023 * this.
024 * 
025 * @author Carl-Eric Menzel
026 */
027public class CheckboxMultipleChoiceSelector extends AbstractCheckSelector
028{
029        private static final long serialVersionUID = 1L;
030
031        private final CheckBoxMultipleChoice<?> choiceComponent;
032
033        /**
034         * @param id
035         *            The component ID
036         * @param choiceComponent
037         *            The checkbox choice component this Selector will manage.
038         */
039        public CheckboxMultipleChoiceSelector(String id, CheckBoxMultipleChoice<?> choiceComponent)
040        {
041                super(id);
042
043                this.choiceComponent = choiceComponent;
044                choiceComponent.setOutputMarkupId(true);
045        }
046
047        @Override
048        protected CharSequence getFindCheckboxesFunction()
049        {
050                return String.format("Wicket.CheckboxSelector.findCheckboxesFunction('%s', '%s')",
051                        choiceComponent.getMarkupId(), choiceComponent.getInputName());
052        }
053}