Преглед изворни кода

Make onChange throw in TextField and CheckBox when Handler is null

Add readDesign, writeDesign, getCustomAttributes to CheckBox

Change-Id: I412413e53fde5a02a4f8a76a6b47b002141435a2
feature/vaadin8-book
Aleksi Hietanen пре 8 година
родитељ
комит
ff768d1f88

+ 3
- 0
server/src/main/java/com/vaadin/ui/components/fields/AbstractTextField.java Прегледај датотеку

@@ -143,6 +143,9 @@ public abstract class AbstractTextField extends AbstractComponent

@Override
public Registration onChange(Handler<String> handler) {
if (handler == null)
throw new IllegalArgumentException("Handler can't be null");
TextChangeListener l = e -> handler
.handleEvent(new com.vaadin.event.handler.Event<String>(this,
e.getText(), true));

+ 56
- 0
server/src/main/java/com/vaadin/ui/components/fields/CheckBox.java Прегледај датотеку

@@ -15,9 +15,13 @@
*/
package com.vaadin.ui.components.fields;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;

import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;

import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
import com.vaadin.event.handler.Handler;
import com.vaadin.event.handler.Registration;
@@ -26,6 +30,8 @@ import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
import com.vaadin.shared.ui.checkbox.CheckBoxState;
import com.vaadin.ui.AbstractComponent;
import com.vaadin.ui.components.HasValue;
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;

public class CheckBox extends AbstractComponent implements HasValue<Boolean> {

@@ -127,6 +133,8 @@ public class CheckBox extends AbstractComponent implements HasValue<Boolean> {

@Override
public Registration onChange(Handler<Boolean> handler) {
if (handler == null)
throw new IllegalArgumentException("Handler can't be null");
handlers.add(handler);
return () -> handlers.remove(handler);
}
@@ -140,5 +148,53 @@ public class CheckBox extends AbstractComponent implements HasValue<Boolean> {
protected CheckBoxState getState() {
return (CheckBoxState) super.getState();
}
@Override
protected CheckBoxState getState(boolean markAsDirty) {
return (CheckBoxState) super.getState(markAsDirty);
}
/*
* (non-Javadoc)
*
* @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element,
* com.vaadin.ui.declarative.DesignContext)
*/
@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
if (design.hasAttr("checked")) {
this.setValue(
DesignAttributeHandler.readAttribute("checked",
design.attributes(), Boolean.class), false);
}
}
/*
* (non-Javadoc)
*
* @see com.vaadin.ui.AbstractField#writeDesign(org.jsoup.nodes.Element,
* com.vaadin.ui.declarative.DesignContext)
*/
@Override
public void writeDesign(Element design, DesignContext designContext) {
super.writeDesign(design, designContext);
CheckBox def = (CheckBox) designContext.getDefaultInstance(this);
Attributes attr = design.attributes();
DesignAttributeHandler.writeAttribute("checked", attr, getValue(),
def.getValue(), Boolean.class);
}
/*
* (non-Javadoc)
*
* @see com.vaadin.ui.AbstractField#getCustomAttributes()
*/
@Override
protected Collection<String> getCustomAttributes() {
Collection<String> attributes = super.getCustomAttributes();
attributes.add("checked");
return attributes;
}

}

Loading…
Откажи
Сачувај