You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by "Sandro Martini (JIRA)" <ji...@apache.org> on 2009/06/17 17:18:07 UTC

[jira] Created: (PIVOT-155) Change Locale on Validators

Change Locale on Validators
---------------------------

                 Key: PIVOT-155
                 URL: https://issues.apache.org/jira/browse/PIVOT-155
             Project: Pivot
          Issue Type: Improvement
    Affects Versions: 1.2, 1.3
            Reporter: Sandro Martini
            Assignee: Greg Brown
            Priority: Minor
             Fix For: 1.3


Unable to change the Locale used in Validators.

For example, in TextInputValidatorTest, in the textinputFloatRange I've seen that giving inputs in the current Locale all works good, but I haven't find a way to change the Locale, or to set a different format to validators ... how can i do this ? 
Maybe the simplest thing could be to set a different Locale and let validators using it, in this case all the application would use only a Locale, but i think this is a common case (only a few times i had to manage more locales in the same application, showing more at the same time to the same user ... ). The best could be to have new settings alive without having to restart the application.

I have to run my applications in a multi-locale environment (but any user with its default or chosen locale) ... thanks.

As a sample, a portion of code that uses this could go for example in TextInputValidatorTest.


Hints for the implementation:

(1) make DecimalValidator not abstract - the reason it is currently abstract is a historical hold-over
(2) make the DecimalValidator constructors public
(3) modify the various *Validator classes to have extra constructors that take a Locale parameter.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Created: (PIVOT-155) Change Locale on Validators

Posted by Noel Grandin <no...@gmail.com>.
Aaah, that would it. Thanks!

Why is it that it is so hard to get programmers to generate reasonable
error messages? Sigh.

Todd Volkert wrote:
> Noel, before I dig too deeply into why you weren't able to commit, I wanted
> to verify that you did a fresh checkout of the svn tree using the *HTTPS*
> svn url.  If you've only checked out using HTTP, it won't let you commit,
> and the error message is entirely unhelpful :)
>
> -T
>
>   


Re: [jira] Created: (PIVOT-155) Change Locale on Validators

Posted by Todd Volkert <tv...@gmail.com>.
Noel, before I dig too deeply into why you weren't able to commit, I wanted
to verify that you did a fresh checkout of the svn tree using the *HTTPS*
svn url.  If you've only checked out using HTTP, it won't let you commit,
and the error message is entirely unhelpful :)

-T

Re: [jira] Created: (PIVOT-155) Change Locale on Validators

Posted by Sandro Martini <sa...@gmail.com>.
Hi to all,
after commit, tell me so next week i can try to redo my tests ... for
the moment thanks to all !!

And I'll send here my new test source for this feature, could be
useful to someone ...

Bye,
Sandro

Re: [jira] Created: (PIVOT-155) Change Locale on Validators

