Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » [DataBinding] CRUD best practice
[DataBinding] CRUD best practice [message #319921] Wed, 05 September 2007 16:06 Go to next message
Eclipse UserFriend
I am converting our RIA CRUD SWT application to Databindings and have a
best practice question that was not covered in the Webinar..

The most basic CRUD operation is enter a value in a text field and then
go to the database and see if the row exists and display it. If it is not
then pop up a warning Dialog saying Not found.

My first pass looked like ..

UpdateValueStrategy uvs = new UpdateValueStrategy();
uvs.setBeforeSetValidator(new IValidator()
{
public IStatus validate(Object value)
{
if(((String)value).length()==0)
{
return(ValidationStatus.CANCEL_STATUS);
}
if(findValue((String)value))
{
dbc.updateTargets();
return(ValidationStatus.CANCEL_STATUS);
}
return(ValidationStatus.error("Row not found"));
});


How do I bind the return status to a Dialog based on severity?
or am I way off base here? Any suggestions or pointers to links/examples
would be appreciated.
Re: [DataBinding] CRUD best practice [message #319930 is a reply to message #319921] Wed, 05 September 2007 23:24 Go to previous messageGo to next message
Eclipse UserFriend
Dave Smith wrote:
> I am converting our RIA CRUD SWT application to Databindings and have a
> best practice question that was not covered in the Webinar..
>
> The most basic CRUD operation is enter a value in a text field and then
> go to the database and see if the row exists and display it. If it is not
> then pop up a warning Dialog saying Not found.
>
> My first pass looked like ..
>
> UpdateValueStrategy uvs = new UpdateValueStrategy();
> uvs.setBeforeSetValidator(new IValidator()
> {
> public IStatus validate(Object value)
> {
> if(((String)value).length()==0)
> {
> return(ValidationStatus.CANCEL_STATUS);
> }
> if(findValue((String)value))
> {
> dbc.updateTargets();
> return(ValidationStatus.CANCEL_STATUS);
> }
> return(ValidationStatus.error("Row not found"));
> });
>
>
> How do I bind the return status to a Dialog based on severity?
> or am I way off base here? Any suggestions or pointers to links/examples
> would be appreciated.
>
>

You can observe changes in the the validation status either with
Binding.getValidationStatus() (it's an observable) or via the validation
statuses provided from DataBindingContext.getValidationStatusMap() that
the Binding is being managed by. When the status changes you can then
react to the severity.

There are other ways to handle this as well:
1. Don't put this in a validator. You could update your model and the
model could search and have a isNoResultsFound() value that when changes
the dialog could be displayed. To me this is a little more testable
from a model perspective as the UI could decide what to do as a result
and you don't have to worry about dismissing a dialog in a test.
2. Don't use JDB for this. You could just hook the control, perform the
search, and display the dialog in SWT code. If this value isn't a part
of your model, and in many cases it won't be, I would think this would
be the most straightforward approach.

-brad
Re: [DataBinding] CRUD best practice [message #319931 is a reply to message #319921] Wed, 05 September 2007 23:24 Go to previous message
Eclipse UserFriend
Dave Smith wrote:
> I am converting our RIA CRUD SWT application to Databindings and have a
> best practice question that was not covered in the Webinar..
>
> The most basic CRUD operation is enter a value in a text field and then
> go to the database and see if the row exists and display it. If it is not
> then pop up a warning Dialog saying Not found.
>
> My first pass looked like ..
>
> UpdateValueStrategy uvs = new UpdateValueStrategy();
> uvs.setBeforeSetValidator(new IValidator()
> {
> public IStatus validate(Object value)
> {
> if(((String)value).length()==0)
> {
> return(ValidationStatus.CANCEL_STATUS);
> }
> if(findValue((String)value))
> {
> dbc.updateTargets();
> return(ValidationStatus.CANCEL_STATUS);
> }
> return(ValidationStatus.error("Row not found"));
> });
>
>
> How do I bind the return status to a Dialog based on severity?
> or am I way off base here? Any suggestions or pointers to links/examples
> would be appreciated.
>
>

You can observe changes in the the validation status either with
Binding.getValidationStatus() (it's an observable) or via the validation
statuses provided from DataBindingContext.getValidationStatusMap() that
the Binding is being managed by. When the status changes you can then
react to the severity.

There are other ways to handle this as well:
1. Don't put this in a validator. You could update your model and the
model could search and have a isNoResultsFound() value that when changes
the dialog could be displayed. To me this is a little more testable
from a model perspective as the UI could decide what to do as a result
and you don't have to worry about dismissing a dialog in a test.
2. Don't use JDB for this. You could just hook the control, perform the
search, and display the dialog in SWT code. If this value isn't a part
of your model, and in many cases it won't be, I would think this would
be the most straightforward approach.

-brad
Previous Topic:Command Handlers and the Current Selection
Next Topic:problems when using embedded jars
Goto Forum:
  


Current Time: Fri Jul 18 04:22:27 EDT 2025

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

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

Back to the top