Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » XWT Validation rules and constructors(How to read in values in a Validation Rule)
XWT Validation rules and constructors [message #638374] Thu, 11 November 2010 04:42 Go to next message
St Clair Clarke is currently offline St Clair ClarkeFriend
Messages: 118
Registered: March 2010
Senior Member
Hello,

I have a simple validation rule for XWT:

import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;

import org.eclipse.e4.xwt.validation.AbstractValidationRule;


public class SuffixValidationRule extends AbstractValidationRule
{

public SuffixValidationRule()
{
super()
} // end ctor SuffixValidationRule


public IStatus validate( Object value )
{
if( !value.matches( /(^[\p{Upper}]|^[\p{Digit}])[\p{Alpha}]*/ ) )
ValidationStatus.error( "Valid characters: Letters, spaces.")
} // end method validate


@Override
public IStatus validateBack( Object value )
{
ValidationStatus.ok()
} // end method validateBack

} // end class SuffixValidationRule



I have tried to pass in objects into the constructor, but XWT does not allows me.

The reason I attempted to pass in objects is that I use OVal framework to validate the model, hence I would like to pass into to the rule the model instance as a parameter being validadted and any other relevant parameters.

Is there a way for me to do this? Any suggestion would be appreciated.

Thanks
Re: XWT Validation rules and constructors [message #639090 is a reply to message #638374] Sun, 14 November 2010 17:10 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 688
Registered: July 2009
Senior Member
Sorry, I don't understand what you want to do and what the problem is with
XWT.

Best regards,
Yves YANG
"St Clair Clarke" <st_clair@flowja.com> wrote in message
news:ibfs0s$mik$1@news.eclipse.org...
> Hello,
>
> I have a simple validation rule for XWT:
>
> import org.eclipse.core.databinding.validation.ValidationStatus;
> import org.eclipse.core.runtime.IStatus;
>
> import org.eclipse.e4.xwt.validation.AbstractValidationRule;
>
>
> public class SuffixValidationRule extends AbstractValidationRule
> {
>
> public SuffixValidationRule()
> {
> super()
> } // end ctor SuffixValidationRule
>
> public IStatus validate( Object value )
> {
> if( !value.matches( /(^[\p{Upper}]|^[\p{Digit}])[\p{Alpha}]*/ ) )
> ValidationStatus.error( "Valid characters: Letters, spaces.")
> } // end method validate
> @Override
> public IStatus validateBack( Object value )
> {
> ValidationStatus.ok()
> } // end method validateBack
> } // end class SuffixValidationRule
>
>
> I have tried to pass in objects into the constructor, but XWT does not
> allows me.
>
> The reason I attempted to pass in objects is that I use OVal framework to
> validate the model, hence I would like to pass into to the rule the model
> instance as a parameter being validadted and any other relevant
> parameters.
>
> Is there a way for me to do this? Any suggestion would be appreciated.
>
> Thanks
Re: XWT Validation rules and constructors [message #639122 is a reply to message #639090] Mon, 15 November 2010 11:30 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I guess he is trying to instantiate a class with a non-zero-arg constructor which (afaik) is not supported by xwt...

class X {
X(Object arg1);
}

Maybe, it is possible to refactor this:

class X {
X ();
void setArg1(Object arg1);
}

and in your xwt:

<Binding>
<Binding.validationRule>
<my:X arg1="myStringToArg1Converter" />
</Binding.validationRule>
</Binding>

Theoretically, this should work Smile

[Updated on: Mon, 15 November 2010 11:31]

Report message to a moderator

Re: XWT Validation rules and constructors [message #639183 is a reply to message #639090] Mon, 15 November 2010 14:46 Go to previous messageGo to next message
St Clair Clarke is currently offline St Clair ClarkeFriend
Messages: 118
Registered: March 2010
Senior Member
Hello Yves,

Sorry I was not clear enough on my request. But the reply by Erdal Karaca explains what I was attempting.

In essence, how can I use a validation rule constructor with an argument. If this is not possible, is there a solution.

Thanks
Re: XWT Validation rules and constructors [message #639378 is a reply to message #639183] Tue, 16 November 2010 10:19 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 688
Registered: July 2009
Senior Member
If you can change the constructor to default one, Erdal Karaca's solution is simple.

Otherwise, you need to define and register your own metaclass to handle the instance creation by implmenting the newInstance() method.

Best regards
Yves YANG
Re: XWT Validation rules and constructors [message #640039 is a reply to message #639378] Thu, 18 November 2010 18:46 Go to previous messageGo to next message
St Clair Clarke is currently offline St Clair ClarkeFriend
Messages: 118
Registered: March 2010
Senior Member
Hello Yves,

Could you post a snippet of your idea please?

Thanks
Re: XWT Validation rules and constructors [message #640073 is a reply to message #640039] Thu, 18 November 2010 22:46 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
So, your model is annotated by 'oval' annotations and you want to validate the whole model?
First, the validation rule does not know of any 'model' as it will just get the value to be validated.
I.e. if you type in text into a text field, that text will be passed to the validation rule to be validated...
There does not seem to be a way to get the data context (or model) inside the validation rule.
Re: XWT Validation rules and constructors [message #641661 is a reply to message #640073] Fri, 26 November 2010 15:03 Go to previous messageGo to next message
St Clair Clarke is currently offline St Clair ClarkeFriend
Messages: 118
Registered: March 2010
Senior Member
Thanks Erdal,

I wonder if the developers would consider something to improve the flexibility of the framework, as for instance giving us the option to pass in objects to be validated, as in my case.

Thanks a million.
Re: XWT Validation rules and constructors [message #642070 is a reply to message #641661] Mon, 29 November 2010 17:52 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANGFriend
Messages: 688
Registered: July 2009
Senior Member
The validation is about the data binding. I think the validation of your
business model should not be part of XWT.

As for XWT, the extensibility and flexibility are our design guidelines.

Best regards
Yves YANG
"St Clair Clarke" <st_clair@flowja.com> wrote in message
news:icoi0v$r5e$1@news.eclipse.org...
> Thanks Erdal,
>
> I wonder if the developers would consider something to improve the
> flexibility of the framework, as for instance giving us the option to pass
> in objects to be validated, as in my case.
>
> Thanks a million.
Re: XWT Validation rules and constructors [message #642817 is a reply to message #642070] Thu, 02 December 2010 19:30 Go to previous message
St Clair Clarke is currently offline St Clair ClarkeFriend
Messages: 118
Registered: March 2010
Senior Member
You are correct Ives. I have stop attempting that route. I realized that my validation will have to conform to XWTs rule.

XWT seems to validate on the UI, my method was validating on the model.

Thanks for our help.
Previous Topic:How to properly center an e4 Application Window?
Next Topic: EPartService cannot find my parts?
Goto Forum:
  


Current Time: Thu Apr 25 05:26:21 GMT 2024

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

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

Back to the top