diff options
author | Henri Sara <hesara@vaadin.com> | 2016-08-09 15:11:02 +0300 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2016-08-11 15:45:59 +0300 |
commit | 5c852b41ff22409e9f69d634f2de5df69b7815c0 (patch) | |
tree | 3359f91fe33d3d7cecfb35a9cf29e6d92b663188 /server/src/main/java/com/vaadin/ui/CheckBox.java | |
parent | c726ae1b276049282286db3b0934e90ac8d8a2ce (diff) | |
download | vaadin-framework-5c852b41ff22409e9f69d634f2de5df69b7815c0.tar.gz vaadin-framework-5c852b41ff22409e9f69d634f2de5df69b7815c0.zip |
Convert CheckBox from legacy to AbstractField
Add LegacyCheckBox for old field factories, Grid editor etc.
Change-Id: Ic40790049421268c6de3d26730d1955d56aa86c4
Diffstat (limited to 'server/src/main/java/com/vaadin/ui/CheckBox.java')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/CheckBox.java | 134 |
1 files changed, 36 insertions, 98 deletions
diff --git a/server/src/main/java/com/vaadin/ui/CheckBox.java b/server/src/main/java/com/vaadin/ui/CheckBox.java index e9e9b0d4b9..1519c64955 100644 --- a/server/src/main/java/com/vaadin/ui/CheckBox.java +++ b/server/src/main/java/com/vaadin/ui/CheckBox.java @@ -1,12 +1,12 @@ /* * Copyright 2000-2014 Vaadin Ltd. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the @@ -21,20 +21,18 @@ import java.util.Collection; import org.jsoup.nodes.Attributes; import org.jsoup.nodes.Element; -import com.vaadin.data.Property; import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl; import com.vaadin.event.FieldEvents.FocusEvent; import com.vaadin.event.FieldEvents.FocusListener; -import com.vaadin.legacy.ui.LegacyAbstractField; import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc; import com.vaadin.shared.ui.checkbox.CheckBoxState; import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; -public class CheckBox extends LegacyAbstractField<Boolean> { +public class CheckBox extends AbstractField<Boolean> { private CheckBoxServerRpc rpc = new CheckBoxServerRpc() { @@ -50,7 +48,7 @@ public class CheckBox extends LegacyAbstractField<Boolean> { * to make sure the cached state is updated to match the client. If * we do not do this, a reverting setValue() call in a listener will * not cause the new state to be sent to the client. - * + * * See #11028, #10030. */ getUI().getConnectorTracker().getDiffState(CheckBox.this) @@ -85,7 +83,7 @@ public class CheckBox extends LegacyAbstractField<Boolean> { /** * Creates a new checkbox with a set caption. - * + * * @param caption * the Checkbox caption. */ @@ -96,7 +94,7 @@ public class CheckBox extends LegacyAbstractField<Boolean> { /** * Creates a new checkbox with a caption and a set initial state. - * + * * @param caption * the caption of the checkbox * @param initialState @@ -107,21 +105,27 @@ public class CheckBox extends LegacyAbstractField<Boolean> { setValue(initialState); } - /** - * Creates a new checkbox that is connected to a boolean property. - * - * @param state - * the Initial state of the switch-button. - * @param dataSource - */ - public CheckBox(String caption, Property<?> dataSource) { - this(caption); - setPropertyDataSource(dataSource); + @Override + public Boolean getValue() { + return getState(false).checked; } + /** + * Sets the value of this ComboBox. If the new value is not equal to + * {@code getValue()}, fires a value change event. Throws + * {@code IllegalArgumentException} if the value is null. + * + * @param value + * the new value + * @throws IllegalArgumentException + * if the value is null + */ @Override - public Class<Boolean> getType() { - return Boolean.class; + public void setValue(Boolean value) { + if (value == null) { + throw new IllegalArgumentException("CheckBox value must not be null"); + } + super.setValue(value); } @Override @@ -129,20 +133,14 @@ public class CheckBox extends LegacyAbstractField<Boolean> { return (CheckBoxState) super.getState(); } - /* - * Overridden to keep the shared state in sync with the LegacyAbstractField - * internal value. Should be removed once LegacyAbstractField is refactored to use - * shared state. - * - * See tickets #10921 and #11064. - */ @Override - protected void setInternalValue(Boolean newValue) { - super.setInternalValue(newValue); - if (newValue == null) { - newValue = false; - } - getState().checked = newValue; + protected CheckBoxState getState(boolean markAsDirty) { + return (CheckBoxState) super.getState(markAsDirty); + } + + @Override + protected void doSetValue(Boolean value) { + getState().checked = value; } public void addBlurListener(BlurListener listener) { @@ -150,71 +148,22 @@ public class CheckBox extends LegacyAbstractField<Boolean> { BlurListener.blurMethod); } - /** - * @deprecated As of 7.0, replaced by {@link #addBlurListener(BlurListener)} - **/ - @Deprecated - public void addListener(BlurListener listener) { - addBlurListener(listener); - } - public void removeBlurListener(BlurListener listener) { removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener); } - /** - * @deprecated As of 7.0, replaced by - * {@link #removeBlurListener(BlurListener)} - **/ - @Deprecated - public void removeListener(BlurListener listener) { - removeBlurListener(listener); - } - public void addFocusListener(FocusListener listener) { addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener, FocusListener.focusMethod); } - /** - * @deprecated As of 7.0, replaced by - * {@link #addFocusListener(FocusListener)} - **/ - @Deprecated - public void addListener(FocusListener listener) { - addFocusListener(listener); - } - public void removeFocusListener(FocusListener listener) { removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener); } - /** - * @deprecated As of 7.0, replaced by - * {@link #removeFocusListener(FocusListener)} - **/ - @Deprecated - public void removeListener(FocusListener listener) { - removeFocusListener(listener); - } - - /** - * Get the boolean value of the button state. - * - * @return True iff the button is pressed down or checked. - * - * @deprecated As of 7.0, use {@link #getValue()} instead and, if needed, - * handle null values. - */ - @Deprecated - public boolean booleanValue() { - Boolean value = getValue(); - return (null == value) ? false : value.booleanValue(); - } - /* * (non-Javadoc) - * + * * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element, * com.vaadin.ui.declarative.DesignContext) */ @@ -224,13 +173,13 @@ public class CheckBox extends LegacyAbstractField<Boolean> { if (design.hasAttr("checked")) { this.setValue( DesignAttributeHandler.readAttribute("checked", - design.attributes(), Boolean.class), false, true); + design.attributes(), Boolean.class), false); } } /* * (non-Javadoc) - * + * * @see com.vaadin.ui.AbstractField#getCustomAttributes() */ @Override @@ -242,7 +191,7 @@ public class CheckBox extends LegacyAbstractField<Boolean> { /* * (non-Javadoc) - * + * * @see com.vaadin.ui.AbstractField#writeDesign(org.jsoup.nodes.Element, * com.vaadin.ui.declarative.DesignContext) */ @@ -255,15 +204,4 @@ public class CheckBox extends LegacyAbstractField<Boolean> { def.getValue(), Boolean.class); } - @Override - public void clear() { - setValue(Boolean.FALSE); - } - - @Override - public boolean isEmpty() { - return getValue() == null || getValue().equals(Boolean.FALSE); - - } - } |