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.extensions.model; 018 019import org.apache.wicket.model.IModel; 020 021/** 022 * Model adapter that makes working with models for checkboxes easier. 023 * 024 * @author Igor Vaynberg (ivaynberg) 025 * 026 */ 027public abstract class AbstractCheckBoxModel implements IModel<Boolean> 028{ 029 private static final long serialVersionUID = 1L; 030 031 /** 032 * @return true to indicate the checkbox should be selected, false otherwise 033 */ 034 public abstract boolean isSelected(); 035 036 /** 037 * Called when checkbox has been selected 038 * 039 */ 040 public abstract void select(); 041 042 /** 043 * Called when checkbox is unselected 044 * 045 */ 046 public abstract void unselect(); 047 048 /** 049 * 050 * @see org.apache.wicket.model.IModel#getObject() 051 */ 052 @Override 053 public final Boolean getObject() 054 { 055 return isSelected(); 056 } 057 058 /** 059 * @see org.apache.wicket.model.IModel#setObject(Object) 060 */ 061 @Override 062 public final void setObject(final Boolean object) 063 { 064 if (Boolean.TRUE.equals(object)) 065 { 066 select(); 067 } 068 else 069 { 070 unselect(); 071 } 072 } 073}