Posted by Todd Volkert <tv...@gmail.com>.
Done.  I'll add a gentle reminder to the JIRA ticket about you not being
listed as a possible assignee in JIRA and try to find out why you can't
commit.  Once we graduate, I think I'll have access to do such things
myself, but as a podling, I can only ask others :-(

-T

On Thu, Jun 18, 2009 at 3:34 AM, Noel Grandin <no...@gmail.com> wrote:

> Hi
>
> My commit access doesn't seem to be working - I don't know if it ever
> worked, since this is the first time I've tried it.
>
> So here's a patch - can someone else please commit this.
>
> Also, I don't seem to have authority to assign issues to myself in JIRA,
> so can someone please mark this issue completed.
>
> Thanks, Noel Grandin.
>
>
> Sandro Martini (JIRA) wrote:
> > Change Locale on Validators
> > ---------------------------
> >
> >                  Key: PIVOT-155
> >                  URL: https://issues.apache.org/jira/browse/PIVOT-155
> >              Project: Pivot
> >           Issue Type: Improvement
> >     Affects Versions: 1.2, 1.3
> >             Reporter: Sandro Martini
> >             Assignee: Greg Brown
> >             Priority: Minor
> >              Fix For: 1.3
> >
> >
> > Unable to change the Locale used in Validators.
> >
> > For example, in TextInputValidatorTest, in the textinputFloatRange I've
> seen that giving inputs in the current Locale all works good, but I haven't
> find a way to change the Locale, or to set a different format to validators
> ... how can i do this ?
> > Maybe the simplest thing could be to set a different Locale and let
> validators using it, in this case all the application would use only a
> Locale, but i think this is a common case (only a few times i had to manage
> more locales in the same application, showing more at the same time to the
> same user ... ). The best could be to have new settings alive without having
> to restart the application.
> >
> > I have to run my applications in a multi-locale environment (but any user
> with its default or chosen locale) ... thanks.
> >
> > As a sample, a portion of code that uses this could go for example in
> TextInputValidatorTest.
> >
> >
> > Hints for the implementation:
> >
> > (1) make DecimalValidator not abstract - the reason it is currently
> abstract is a historical hold-over
> > (2) make the DecimalValidator constructors public
> > (3) modify the various *Validator classes to have extra constructors that
> take a Locale parameter.
> >
> >
> >
>
>
> Index: wtk/src/org/apache/pivot/wtk/text/validation/DecimalValidator.java
> ===================================================================
> --- wtk/src/org/apache/pivot/wtk/text/validation/DecimalValidator.java
>  (revision 785933)
> +++ wtk/src/org/apache/pivot/wtk/text/validation/DecimalValidator.java
>  (working copy)
> @@ -16,24 +16,29 @@
>  import java.text.DecimalFormat;
>  import java.text.NumberFormat;
>  import java.text.ParseException;
> +import java.util.Locale;
>
>  /**
>  * A validator for decimal values.
>  *
>  * @author Noel Grandin
>  */
> -public abstract class DecimalValidator extends
> FormattedValidator<NumberFormat> {
> +public class DecimalValidator extends FormattedValidator<NumberFormat> {
>
> -    protected DecimalValidator(DecimalFormat format) {
> +    public DecimalValidator(DecimalFormat format) {
>         super(format);
>     }
>
> -    protected DecimalValidator() {
> +    public DecimalValidator() {
>         super(NumberFormat.getInstance());
>     }
>
> -    /** helper for textToObject */
> -    protected final Number parse(String text) {
> +    public DecimalValidator(Locale locale) {
> +        super(NumberFormat.getInstance(locale));
> +    }
> +
> +    /** helper method that wraps the ParseException in a RuntimeException.
> */
> +    protected final Number parseNumber(String text) {
>         try {
>             return format.parse(text);
>         } catch (ParseException ex) {
> Index:
> wtk/src/org/apache/pivot/wtk/text/validation/DoubleRangeValidator.java
> ===================================================================
> --- wtk/src/org/apache/pivot/wtk/text/validation/DoubleRangeValidator.java
>      (revision 785933)
> +++ wtk/src/org/apache/pivot/wtk/text/validation/DoubleRangeValidator.java
>      (working copy)
> @@ -13,6 +13,8 @@
>  */
>  package org.apache.pivot.wtk.text.validation;
>
> +import java.util.Locale;
> +
>  /**
>  * A validator for a double value limited to a range.
>  *
> @@ -26,11 +28,23 @@
>         this.maxValue = 1;
>     }
>
> +    public DoubleRangeValidator(Locale locale) {
> +        super(locale);
> +        this.minValue = 0;
> +        this.maxValue = 1;
> +    }
> +
>     public DoubleRangeValidator(double minValue, double maxValue) {
>         this.minValue = minValue;
>         this.maxValue = maxValue;
>     }
>
> +    public DoubleRangeValidator(Locale locale, double minValue, double
> maxValue) {
> +        super(locale);
> +        this.minValue = minValue;
> +        this.maxValue = maxValue;
> +    }
> +
>     public double getMinimum() {
>         return minValue;
>     }
> @@ -58,4 +72,8 @@
>
>         return valid;
>     }
> +
> +    private final Double textToObject(String text) {
> +        return parseNumber(text).doubleValue();
> +    }
>  }
> \ No newline at end of file
> Index: wtk/src/org/apache/pivot/wtk/text/validation/DoubleValidator.java
> ===================================================================
> --- wtk/src/org/apache/pivot/wtk/text/validation/DoubleValidator.java
> (revision 785933)
> +++ wtk/src/org/apache/pivot/wtk/text/validation/DoubleValidator.java
> (working copy)
> @@ -13,6 +13,8 @@
>  */
>  package org.apache.pivot.wtk.text.validation;
>
> +import java.util.Locale;
> +
>  /**
>  * A validator for a double value.
>  *
> @@ -22,7 +24,7 @@
>     public DoubleValidator() {
>     }
>
> -    protected final Double textToObject(String text) {
> -        return parse(text).doubleValue();
> +    public DoubleValidator(Locale locale) {
> +        super(locale);
>     }
>  }
> Index:
> wtk/src/org/apache/pivot/wtk/text/validation/FloatRangeValidator.java
> ===================================================================
> --- wtk/src/org/apache/pivot/wtk/text/validation/FloatRangeValidator.java
>     (revision 785933)
> +++ wtk/src/org/apache/pivot/wtk/text/validation/FloatRangeValidator.java
>     (working copy)
> @@ -13,6 +13,8 @@
>  */
>  package org.apache.pivot.wtk.text.validation;
>
> +import java.util.Locale;
> +
>  /**
>  * A validator for a float value limited to a range.
>  *
> @@ -26,11 +28,23 @@
>         this.maxValue = 1;
>     }
>
> +    public FloatRangeValidator(Locale locale) {
> +        super(locale);
> +        this.minValue = 0;
> +        this.maxValue = 1;
> +    }
> +
>     public FloatRangeValidator(float minValue, float maxValue) {
>         this.minValue = minValue;
>         this.maxValue = maxValue;
>     }
>
> +    public FloatRangeValidator(Locale locale, float minValue, float
> maxValue) {
> +        super(locale);
> +        this.minValue = minValue;
> +        this.maxValue = maxValue;
> +    }
> +
>     public float getMinimum() {
>         return minValue;
>     }
> @@ -58,4 +72,8 @@
>
>         return valid;
>     }
> +
> +    private final Float textToObject(String text) {
> +        return parseNumber(text).floatValue();
> +    }
>  }
> Index: wtk/src/org/apache/pivot/wtk/text/validation/FloatValidator.java
> ===================================================================
> --- wtk/src/org/apache/pivot/wtk/text/validation/FloatValidator.java
>  (revision 785933)
> +++ wtk/src/org/apache/pivot/wtk/text/validation/FloatValidator.java
>  (working copy)
> @@ -13,16 +13,39 @@
>  */
>  package org.apache.pivot.wtk.text.validation;
>
> +import java.util.Locale;
> +
>  /**
>  * A validator for a float value.
> - *
> + *
>  * @author Noel Grandin
>  */
>  public class FloatValidator extends DecimalValidator {
>     public FloatValidator() {
>     }
>
> -    protected final Float textToObject(String text) {
> -        return parse(text).floatValue();
> +    public FloatValidator(Locale locale) {
> +        super(locale);
> +    }
> +
> +    @Override
> +    public boolean isValid(String text) {
> +        if (!super.isValid(text))
> +            return false;
> +
> +        /*
> +         * DecimalFormat will parse the number as a double. Make sure the
> +         * resulting number is withing range for a float.
> +         */
> +        Number number = parseNumber(text);
> +        if (number.floatValue() > 0
> +                && number.floatValue() < number.doubleValue()) {
> +            return false;
> +        }
> +        if (number.floatValue() < 0
> +                && number.floatValue() > number.doubleValue()) {
> +            return false;
> +        }
> +        return true;
>     }
>  }
> Index: wtk/src/org/apache/pivot/wtk/text/validation/FormattedValidator.java
> ===================================================================
> --- wtk/src/org/apache/pivot/wtk/text/validation/FormattedValidator.java
>      (revision 785933)
> +++ wtk/src/org/apache/pivot/wtk/text/validation/FormattedValidator.java
>      (working copy)
> @@ -23,10 +23,10 @@
>  *
>  * @author Noel Grandin
>  */
> -public abstract class FormattedValidator<F extends Format> implements
> Validator {
> +public class FormattedValidator<F extends Format> implements Validator {
>     protected final F format;
>
> -    protected FormattedValidator(F format) {
> +    public FormattedValidator(F format) {
>         this.format = format;
>     }
>
> Index: wtk/src/org/apache/pivot/wtk/text/validation/IntRangeValidator.java
> ===================================================================
> --- wtk/src/org/apache/pivot/wtk/text/validation/IntRangeValidator.java
> (revision 785933)
> +++ wtk/src/org/apache/pivot/wtk/text/validation/IntRangeValidator.java
> (working copy)
> @@ -13,6 +13,8 @@
>  */
>  package org.apache.pivot.wtk.text.validation;
>
> +import java.util.Locale;
> +
>  /**
>  * A validator for an int value limited to a range.
>  *
> @@ -26,11 +28,23 @@
>         this.maxValue = 1;
>     }
>
> +    public IntRangeValidator(Locale locale) {
> +        super(locale);
> +        this.minValue = 0;
> +        this.maxValue = 1;
> +    }
> +
>     public IntRangeValidator(int minValue, int maxValue) {
>         this.minValue = minValue;
>         this.maxValue = maxValue;
>     }
>
> +    public IntRangeValidator(Locale locale, int minValue, int maxValue) {
> +        super(locale);
> +        this.minValue = minValue;
> +        this.maxValue = maxValue;
> +    }
> +
>     public int getMinimum() {
>         return minValue;
>     }
> @@ -58,4 +72,8 @@
>
>         return valid;
>     }
> +
> +    private final Integer textToObject(String text) {
> +        return parseNumber(text).intValue();
> +    }
>  }
> Index: wtk/src/org/apache/pivot/wtk/text/validation/IntValidator.java
> ===================================================================
> --- wtk/src/org/apache/pivot/wtk/text/validation/IntValidator.java
>  (revision 785933)
> +++ wtk/src/org/apache/pivot/wtk/text/validation/IntValidator.java
>  (working copy)
> @@ -13,6 +13,8 @@
>  */
>  package org.apache.pivot.wtk.text.validation;
>
> +import java.util.Locale;
> +
>  /**
>  * A validator for an int value.
>  *
> @@ -23,7 +25,9 @@
>         format.setParseIntegerOnly(true);
>     }
>
> -    protected final Integer textToObject(String text) {
> -        return parse(text).intValue();
> +    public IntValidator(Locale locale) {
> +        super(locale);
> +        format.setParseIntegerOnly(true);
>     }
> +
>  }
>
>

Re: [jira] Created: (PIVOT-155) Change Locale on Validators

Posted by Noel Grandin <no...@gmail.com>.
Hi

My commit access doesn't seem to be working - I don't know if it ever
worked, since this is the first time I've tried it.

So here's a patch - can someone else please commit this.

Also, I don't seem to have authority to assign issues to myself in JIRA,
so can someone please mark this issue completed.

Thanks, Noel Grandin.


Sandro Martini (JIRA) wrote:
> Change Locale on Validators
> ---------------------------
>
>                  Key: PIVOT-155
>                  URL: https://issues.apache.org/jira/browse/PIVOT-155
>              Project: Pivot
>           Issue Type: Improvement
>     Affects Versions: 1.2, 1.3
>             Reporter: Sandro Martini
>             Assignee: Greg Brown
>             Priority: Minor
>              Fix For: 1.3
>
>
> Unable to change the Locale used in Validators.
>
> For example, in TextInputValidatorTest, in the textinputFloatRange I've seen that giving inputs in the current Locale all works good, but I haven't find a way to change the Locale, or to set a different format to validators ... how can i do this ? 
> Maybe the simplest thing could be to set a different Locale and let validators using it, in this case all the application would use only a Locale, but i think this is a common case (only a few times i had to manage more locales in the same application, showing more at the same time to the same user ... ). The best could be to have new settings alive without having to restart the application.
>
> I have to run my applications in a multi-locale environment (but any user with its default or chosen locale) ... thanks.
>
> As a sample, a portion of code that uses this could go for example in TextInputValidatorTest.
>
>
> Hints for the implementation:
>
> (1) make DecimalValidator not abstract - the reason it is currently abstract is a historical hold-over
> (2) make the DecimalValidator constructors public
> (3) modify the various *Validator classes to have extra constructors that take a Locale parameter.
>
>
>   


Re: [jira] Resolved: (PIVOT-155) Change Locale on Validators

Posted by Greg Brown <gk...@mac.com>.
> thanks to Noel and to Greg for solving this issue.

All Noel. All I did was close the JIRA issue.  :-)


Re: [jira] Resolved: (PIVOT-155) Change Locale on Validators

Posted by Sandro Martini <sa...@gmail.com>.
Hi,
thanks to Noel and to Greg for solving this issue.

I'll try to use the new code (but in a two / three weeks, sorry i
can't before ...).

Tell me if i could add a simple case for this in the Test class
TextInputValidatorTest (or if Noel or Greg was to do this, could be a
useful feature to show).

Bye,
Sandro

[jira] Resolved: (PIVOT-155) Change Locale on Validators

Posted by "Greg Brown (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/PIVOT-155?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Greg Brown resolved PIVOT-155.
------------------------------

    Resolution: Fixed

This issue was resolved by Noel.


> Change Locale on Validators
> ---------------------------
>
>                 Key: PIVOT-155
>                 URL: https://issues.apache.org/jira/browse/PIVOT-155
>             Project: Pivot
>          Issue Type: Improvement
>    Affects Versions: 1.2, 1.3
>            Reporter: Sandro Martini
>            Assignee: Greg Brown
>            Priority: Minor
>             Fix For: 1.3
>
>
> Unable to change the Locale used in Validators.
> For example, in TextInputValidatorTest, in the textinputFloatRange I've seen that giving inputs in the current Locale all works good, but I haven't find a way to change the Locale, or to set a different format to validators ... how can i do this ? 
> Maybe the simplest thing could be to set a different Locale and let validators using it, in this case all the application would use only a Locale, but i think this is a common case (only a few times i had to manage more locales in the same application, showing more at the same time to the same user ... ). The best could be to have new settings alive without having to restart the application.
> I have to run my applications in a multi-locale environment (but any user with its default or chosen locale) ... thanks.
> As a sample, a portion of code that uses this could go for example in TextInputValidatorTest.
> Hints for the implementation:
> (1) make DecimalValidator not abstract - the reason it is currently abstract is a historical hold-over
> (2) make the DecimalValidator constructors public
> (3) modify the various *Validator classes to have extra constructors that take a Locale parameter.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.