From 9e146487a2dec08b538f87e650e8f714ac2089cf Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 22 Dec 2011 08:27:52 +0200 Subject: [PATCH] Removed getStringValue based on API review meeting --- .../vaadin/data/util/AbstractProperty.java | 18 +------ .../vaadin/data/util/IndexedContainer.java | 19 +------- .../vaadin/data/util/PropertyFormatter.java | 18 ++----- .../util/sqlcontainer/ColumnProperty.java | 23 +-------- src/com/vaadin/ui/AbstractField.java | 47 +++++++++---------- src/com/vaadin/ui/AbstractTextField.java | 2 +- src/com/vaadin/ui/ProgressIndicator.java | 11 ----- src/com/vaadin/ui/RichTextArea.java | 2 +- .../tests/TestForContainerFilterable.java | 8 ++-- .../DefaultHandleUnparsableDateField.java | 3 +- .../com/vaadin/tests/tickets/Ticket2053.java | 2 +- .../com/vaadin/tests/tickets/Ticket2090.java | 4 +- 12 files changed, 40 insertions(+), 117 deletions(-) diff --git a/src/com/vaadin/data/util/AbstractProperty.java b/src/com/vaadin/data/util/AbstractProperty.java index 5e90d11831..3b6db3807e 100644 --- a/src/com/vaadin/data/util/AbstractProperty.java +++ b/src/com/vaadin/data/util/AbstractProperty.java @@ -59,8 +59,7 @@ public abstract class AbstractProperty implements Property, * format. * * @return String representation of the value stored in the Property - * @deprecated use the property value directly, or {@link #getStringValue()} - * during migration period + * @deprecated use {@link #getValue()} instead and possibly toString on that */ @Deprecated @Override @@ -70,21 +69,6 @@ public abstract class AbstractProperty implements Property, + ".toString()"); } - /** - * Returns the value of the Property in human readable textual - * format. - * - * @return String representation of the value stored in the Property - * @since 7.0 - */ - public String getStringValue() { - final Object value = getValue(); - if (value == null) { - return null; - } - return value.toString(); - } - /* Events */ /** diff --git a/src/com/vaadin/data/util/IndexedContainer.java b/src/com/vaadin/data/util/IndexedContainer.java index 424fccb1e9..1e0a2fae1a 100644 --- a/src/com/vaadin/data/util/IndexedContainer.java +++ b/src/com/vaadin/data/util/IndexedContainer.java @@ -894,8 +894,8 @@ public class IndexedContainer extends * * @return String representation of the value stored in the * Property - * @deprecated use the property value directly, or - * {@link #getStringValue()} during migration period + * @deprecated use {@link #getValue()} instead and possibly toString on + * that */ @Deprecated @Override @@ -904,21 +904,6 @@ public class IndexedContainer extends "Use Property.getValue() instead of IndexedContainerProperty.toString()"); } - /** - * Returns the value of the Property in human readable - * textual format. - * - * @return String representation of the value stored in the Property - * @since 7.0 - */ - public String getStringValue() { - final Object value = getValue(); - if (value == null) { - return null; - } - return value.toString(); - } - /** * Calculates a integer hash-code for the Property that's unique inside * the Item containing the Property. Two different Properties inside the diff --git a/src/com/vaadin/data/util/PropertyFormatter.java b/src/com/vaadin/data/util/PropertyFormatter.java index e126d97d3c..a63973535b 100644 --- a/src/com/vaadin/data/util/PropertyFormatter.java +++ b/src/com/vaadin/data/util/PropertyFormatter.java @@ -106,7 +106,7 @@ public abstract class PropertyFormatter extends AbstractProperty .removeListener(this); } readOnly = isReadOnly(); - prevValue = getStringValue(); + prevValue = getValue(); } dataSource = newDataSource; @@ -124,7 +124,7 @@ public abstract class PropertyFormatter extends AbstractProperty if (isReadOnly() != readOnly) { fireReadOnlyStatusChange(); } - String newVal = getStringValue(); + String newVal = getValue(); if ((prevValue == null && newVal != null) || (prevValue != null && !prevValue.equals(newVal))) { fireValueChange(); @@ -143,18 +143,6 @@ public abstract class PropertyFormatter extends AbstractProperty * String given by format(). */ public String getValue() { - return getStringValue(); - } - - /** - * Get the formatted value. For PropertyFormatter, this is identical with - * {@link #getValue()}. - * - * @return If the datasource returns null, this is null. Otherwise this is - * String given by format(). - */ - @Override - public String getStringValue() { T value = dataSource == null ? null : dataSource.getValue(); if (value == null) { return null; @@ -219,7 +207,7 @@ public abstract class PropertyFormatter extends AbstractProperty } else { try { dataSource.setValue(parse(newValue.toString())); - if (!newValue.equals(getStringValue())) { + if (!newValue.equals(getValue())) { fireValueChange(); } } catch (Exception e) { diff --git a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java index 5e152da79e..a74db6ce8a 100644 --- a/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java +++ b/src/com/vaadin/data/util/sqlcontainer/ColumnProperty.java @@ -160,8 +160,7 @@ final public class ColumnProperty implements Property { * Returns the value of the Property in human readable textual format. * * @see java.lang.Object#toString() - * @deprecated get the string representation from the value, or use - * getStringValue() during migration + * @deprecated get the string representation from the value */ @Deprecated @Override @@ -170,26 +169,6 @@ final public class ColumnProperty implements Property { "Use ColumnProperty.getValue() instead of ColumnProperty.toString()"); } - /** - * Returns the (UI type) value of the field converted to a String using - * toString(). - * - * This method exists to help migration from the use of Property.toString() - * to get the field value - for new applications, access getValue() - * directly. This method may disappear in future Vaadin versions. - * - * @return string representation of the field value or null if the value is - * null - * @since 7.0 - */ - public String getStringValue() { - final Object value = getValue(); - if (value == null) { - return null; - } - return value.toString(); - } - public void setOwner(RowItem owner) { if (owner == null) { throw new IllegalArgumentException("Owner can not be set to null."); diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index cbdee0eae1..3e75da5ae2 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -13,6 +13,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.logging.Logger; import com.vaadin.Application; import com.vaadin.data.Buffered; @@ -63,6 +64,9 @@ public abstract class AbstractField extends AbstractComponent implements /* Private members */ + private static final Logger logger = Logger.getLogger(AbstractField.class + .getName()); + /** * Value of the abstract field. */ @@ -340,16 +344,20 @@ public abstract class AbstractField extends AbstractComponent implements } } + /** + * Gets the value from the data source. This is only here because of clarity + * in the code that handles both the data model value and the field value. + * + * @return The value of the property data source + */ private Object getDataSourceValue() { return dataSource.getValue(); } /** - * Returns the value that is or should be displayed in the field. This is - * always of type T. - * - * This method should return the converter data source value if there are no - * buffered changes in the field. + * Returns the field value. This is always identical to {@link #getValue()} + * and only here because of clarity in the code that handles both the data + * model value and the field value. * * @return The value of the field */ @@ -488,32 +496,21 @@ public abstract class AbstractField extends AbstractComponent implements /* Property interface implementation */ /** - * Returns the value of the Property in human readable textual format. + * Returns the (field) value converted to a String using toString(). * * @see java.lang.Object#toString() - * @deprecated get the string representation from the data source, or use - * getStringValue() during migration + * @deprecated Instead use {@link #getValue()} to get the value of the + * field, {@link #getConvertedValue()} to get the field value + * converted to the data model type or + * {@link #getPropertyDataSource()} .getValue() to get the value + * of the data source. */ @Deprecated @Override public String toString() { - throw new UnsupportedOperationException( - "Use Property.getValue() instead of " + getClass() - + ".toString()"); - } - - /** - * Returns the (UI type) value of the field converted to a String. - * - * This method exists to help migration from the use of Property.toString() - * to get the field value. For new applications, it is often better to - * access getValue() directly. - * - * @return string representation of the field value or null if the value is - * null - * @since 7.0 - */ - public String getStringValue() { + logger.warning("You are using AbstractField.toString() to get the value for a " + + getClass().getSimpleName() + + ". This is not recommended and will not be supported in future versions."); final Object value = getFieldValue(); if (value == null) { return null; diff --git a/src/com/vaadin/ui/AbstractTextField.java b/src/com/vaadin/ui/AbstractTextField.java index 7d2509b978..96d8a11410 100644 --- a/src/com/vaadin/ui/AbstractTextField.java +++ b/src/com/vaadin/ui/AbstractTextField.java @@ -375,7 +375,7 @@ public abstract class AbstractTextField extends AbstractField implements @Override protected boolean isEmpty() { - return super.isEmpty() || getStringValue().length() == 0; + return super.isEmpty() || getValue().length() == 0; } /** diff --git a/src/com/vaadin/ui/ProgressIndicator.java b/src/com/vaadin/ui/ProgressIndicator.java index 30555f9427..cc17333cc4 100644 --- a/src/com/vaadin/ui/ProgressIndicator.java +++ b/src/com/vaadin/ui/ProgressIndicator.java @@ -149,17 +149,6 @@ public class ProgressIndicator extends AbstractField implements dataSource.setValue(newValue); } - /** - * @see com.vaadin.ui.AbstractField#toString() - * @deprecated use the data source value instead of toString() - */ - @Deprecated - @Override - public String toString() { - throw new UnsupportedOperationException( - "Use Property.getValue() instead of ProgressIndicator.toString()"); - } - /** * @see com.vaadin.ui.AbstractField#getType() */ diff --git a/src/com/vaadin/ui/RichTextArea.java b/src/com/vaadin/ui/RichTextArea.java index 1ef843b789..ea22a6b54b 100644 --- a/src/com/vaadin/ui/RichTextArea.java +++ b/src/com/vaadin/ui/RichTextArea.java @@ -343,7 +343,7 @@ public class RichTextArea extends AbstractField { @Override protected boolean isEmpty() { - return super.isEmpty() || getStringValue().length() == 0; + return super.isEmpty() || getValue().length() == 0; } } diff --git a/tests/testbench/com/vaadin/tests/TestForContainerFilterable.java b/tests/testbench/com/vaadin/tests/TestForContainerFilterable.java index 6a61674e9b..92b7ae4f62 100644 --- a/tests/testbench/com/vaadin/tests/TestForContainerFilterable.java +++ b/tests/testbench/com/vaadin/tests/TestForContainerFilterable.java @@ -62,12 +62,12 @@ public class TestForContainerFilterable extends CustomComponent { filterButton.addListener(new Button.ClickListener() { public void buttonClick(ClickEvent event) { ic.removeAllContainerFilters(); - if (fooFilter.getStringValue().length() > 0) { - ic.addContainerFilter("foo", fooFilter.getStringValue(), false, + if (fooFilter.getValue().length() > 0) { + ic.addContainerFilter("foo", fooFilter.getValue(), false, false); } - if (barFilter.getStringValue().length() > 0) { - ic.addContainerFilter("bar", barFilter.getStringValue(), true, + if (barFilter.getValue().length() > 0) { + ic.addContainerFilter("bar", barFilter.getValue(), true, true); } count.setValue("Rows in table: " + ic.size()); diff --git a/tests/testbench/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java b/tests/testbench/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java index 14c0198270..060c7fcc0a 100644 --- a/tests/testbench/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java +++ b/tests/testbench/com/vaadin/tests/components/datefield/DefaultHandleUnparsableDateField.java @@ -17,7 +17,8 @@ public class DefaultHandleUnparsableDateField extends TestBase { date.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { if (date.isValid()) { - getMainWindow().showNotification(date.getStringValue()); + getMainWindow() + .showNotification(date.getValue().toString()); } } diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2053.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2053.java index a2ff1816e0..751dbbae01 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2053.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2053.java @@ -37,7 +37,7 @@ public class Ticket2053 extends Application.LegacyApplication { tf.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { main.addComponent(new Label(name + " send text:" - + tf.getStringValue())); + + tf.getValue())); } }); for (int i = 0; i < 3; i++) { diff --git a/tests/testbench/com/vaadin/tests/tickets/Ticket2090.java b/tests/testbench/com/vaadin/tests/tickets/Ticket2090.java index de89f1baec..b0bc546065 100644 --- a/tests/testbench/com/vaadin/tests/tickets/Ticket2090.java +++ b/tests/testbench/com/vaadin/tests/tickets/Ticket2090.java @@ -30,7 +30,7 @@ public class Ticket2090 extends Application.LegacyApplication { height.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { try { - target.setHeight(height.getStringValue()); + target.setHeight(height.getValue()); height.setComponentError(null); updateLabel(); } catch (Exception e) { @@ -41,7 +41,7 @@ public class Ticket2090 extends Application.LegacyApplication { width.addListener(new Property.ValueChangeListener() { public void valueChange(ValueChangeEvent event) { try { - target.setWidth(width.getStringValue()); + target.setWidth(width.getValue()); width.setComponentError(null); updateLabel(); } catch (Exception e) { -- 2.39.5