You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2013/02/14 12:40:47 UTC

svn commit: r1446129 - in /pivot/branches/2.0.x: tests/src/org/apache/pivot/tests/ wtk/src/org/apache/pivot/wtk/validation/

Author: smartini
Date: Thu Feb 14 11:40:46 2013
New Revision: 1446129

URL: http://svn.apache.org/r1446129
Log:
PIVOT-892: add utility method in DecimalValidator (for later usage), and add EmptyTextValidator (even in the test application)

Added:
    pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java
Modified:
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java
    pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml
    pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/DecimalValidator.java

Modified: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java?rev=1446129&r1=1446128&r2=1446129&view=diff
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java (original)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/TextInputValidatorTest.java Thu Feb 14 11:40:46 2013
@@ -29,6 +29,7 @@ import org.apache.pivot.wtk.TextInput;
 import org.apache.pivot.wtk.TextInputListener;
 import org.apache.pivot.wtk.Window;
 import org.apache.pivot.wtk.validation.DoubleValidator;
+import org.apache.pivot.wtk.validation.EmptyTextValidator;
 import org.apache.pivot.wtk.validation.FloatRangeValidator;
 import org.apache.pivot.wtk.validation.FloatValidator;
 import org.apache.pivot.wtk.validation.IntRangeValidator;
@@ -52,6 +53,7 @@ public class TextInputValidatorTest  ext
     private TextInput textinputDateRegex = null;
     private TextInput textinputCustomBoolean = null;
     private TextInput textinputNotEmptyText = null;
+    private TextInput textinputEmptyText = null;
 
     @Override
     public void startup(Display display, Map<String, String> properties) throws Exception {
@@ -81,6 +83,7 @@ public class TextInputValidatorTest  ext
         textinputDateRegex = (TextInput)bxmlSerializer.getNamespace().get("textinputDateRegex");
         textinputCustomBoolean = (TextInput)bxmlSerializer.getNamespace().get("textinputCustomBoolean");
         textinputNotEmptyText = (TextInput)bxmlSerializer.getNamespace().get("textinputNotEmptyText");
+        textinputEmptyText = (TextInput)bxmlSerializer.getNamespace().get("textinputEmptyText");
 
         textinputLocale.setText(locale.toString());
 
@@ -100,7 +103,9 @@ public class TextInputValidatorTest  ext
         textinputFloat.setValidator(new FloatValidator());
 
         // standard float range model
-        textinputFloatRange.setText(nf.format(value));
+        // note that float approximations could give errors,
+        // try to increment/decrement the initial value near a range end, to see problems ...
+        textinputFloatRange.setText("123456789");  // (nf.format(value));
         textinputFloatRange.setValidator(new FloatRangeValidator(2.0f, 123456789f));
 
         // test the listener by updating a label
@@ -135,6 +140,10 @@ public class TextInputValidatorTest  ext
         textinputNotEmptyText.setText("  Not Empty, and with spaces  ");
         textinputNotEmptyText.setValidator(new NotEmptyTextValidator());
 
+        // validate any empty text, edge case
+        textinputEmptyText.setText("    ");
+        textinputEmptyText.setValidator(new EmptyTextValidator());
+
 
         window.setTitle("Text Input Validator Test");
         window.setMaximized(true);

Modified: pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml?rev=1446129&r1=1446128&r2=1446129&view=diff
==============================================================================
--- pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml (original)
+++ pivot/branches/2.0.x/tests/src/org/apache/pivot/tests/text_input_validator_test.bxml Thu Feb 14 11:40:46 2013
@@ -66,4 +66,10 @@ limitations under the License.
             styles="{wrapText:true}"
         />
     </TablePane.Row>
+    <TablePane.Row height="-1">
+        <Label text="empty text"/>
+        <TextInput bxml:id="textinputEmptyText"/>
+        <Label text="valid values: any empty text (note that it will be trimmed)"
+        />
+    </TablePane.Row>
 </TablePane>

Modified: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/DecimalValidator.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/DecimalValidator.java?rev=1446129&r1=1446128&r2=1446129&view=diff
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/DecimalValidator.java (original)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/DecimalValidator.java Thu Feb 14 11:40:46 2013
@@ -13,6 +13,7 @@
  */
 package org.apache.pivot.wtk.validation;
 
+import java.math.BigDecimal;
 import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.text.ParseException;
@@ -50,4 +51,13 @@ public class DecimalValidator extends Fo
             throw new RuntimeException(ex);
         }
     }
+
+    /** helper method that returns the widest number real instance,
+     * and extract later values depending on the precision needed.
+     */
+    protected final BigDecimal textToBigDecimal(String text) {
+        BigDecimal bd = new BigDecimal(parseNumber(text).toString());
+        return bd;
+    }
+
 }

Added: pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java
URL: http://svn.apache.org/viewvc/pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java?rev=1446129&view=auto
==============================================================================
--- pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java (added)
+++ pivot/branches/2.0.x/wtk/src/org/apache/pivot/wtk/validation/EmptyTextValidator.java Thu Feb 14 11:40:46 2013
@@ -0,0 +1,31 @@
+/*
+ * 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 License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pivot.wtk.validation;
+
+/**
+ * A validator for a (trimmed) text.
+ * <p>
+ * This is useful only when a value to be valid has to be absent.
+ */
+public class EmptyTextValidator implements Validator {
+
+    public EmptyTextValidator() {
+    }
+
+    @Override
+    public boolean isValid(String text) {
+        return (text.trim()).length() == 0;
+    }
+
+}