Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » XWT ValidationRule question
XWT ValidationRule question [message #986942] Thu, 22 November 2012 13:03 Go to next message
Jürgen Weinberger is currently offline Jürgen WeinbergerFriend
Messages: 42
Registered: August 2012
Member
Hello!

First of all, thanks for all the help so far.
But now i ran into following problem and i think it is more of the conceptual kind Smile.

I have a gui with a lot of controlls and some of them must be specified by the user. To show him which one are mandatory they are marked with a different background color. As soon as he fills them they get back to their normal state. This all works great via xwt and is done by the bindingcontexts, validationrules and some converters. (don't need anything additional).

Now my problem is that i have two Textboxes where the user has to fill at least one of them. So if nothing is in the textboxes both are marked as mandatory and if one gets filled both should get to their normal state.

How could i manage this? I think with the jface databinding i would solve that by using a Multivalidator (only a guess because of some googeling). Is there something in xwt like this?

Any help or hint would be appreciated.
Thanks to all in advanced
and best regards weinma

Re: XWT ValidationRule question [message #987009 is a reply to message #986942] Thu, 22 November 2012 20:19 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
Not tried, but the following should work...

This would be your converter (pseudo code):
class YourConverter implements IValueConverter {
  String text1
  String text2

  Object convert(Object value) {
    return text1 is empty and text2 is empty ? RED_COLOR : null;
  }

  ... getters/setters for text1 and text2
}


Your XWT:
<Composite.Resources>
	<y:YourConverter x:key="sharedConverter" text1="{Binding elementName=text1, path=text, updateSourceTrigger=PropertyChanged}"
		text2="{Binding elementName=text2, path=text, updateSourceTrigger=PropertyChanged}"/>
</Composite.Resources>

<text x:name="text1" background="{Binding converter={StaticResource sharedConverter}}" />
<text x:name="text2" background="{Binding converter={StaticResource sharedConverter}}"/>



The key idea is to "inject" both text values (text1/text2) into the converter/validator.


Jürgen Weinberger wrote on Thu, 22 November 2012 14:03
Hello!

First of all, thanks for all the help so far.
But now i ran into following problem and i think it is more of the conceptual kind Smile.

I have a gui with a lot of controlls and some of them must be specified by the user. To show him which one are mandatory they are marked with a different background color. As soon as he fills them they get back to their normal state. This all works great via xwt and is done by the bindingcontexts, validationrules and some converters. (don't need anything additional).

Now my problem is that i have two Textboxes where the user has to fill at least one of them. So if nothing is in the textboxes both are marked as mandatory and if one gets filled both should get to their normal state.

How could i manage this? I think with the jface databinding i would solve that by using a Multivalidator (only a guess because of some googeling). Is there something in xwt like this?

Any help or hint would be appreciated.
Thanks to all in advanced
and best regards weinma


Re: XWT ValidationRule question [message #987547 is a reply to message #987009] Tue, 27 November 2012 06:12 Go to previous messageGo to next message
Jürgen Weinberger is currently offline Jürgen WeinbergerFriend
Messages: 42
Registered: August 2012
Member
Hey! Thanks for the tip.
I built the "converter" now the way you suggested. The only difference i made is that i pluged the statuses of the bindingcontexts into that converter. By the way in my case its not a converter, it is a custom widget inherited from a composite. (But it doesn't matter)

My only thought was that the ValidationRules do the validation and that the Widget only shows the status. Now my widget is a little more inteligence
and links the two bindingcontext statuses with a logical or (So that only one rule must be valid). I thought it would be nicer if a rule would do this but for now i can live with that solution:

<StatusLabel>
<StatusLabel.status>
<Binding source="{StaticResource context1}" path="status"/>
</StatusLabel.status>
<StatusLabel.secondStatus>
<Binding source="{StaticResource context2}" path="status"/>
</StatusLabel.secondStatus>
</StatusLabel>


public class StatusLabel extends Composite {
..

public void setStatus(IStatus) {
..
}

public IStatus getStatus() {
..
}

public void setSecondStatus(IStatus) {
..
}

public IStatus getSecondStatus() {
..
}

}


And there comes another question Smile
I think it would be nicer if it was possible to plug an array or List<> of IStatus into that Composite/Converter something like that:

<StatusLabel>
<StatusLabel.statuses>
<Binding source="{StaticResource context1}" path="status"/>
<Binding source="{StaticResource context2}" path="status"/>
<Binding source="{StaticResource context3}" path="status"/>
...
</StatusLabel.statuses>
</StatusLabel>


public class StatusLabel extends Composite {
..

public void setStatuses(IStatus[] statuses) {
..
}

public IStatus[] getStatuses() {
..
}

}


Is something like that possible how would i have to declare this in the xml and java code?

Thanks a lot for the hint again!
best regards weinma

[Updated on: Tue, 27 November 2012 06:13]

Report message to a moderator

Re: XWT ValidationRule question [message #987886 is a reply to message #987547] Wed, 28 November 2012 14:36 Go to previous message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I think this will (try to) provide an array of Bindings to StatusLabel.setStatuses().
I.e. at that point, the Bindings will not be evaluated but taken as objects.

You could try to register an XWT converter (XWT.registerConverter()) that handles the Binding to Object conversion (i.e. in your converter you would just return Binding.getValue()).

Jürgen Weinberger wrote on Tue, 27 November 2012 07:12
Hey! Thanks for the tip.
I built the "converter" now the way you suggested. The only difference i made is that i pluged the statuses of the bindingcontexts into that converter. By the way in my case its not a converter, it is a custom widget inherited from a composite. (But it doesn't matter)

My only thought was that the ValidationRules do the validation and that the Widget only shows the status. Now my widget is a little more inteligence
and links the two bindingcontext statuses with a logical or (So that only one rule must be valid). I thought it would be nicer if a rule would do this but for now i can live with that solution:

<StatusLabel>
<StatusLabel.status>
<Binding source="{StaticResource context1}" path="status"/>
</StatusLabel.status>
<StatusLabel.secondStatus>
<Binding source="{StaticResource context2}" path="status"/>
</StatusLabel.secondStatus>
</StatusLabel>


public class StatusLabel extends Composite {
..

public void setStatus(IStatus) {
..
}

public IStatus getStatus() {
..
}

public void setSecondStatus(IStatus) {
..
}

public IStatus getSecondStatus() {
..
}

}


And there comes another question Smile
I think it would be nicer if it was possible to plug an array or List<> of IStatus into that Composite/Converter something like that:

<StatusLabel>
<StatusLabel.statuses>
<Binding source="{StaticResource context1}" path="status"/>
<Binding source="{StaticResource context2}" path="status"/>
<Binding source="{StaticResource context3}" path="status"/>
...
</StatusLabel.statuses>
</StatusLabel>


public class StatusLabel extends Composite {
..

public void setStatuses(IStatus[] statuses) {
..
}

public IStatus[] getStatuses() {
..
}

}


Is something like that possible how would i have to declare this in the xml and java code?

Thanks a lot for the hint again!
best regards weinma

Previous Topic:At what Point to insert a singleton class into the model?
Next Topic:dynamically add part to partStack
Goto Forum:
  


Current Time: Tue Apr 16 17:24:52 GMT 2024

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

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

Back to the top