]> source.dussan.org Git - vaadin-framework.git/commitdiff
Eliminate more cases that used Property.toString().
authorHenri Sara <hesara@vaadin.com>
Tue, 8 Nov 2011 09:24:12 +0000 (11:24 +0200)
committerHenri Sara <hesara@vaadin.com>
Tue, 8 Nov 2011 09:24:12 +0000 (11:24 +0200)
Remaining possibly problematic cases include Label.compareTo(),
TestForPreconfiguredComponents and TestForTrees.

src/com/vaadin/data/util/IndexedContainer.java
src/com/vaadin/ui/AbstractField.java
src/com/vaadin/ui/AbstractSelect.java
src/com/vaadin/ui/Label.java
tests/testbench/com/vaadin/tests/TestForPreconfiguredComponents.java
tests/testbench/com/vaadin/tests/TestForTrees.java
tests/testbench/com/vaadin/tests/components/textfield/TextChangeEventsWithNonImmediateValueChange.java
tests/testbench/com/vaadin/tests/components/tree/TreeFocusGaining.java
tests/testbench/com/vaadin/tests/dd/DDTest2.java
tests/testbench/com/vaadin/tests/tickets/Ticket2053.java

index c9499d4aa8287ba43a391cb17671f3832a3182cb..a6e03970ccb5dd03e9c4be49ce9c7df739d5e734 100644 (file)
@@ -691,8 +691,8 @@ public class IndexedContainer extends
         /**
          * Gets the <code>String</code> representation of the contents of the
          * Item. The format of the string is a space separated catenation of the
-         * <code>String</code> representations of the Properties contained by
-         * the Item.
+         * <code>String</code> representations of the values of the Properties
+         * contained by the Item.
          * 
          * @return <code>String</code> representation of the Item contents
          */
