Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » DataBinding allow only digit?
DataBinding allow only digit? [message #334982] Fri, 13 March 2009 16:16 Go to next message
Stefano Zaccaria is currently offline Stefano ZaccariaFriend
Messages: 48
Registered: July 2009
Member
I am starting to use jface databinding in my app.
I would want to put a restrict on field Text for allow only digit, not char.
I found a snippet in swt like this:
However, I would put this restriction inside IValidator with binding. It
is possible?
Re: DataBinding allow only digit? [message #334983 is a reply to message #334982] Fri, 13 March 2009 16:17 Go to previous messageGo to next message
Stefano Zaccaria is currently offline Stefano ZaccariaFriend
Messages: 48
Registered: July 2009
Member
Stefano Zaccaria ha scritto:
> I am starting to use jface databinding in my app.
> I would want to put a restrict on field Text for allow only digit, not
> char.
> I found a snippet in swt like this:
> However, I would put this restriction inside IValidator with binding.
> It is possible?
The snipper code is:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
Re: DataBinding allow only digit? [message #334991 is a reply to message #334983] Fri, 13 March 2009 18:00 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 3/13/2009 12:17 PM, Stefano Zaccaria wrote:
> Stefano Zaccaria ha scritto:
>> I am starting to use jface databinding in my app.
>> I would want to put a restrict on field Text for allow only digit, not
>> char.
>> I found a snippet in swt like this:
>> However, I would put this restriction inside IValidator with binding.
>> It is possible?
> The snipper code is:
>
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
>

DataBinding can handle this kind of thing easily, just set an IValidator
on the UpdateValueStrategy that you use when binding your widget to your
model.
The package org.eclipse.core.internal.databinding.validation has a bunch
of useful IValidator implementations for you to use, or you can write
your own.
The Data Binding snippets page
http://wiki.eclipse.org/JFace_Data_Binding/Snippets has some examples of
using validation.

Hope this helps,
Eric
Re: DataBinding allow only digit? [message #334995 is a reply to message #334991] Sat, 14 March 2009 09:13 Go to previous messageGo to next message
Stefano Zaccaria is currently offline Stefano ZaccariaFriend
Messages: 48
Registered: July 2009
Member
Eric Rizzo ha scritto:
> On 3/13/2009 12:17 PM, Stefano Zaccaria wrote:
>> Stefano Zaccaria ha scritto:
>>> I am starting to use jface databinding in my app.
>>> I would want to put a restrict on field Text for allow only digit, not
>>> char.
>>> I found a snippet in swt like this:
>>> However, I would put this restriction inside IValidator with binding.
>>> It is possible?
>> The snipper code is:
>>
>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
>>
>>
>
> DataBinding can handle this kind of thing easily, just set an
> IValidator on the UpdateValueStrategy that you use when binding your
> widget to your model.
> The package org.eclipse.core.internal.databinding.validation has a
> bunch of useful IValidator implementations for you to use, or you can
> write your own.
> The Data Binding snippets page
> http://wiki.eclipse.org/JFace_Data_Binding/Snippets has some examples
> of using validation.
>
> Hope this helps,
> Eric
>
Thanks Eric,
I had just look IValidator, but it not prevent the user to insert a
wrong char. It signal to user that the string insert is wrong, but not
prevent to insert that. Example: I've a BigDecimal field as model and a
SWT Text field as Input, if the user insert "23.2a5" the IValidator
signal to the ui of the wrong string. But i would that when the user
insert "a" char the ui prevent to insert it as the snippet
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
do.
More, is possible with databinding formating the string? As example
currency, date, time etc

Thanks again

Stefano
Re: DataBinding allow only digit? [message #335005 is a reply to message #334995] Sun, 15 March 2009 17:02 Go to previous messageGo to next message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
This use case is not supported by DataBinding--you need to filter input
at the widget. You want to either use an SWT.Verify [1] listener on the
Text control, or use the FormattedText [2] control from Nebula.

Matthew

[1]
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19. java
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet179 .java

[2] http://www.eclipse.org/nebula/widgets/formattedtext/formatte dtext.php

Stefano Zaccaria wrote:
> Eric Rizzo ha scritto:
>> On 3/13/2009 12:17 PM, Stefano Zaccaria wrote:
>>> Stefano Zaccaria ha scritto:
>>>> I am starting to use jface databinding in my app.
>>>> I would want to put a restrict on field Text for allow only digit, not
>>>> char.
>>>> I found a snippet in swt like this:
>>>> However, I would put this restriction inside IValidator with binding.
>>>> It is possible?
>>> The snipper code is:
>>>
>>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
>>>
>>>
>>
>> DataBinding can handle this kind of thing easily, just set an
>> IValidator on the UpdateValueStrategy that you use when binding your
>> widget to your model.
>> The package org.eclipse.core.internal.databinding.validation has a
>> bunch of useful IValidator implementations for you to use, or you can
>> write your own.
>> The Data Binding snippets page
>> http://wiki.eclipse.org/JFace_Data_Binding/Snippets has some examples
>> of using validation.
>>
>> Hope this helps,
>> Eric
>>
> Thanks Eric,
> I had just look IValidator, but it not prevent the user to insert a
> wrong char. It signal to user that the string insert is wrong, but not
> prevent to insert that. Example: I've a BigDecimal field as model and a
> SWT Text field as Input, if the user insert "23.2a5" the IValidator
> signal to the ui of the wrong string. But i would that when the user
> insert "a" char the ui prevent to insert it as the snippet
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
> do.
> More, is possible with databinding formating the string? As example
> currency, date, time etc
>
> Thanks again
>
> Stefano
>
Re: DataBinding allow only digit? [message #335006 is a reply to message #335005] Mon, 16 March 2009 07:38 Go to previous messageGo to next message
Stefano Zaccaria is currently offline Stefano ZaccariaFriend
Messages: 48
Registered: July 2009
Member
Thanks Matthew,
you confirm my supposition
Regards

Matthew Hall ha scritto:
> This use case is not supported by DataBinding--you need to filter
> input at the widget. You want to either use an SWT.Verify [1]
> listener on the Text control, or use the FormattedText [2] control
> from Nebula.
>
> Matthew
>
> [1]
> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet19. java
>
> http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet179 .java
>
>
> [2] http://www.eclipse.org/nebula/widgets/formattedtext/formatte dtext.php
>
> Stefano Zaccaria wrote:
>> Eric Rizzo ha scritto:
>>> On 3/13/2009 12:17 PM, Stefano Zaccaria wrote:
>>>> Stefano Zaccaria ha scritto:
>>>>> I am starting to use jface databinding in my app.
>>>>> I would want to put a restrict on field Text for allow only digit,
>>>>> not
>>>>> char.
>>>>> I found a snippet in swt like this:
>>>>> However, I would put this restriction inside IValidator with binding.
>>>>> It is possible?
>>>> The snipper code is:
>>>>
>>>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
>>>>
>>>>
>>>
>>> DataBinding can handle this kind of thing easily, just set an
>>> IValidator on the UpdateValueStrategy that you use when binding your
>>> widget to your model.
>>> The package org.eclipse.core.internal.databinding.validation has a
>>> bunch of useful IValidator implementations for you to use, or you
>>> can write your own.
>>> The Data Binding snippets page
>>> http://wiki.eclipse.org/JFace_Data_Binding/Snippets has some
>>> examples of using validation.
>>>
>>> Hope this helps,
>>> Eric
>>>
>> Thanks Eric,
>> I had just look IValidator, but it not prevent the user to insert a
>> wrong char. It signal to user that the string insert is wrong, but
>> not prevent to insert that. Example: I've a BigDecimal field as model
>> and a SWT Text field as Input, if the user insert "23.2a5" the
>> IValidator signal to the ui of the wrong string. But i would that
>> when the user insert "a" char the ui prevent to insert it as the
>> snippet
>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
>> do.
>> More, is possible with databinding formating the string? As example
>> currency, date, time etc
>>
>> Thanks again
>>
>> Stefano
>>
Re: DataBinding allow only digit? [message #335017 is a reply to message #334995] Mon, 16 March 2009 18:22 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 3/14/2009 5:13 AM, Stefano Zaccaria wrote:
> Eric Rizzo ha scritto:
>> On 3/13/2009 12:17 PM, Stefano Zaccaria wrote:
>>> Stefano Zaccaria ha scritto:
>>>> I am starting to use jface databinding in my app.
>>>> I would want to put a restrict on field Text for allow only digit, not
>>>> char.
>>>> I found a snippet in swt like this:
>>>> However, I would put this restriction inside IValidator with binding.
>>>> It is possible?
>>> The snipper code is:
>>>
>>> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
>>>
>>>
>>
>> DataBinding can handle this kind of thing easily, just set an
>> IValidator on the UpdateValueStrategy that you use when binding your
>> widget to your model.
>> The package org.eclipse.core.internal.databinding.validation has a
>> bunch of useful IValidator implementations for you to use, or you can
>> write your own.
>> The Data Binding snippets page
>> http://wiki.eclipse.org/JFace_Data_Binding/Snippets has some examples
>> of using validation.
>>
>> Hope this helps,
>> Eric
>>
> Thanks Eric,
> I had just look IValidator, but it not prevent the user to insert a
> wrong char. It signal to user that the string insert is wrong, but not
> prevent to insert that. Example: I've a BigDecimal field as model and a
> SWT Text field as Input, if the user insert "23.2a5" the IValidator
> signal to the ui of the wrong string. But i would that when the user
> insert "a" char the ui prevent to insert it as the snippet
> http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet19.java?view=co
> do.

I don't understand - why don't you just use the code from that snippet?
It has nothing to do with data binding, it just works.


> More, is possible with databinding formating the string? As example
> currency, date, time etc

Look at ComputedValue (again, the snippets page has an example).

Eric
Previous Topic:Update fails "No repository found containing..."
Next Topic:Correct strategy for handling page changes in FormEditor
Goto Forum:
  


Current Time: Fri Dec 27 01:36:55 GMT 2024

Powered by FUDForum. Page generated in 0.14698 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top