Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Validating a custom field
Validating a custom field [message #1060593] Mon, 27 May 2013 04:27 Go to next message
Urs Beeli is currently offline Urs Beeli
Messages: 315
Registered: October 2012
Location: Bern, Switzerland
Senior Member
I've created a rather complex custom field that lets me select dates using various methods. I now have the requirement that depending on the situation I need to define a minimum and maximum number of days that must be selected.

I was hoping to add some way of checking the currently selected number of days in a method like execValidateValue() after each change of selection and when clicking the ok button.

Is there an easy way to add this functionality without having to implement all of IValueField (which would be massive overkill in my case)? Ideally I would like the functionality to be caught by the form without having to add extra code to the form.
Re: Validating a custom field [message #1060597 is a reply to message #1060593] Mon, 27 May 2013 04:52 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan Motsch
Messages: 100
Registered: March 2010
Senior Member
What is the base type (super class) of your custom field?
May you share with us some source code? We only need the relevant parts,
cut out the other parts.
Re: Validating a custom field [message #1060624 is a reply to message #1060597] Mon, 27 May 2013 07:22 Go to previous messageGo to next message
Urs Beeli is currently offline Urs Beeli
Messages: 315
Registered: October 2012
Location: Bern, Switzerland
Senior Member
The class definition of my custom field looks as follows:
public abstract class AbstractTagesfilterField extends AbstractCustomField implements ITagesfilterField {

where ITagesfilterField defines a few setters/getters to access the selected days.

However, I think the solution to my problem is easier than I had anticipated. The only "loss" of my solution is that the validation is not executed automatically, but needs to be triggered explicitely in my field.

I've added a method validateValue() which evaluates the min/max limites (defined as configuration properties) and the currently selected number of days. Depending on the outcome it just calls clearErrorStatus()/setErrorStatus() on the field. This is enough to be taken into account when I press the OK button on the form, the only thing that remains is to also use this information to graphically indicate the error status on the control itself. To handle dynamic changes, I am calling validateValue() in my UIFacade whenever a user interaction (mouse click) effects a change in selected days.

Below you see the result of all this (left side: invalid selection, right side: valid selection):
index.php/fa/15059/0/

  • Attachment: kalender.png
    (Size: 150.17KB, Downloaded 137 times)

[Updated on: Mon, 27 May 2013 07:23]

Report message to a moderator

Re: Validating a custom field [message #1060726 is a reply to message #1060624] Tue, 28 May 2013 05:08 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan Motsch
Messages: 100
Registered: March 2010
Senior Member
For me it looks like a good solution using the toolbox functions of the field. Using the validate and errorStatus is in fact designed to be used for such cases.

You might also take a look at #checkEmpty and #isSaveNeeded/touch/markSaved to decide if the field "contains information" respectively should be saved on "Ok".
Re: Validating a custom field [message #1060753 is a reply to message #1060726] Tue, 28 May 2013 07:13 Go to previous message
Urs Beeli is currently offline Urs Beeli
Messages: 315
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Thanks for your input, I am already using isSaveNeeded et al, but did not know about checkEmpty, I'll have a look at that.
Previous Topic:Error when using External plugin
Next Topic:Using the Accessive library in the unit tests.
Goto Forum:
  


Current Time: Tue Jul 22 15:48:23 EDT 2014

Powered by FUDForum. Page generated in 0.01957 seconds