01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.extensions.model;
18:
19: import org.apache.wicket.Component;
20: import org.apache.wicket.model.IModel;
21:
22: /**
23: * Model adapter that makes working with models for checkboxes easier.
24: *
25: * @author Igor Vaynberg (ivaynberg)
26: *
27: */
28: public abstract class AbstractCheckBoxModel implements IModel {
29: private static final long serialVersionUID = 1L;
30:
31: /**
32: * Detach model.
33: */
34: public void detach() {
35: }
36:
37: /**
38: * @return true to indicate the checkbox should be selected, false otherwise
39: */
40: public abstract boolean isSelected();
41:
42: /**
43: * Called when checkbox has been selected
44: *
45: */
46: public abstract void select();
47:
48: /**
49: * Called when checkbox is unselected
50: *
51: */
52: public abstract void unselect();
53:
54: /**
55: *
56: * @see org.apache.wicket.model.IModel#getObject()
57: */
58: public final Object getObject() {
59: return Boolean.valueOf(isSelected());
60: }
61:
62: /**
63: * @see org.apache.wicket.model.IModel#setObject(java.lang.Object)
64: */
65: public final void setObject(Object object) {
66: if (Boolean.TRUE.equals(object)) {
67: select();
68: } else {
69: unselect();
70: }
71: }
72:
73: // TODO Remove methods after deprecation release is done
74:
75: /** @deprecated replaced by {@link #getObject()} */
76: public final Object getObject(Component component) {
77: throw new UnsupportedOperationException();
78: }
79:
80: /** @deprecated replaced by {@link #isSelected()} */
81: public final boolean isSelected(Component component) {
82: throw new UnsupportedOperationException();
83: }
84:
85: /** @deprecated replaced by {@link #setObject(Object)} */
86: public final void setObject(Component component, Object object) {
87: throw new UnsupportedOperationException();
88: }
89:
90: /** @deprecated replaced by {@link #select()} */
91: public final void setSelected(Component component, boolean sel) {
92: throw new UnsupportedOperationException();
93: }
94: }
|