Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Issue about databinding validation and cursor(the cursor moves to the start of input text every time validation returns OK status)
Issue about databinding validation and cursor [message #530140] Wed, 28 April 2010 15:58 Go to next message
Carusyte Missing name is currently offline Carusyte Missing nameFriend
Messages: 27
Registered: July 2009
Junior Member
I am binding a text control with a string property of a model, if things go right (i.e when the validation returns error status), the cursor moves naturally as I type in the text control, and the wizard updates messages; but if I type in correct content, the cursor would jump to the start of input which is very annoying. I can't figure out what's wrong in the code:
// here's the binding code
dbc = new DataBindingContext();
IObservableValue ovView = SWTObservables.observeText(filePath_txt,
					SWT.Modify);
IObservableValue ovModel = BeansObservables.observeValue(
					getModel(), "filePath");

UpdateValueStrategy strategy = getUpdateValueStrategy();
binding = dbc.bindValue(ovView, ovModel, strategy, null);
WizardPageSupport wps = WizardPageSupport.create(this, dbc);
....
// get the strategy
private UpdateValueStrategy getUpdateValueStrategy() {
			return new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE)
					.setBeforeSetValidator(new FileValidator());
}

class FileValidator implements IValidator {
...
// roughly speaking, it validates whether the file path entered in filePath_txt control is right, and this part of code works properly
@Override
public IStatus validate(Object value) {
...
}
}


Any kind of help would be appreciated!
Re: Issue about databinding validation and cursor [message #530242 is a reply to message #530140] Thu, 29 April 2010 04:12 Go to previous messageGo to next message
Carusyte Missing name is currently offline Carusyte Missing nameFriend
Messages: 27
Registered: July 2009
Junior Member
Problem solved. It turns out that I unintentionally made a "double-bind" with the model and the target. Here is the detail:

I wish the user can restart the wizard without closing and re-opening it, so I write a "reset" method for each page and it will be called once the starting page is visited. Carelessly coded, the reset() is called when the wizard is created, and the binding is re-created, which I believe causing this weird behavior.
// before the fix
private void reset() {
	getModel().setFilePath(null);
	dbc.updateTargets();
	dbc.removeBinding(binding);
	doBinding();       // creating the dbc
}

// after the fix, appears that I just have to reset the model value and call dbc.updateTargets() in order to reset the wizard validation state
private void reset() {
	getModel().setFilePath(null);
	dbc.updateTargets();
	// dbc.removeBinding(binding);
	// dbc.addBinding(binding);
        // doBinding();       // creating the dbc
}


Thank you guys for reading. I want to digress the topic a little bit: the idea of letting user to jump back to the starting page and walk through a similar wizard navigation may not be good, perhaps a better idea is to re-open it in sacrifice of resources reallocation...is there any better way to achieve this?
Re: Issue about databinding validation and cursor [message #530246 is a reply to message #530140] Thu, 29 April 2010 04:54 Go to previous messageGo to next message
Carusyte Missing name is currently offline Carusyte Missing nameFriend
Messages: 27
Registered: July 2009
Junior Member
Seems that in order to reset the wizard page validation status properly, I have to code reset() this way instead:
private void reset() {
	getModel().setFilePath(null);   //reset model value
	binding.init(dbc);  // reset validation status
	wps.dispose();  // recreate the wizard page support with dbc
	wps = WizardPageSupport.create(BatchFileSelectionPage.this, dbc);
}

Sorry for the confusion...
Re: Issue about databinding validation and cursor [message #1368313 is a reply to message #530140] Tue, 20 May 2014 04:41 Go to previous message
Kai Mechel is currently offline Kai MechelFriend
Messages: 6
Registered: July 2009
Junior Member
Thanks for answering your own question Smile
That helped me a lot - I had the same problem and you saved me a lot of time figuring out the problem by myself.

Thank you!
Kai
--

Previous Topic:Limit the number of lines in Console in RCP
Next Topic:pulldown toolbar of view over the border
Goto Forum:
  


Current Time: Fri Apr 26 02:32:51 GMT 2024

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

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

Back to the top