Skip to content

Commit

Permalink
Declarative for DateFields (and related) with ISO8601 (#16313)
Browse files Browse the repository at this point in the history
DesignAttributeHandler supports method names that contains some words in
uppercase

DesignAttributeHandler and other components now use extensible Formatter
with Converters rather than static methods

Change-Id: I9f68414bd4821f47ff37a26375091d154cae9a93
  • Loading branch information
vaadin-miki authored and Vaadin Code Review committed Feb 3, 2015
1 parent 293b62a commit a508ed7
Show file tree
Hide file tree
Showing 16 changed files with 1,445 additions and 366 deletions.
4 changes: 2 additions & 2 deletions server/src/com/vaadin/ui/AbsoluteLayout.java
Expand Up @@ -759,8 +759,8 @@ public void writeDesign(Element design, DesignContext designContext) {
private void writePositionAttribute(Node node, String key, String symbol, private void writePositionAttribute(Node node, String key, String symbol,
Float value) { Float value) {
if (value != null) { if (value != null) {
String valueString = DesignAttributeHandler.formatFloat(value String valueString = DesignAttributeHandler.getFormatter().format(
.floatValue()); value);
node.attr(key, valueString + symbol); node.attr(key, valueString + symbol);
} }
} }
Expand Down
18 changes: 8 additions & 10 deletions server/src/com/vaadin/ui/AbstractComponent.java
Expand Up @@ -959,8 +959,8 @@ public void readDesign(Element design, DesignContext designContext) {
} }
// handle immediate // handle immediate
if (attr.hasKey("immediate")) { if (attr.hasKey("immediate")) {
setImmediate(DesignAttributeHandler.parseBoolean(attr setImmediate(DesignAttributeHandler.getFormatter().parse(
.get("immediate"))); attr.get("immediate"), Boolean.class));
} }


// handle locale // handle locale
Expand All @@ -984,8 +984,8 @@ public void readDesign(Element design, DesignContext designContext) {


// handle responsive // handle responsive
if (attr.hasKey("responsive")) { if (attr.hasKey("responsive")) {
setResponsive(DesignAttributeHandler.parseBoolean(attr setResponsive(DesignAttributeHandler.getFormatter().parse(
.get("responsive"))); attr.get("responsive"), Boolean.class));
} }
// check for unsupported attributes // check for unsupported attributes
Set<String> supported = new HashSet<String>(); Set<String> supported = new HashSet<String>();
Expand Down Expand Up @@ -1138,9 +1138,8 @@ private void writeSize(Attributes attributes, Component defaultInstance) {
} else if (widthAuto) { } else if (widthAuto) {
attributes.put("width-auto", "true"); attributes.put("width-auto", "true");
} else { } else {
String widthString = DesignAttributeHandler String widthString = DesignAttributeHandler.getFormatter()
.formatFloat(getWidth()) .format(getWidth()) + getWidthUnits().getSymbol();
+ getWidthUnits().getSymbol();
attributes.put("width", widthString); attributes.put("width", widthString);


} }
Expand All @@ -1152,9 +1151,8 @@ private void writeSize(Attributes attributes, Component defaultInstance) {
} else if (heightAuto) { } else if (heightAuto) {
attributes.put("height-auto", "true"); attributes.put("height-auto", "true");
} else { } else {
String heightString = DesignAttributeHandler String heightString = DesignAttributeHandler.getFormatter()
.formatFloat(getHeight()) .format(getHeight()) + getHeightUnits().getSymbol();
+ getHeightUnits().getSymbol();
attributes.put("height", heightString); attributes.put("height", heightString);
} }
} }
Expand Down
4 changes: 2 additions & 2 deletions server/src/com/vaadin/ui/AbstractOrderedLayout.java
Expand Up @@ -563,8 +563,8 @@ public void writeDesign(Element design, DesignContext designContext) {
if (expandRatio == 1.0f) { if (expandRatio == 1.0f) {
childElement.attr(":expand", ""); childElement.attr(":expand", "");
} else if (expandRatio > 0) { } else if (expandRatio > 0) {
childElement.attr(":expand", childElement.attr(":expand", DesignAttributeHandler
DesignAttributeHandler.formatFloat(expandRatio)); .getFormatter().format(expandRatio));
} }
} }
} }
Expand Down
41 changes: 41 additions & 0 deletions server/src/com/vaadin/ui/DateField.java
Expand Up @@ -24,6 +24,9 @@
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.logging.Logger;

import org.jsoup.nodes.Element;


import com.vaadin.data.Property; import com.vaadin.data.Property;
import com.vaadin.data.Validator; import com.vaadin.data.Validator;
Expand All @@ -40,6 +43,8 @@
import com.vaadin.shared.ui.datefield.DateFieldConstants; import com.vaadin.shared.ui.datefield.DateFieldConstants;
import com.vaadin.shared.ui.datefield.Resolution; import com.vaadin.shared.ui.datefield.Resolution;
import com.vaadin.shared.ui.datefield.TextualDateFieldState; import com.vaadin.shared.ui.datefield.TextualDateFieldState;
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;


/** /**
* <p> * <p>
Expand Down Expand Up @@ -1061,4 +1066,40 @@ public UnparsableDateString(String message) {
} }


} }

@Override
public void readDesign(Element design, DesignContext designContext) {
super.readDesign(design, designContext);
if (design.hasAttr("value") && !design.attr("value").isEmpty()) {
Date date = DesignAttributeHandler.getFormatter().parse(
design.attr("value"), Date.class);
// formatting will return null if it cannot parse the string
if (date == null) {
Logger.getLogger(DateField.class.getName()).info(
"cannot parse " + design.attr("value") + " as date");
}
this.setValue(date);
}
}

@Override
public void writeDesign(Element design, DesignContext designContext) {
super.writeDesign(design, designContext);
if (getValue() != null) {
design.attr("value",
DesignAttributeHandler.getFormatter().format(getValue()));
}
}

/**
* Returns current date-out-of-range error message.
*
* @see #setDateOutOfRangeMessage(String)
* @since 7.4
* @return Current error message for dates out of range.
*/
public String getDateOutOfRangeMessage() {
return dateOutOfRangeMessage;
}

} }

0 comments on commit a508ed7

Please sign in to comment.