@@ -702,8 +702,7 @@ public class IndexedContainer extends
 
             for (final Iterator<?> i = propertyIds.iterator(); i.hasNext();) {
                 final Object propertyId = i.next();
-                // TODO do not use Property.toString()
-                retValue += getItemProperty(propertyId).toString();
+                retValue += getItemProperty(propertyId).getValue();
                 if (i.hasNext()) {
                     retValue += " ";
                 }
index 007f851a722936aaf865f5dbc358ba900f3ed0e8..7b686fd3976762e24f97c5b0f54fcf0704a6f7f1 100644 (file)
@@ -299,7 +299,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
 
                 // Discards buffer by overwriting from datasource
                 newValue = dataSource.getValue();
-                if (String.class == getType()) {
+                if (String.class == getType() && newValue != null) {
                     newValue = newValue.toString();
                 }
 
@@ -390,7 +390,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
         readThroughMode = readThrough;
         if (!isModified() && readThroughMode && dataSource != null) {
             Object newValue = dataSource.getValue();
-            if (String.class == getType()) {
+            if (String.class == getType() && newValue != null) {
                 newValue = newValue.toString();
             }
             setInternalValue(newValue);
@@ -468,7 +468,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
         }
 
         Object result = dataSource.getValue();
-        if (String.class == getType()) {
+        if (String.class == getType() && result != null) {
             result = result.toString();
         }
         return result;
@@ -640,7 +640,7 @@ public abstract class AbstractField extends AbstractComponent implements Field,
         try {
             if (dataSource != null) {
                 Object newValue = dataSource.getValue();
-                if (String.class == getType()) {
+                if (String.class == getType() && newValue != null) {
                     newValue = newValue.toString();
                 }
                 setInternalValue(newValue);
index 646d898a54b8058a79cd9974e7d3ef15dbde3453..eaac3bb4c5dfffd6de21227969668dd17df00e9b 100644 (file)
@@ -1080,7 +1080,10 @@ public abstract class AbstractSelect extends AbstractField implements
             final Property p = getContainerProperty(itemId,
                     getItemCaptionPropertyId());
             if (p != null) {
-                caption = p.toString();
+                Object value = p.getValue();
+                if (value != null) {
+                    caption = value.toString();
+                }
             }
             break;
         }
index c7504230e37d573e0b5c74eda09834f44bf6504e..1249f20a62899a561b8b7b94811895378ec44c30 100644 (file)
@@ -257,16 +257,22 @@ public class Label extends AbstractComponent implements Property,
     }
 
     /**
-     * TODO temporary method to help eliminate the use of toString()
+     * Returns the value of the <code>Property</code> in human readable textual
+     * format.
      * 
-     * @return
+     * This method exists to help migration from previous Vaadin versions by
+     * providing a simple replacement for {@link #toString()}. However, it is
+     * normally better to use the value of the label directly.
+     * 
+     * @return String representation of the value stored in the Property
+     * @since 7.0
      */
     public String getStringValue() {
         if (dataSource == null) {
             throw new IllegalStateException(DATASOURCE_MUST_BE_SET);
         }
-        // TODO do not use Property.toString()
-        return dataSource.toString();
+        Object value = dataSource.getValue();
+        return (null != value) ? value.toString() : null;
     }
 
     /**
index 1c7a9e6c64bb5cedbf252ae9b5877ff16db03d30..caea457ccd4491d76dfec0588246f6ac52df0d41 100644 (file)
@@ -160,7 +160,7 @@ public class TestForPreconfiguredComponents extends CustomComponent implements
         t.addListener(new Listener() {
             public void componentEvent(Event event) {
                 status.addComponent(new Label(event.getClass().getName()));
-                // TODO should not use Property.toString()
+                // TODO should not use Field.toString()
                 status.addComponent(new Label("selected: "
                         + event.getSource().toString()));
             }
index dc9cb66f0e06da346d6f529a2fe8e46670a10f4b..c5f66a2b0024526d21277dbe1d1799a5d3c92e02 100644 (file)
@@ -142,7 +142,7 @@ public class TestForTrees extends CustomComponent implements Handler {
         t.addListener(new Listener() {
             public void componentEvent(Event event) {
                 status.addComponent(new Label(event.getClass().getName()));
-                // TODO should not use Property.toString()
+                // TODO should not use Field.toString()
                 status.addComponent(new Label("selected: "
                         + event.getSource().toString()));
             }
index 051f50988574c791c2297320c5fc61fefc3d617a..f44527bc1c1e6e2ea2afbb848bae7092a0e81db7 100644 (file)
@@ -33,8 +33,7 @@ public class TextChangeEventsWithNonImmediateValueChange extends TestBase {
         tf.addListener(new ValueChangeListener() {
 
             public void valueChange(ValueChangeEvent event) {
-                // TODO should not use Property.toString()
-                l.log("Value change:" + event.getProperty().toString());
+                l.log("Value change:" + event.getProperty().getValue());
             }
         });
 
index e784009bce7dd8ce870db47d05e0d293a5e8940a..87170214ca8a4f5dee35065ddbfb92592709b5e9 100644 (file)
@@ -21,7 +21,7 @@ public class TreeFocusGaining extends TestBase {
         textField.addListener(new Property.ValueChangeListener() {
 
             public void valueChange(ValueChangeEvent event) {
-                log.log("TF value now:" + event.getProperty());
+                log.log("TF value now:" + event.getProperty().getValue());
             }
         });
 
@@ -31,7 +31,7 @@ public class TreeFocusGaining extends TestBase {
         tree.addListener(new Property.ValueChangeListener() {
 
             public void valueChange(ValueChangeEvent event) {
-                log.log("Tree value now:" + event.getProperty());
+                log.log("Tree value now:" + event.getProperty().getValue());
             }
         });
         tree.setImmediate(true);
index 60d4addd24797b55726efc15d85c758efce23dd6..961a60f7760ae942b58d36cfb2affdca05f3a8d2 100644 (file)
@@ -94,13 +94,13 @@ public class DDTest2 extends TestBase {
                 if (transferable instanceof TableTransferable) {
                     TableTransferable tr = (TableTransferable) transferable;
                     System.out.println("From table row" + tr.getPropertyId());
-                    // TODO should not use Property.toString()
-                    data = tr.getSourceContainer().getItem(tr.getItemId())
-                            .getItemProperty(tr.getPropertyId()).toString();
-
+                    Object value = tr.getSourceContainer()
+                            .getItem(tr.getItemId())
+                            .getItemProperty(tr.getPropertyId()).getValue();
+                    data = (null != value) ? value.toString() : null;
                 }
                 if (data == null) {
-                    data = "-no Text data flawor-";
+                    data = "-no Text data flavor-";
                 }
                 tree3.addItem(data);
                 AbstractSelect.AbstractSelectTargetDetails dropTargetData = (AbstractSelect.AbstractSelectTargetDetails) dropEvent
@@ -138,7 +138,7 @@ public class DDTest2 extends TestBase {
             public void drop(DragAndDropEvent event) {
                 /*
                  * We know transferrable is from table, so it is of type
-                 * DataBindedTransferrable
+                 * DataBoundTransferrable
                  */
                 DataBoundTransferable tr = (DataBoundTransferable) event
                         .getTransferable();
@@ -148,9 +148,10 @@ public class DDTest2 extends TestBase {
                     // if the source is from table (not from tree1 itself),
                     // transfer Name property and use it as an identifier in
                     // tree1
-                    // TODO should not use Property.toString()
-                    String name = sourceContainer.getItem(itemId)
-                            .getItemProperty("Name").toString();
+                    Object nameValue = sourceContainer.getItem(itemId)
+                            .getItemProperty("Name").getValue();
+                    String name = (null != nameValue) ? nameValue.toString()
+                            : null;
 
                     tree1.addItem(name);
                     tree1.setChildrenAllowed(name, false);
index cb1776e06f192990c810b6f4c7b94e2c2cf7c2b0..5b83c3033bce7237ebced2f948d554d63c6f5d13 100644 (file)
@@ -41,7 +41,6 @@ public class Ticket2053 extends Application {
                 c.addComponent(tf);
                 tf.addListener(new Property.ValueChangeListener() {
                     public void valueChange(ValueChangeEvent event) {
-                        // TODO should not use Property.toString()
                         main.addComponent(new Label(name + " send text:"
                                 + tf.getStringValue()));
                     }