Reputation: 305
I have RCP application, and i have a command in it, that launches a wizard of some entity (edit wizard, that shows all fields of entity, and user can change it and finish wizard to save this entity). I'm using JFace data binding to bind entity's field to swt Texts and Combos.
That command have handler (that contains wizard call), and this handler is bind to some button and all works fine.
Then i need to bind this command to some Key combination (Ctrl+E for example). I'm using org.eclipse.ui.bindings extention for it:
<key
commandId="com.project.command"
contextId="com.project.view.context"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+E">
</key>
"com.project.view.context" is made by me to bind to same key combination in 2 different views and it's looks ok (and activates different commands in these 2 views).
But when i open my wizard through this key combination there is a problem:
SWT Text fields dont binds to Integer fields of entity. With String fields it's all ok, and they're binding fine. But Integer fields dont (There are just empty space in it).
What i've tried:
I debugged my wizard and wizard page, and all time entity state is fine (their Integer fields is correct and not 0 or null)
Tried to write Integer to String Convertors for JFace binding. Didnt help.
I tried disable JFace binding for this fields, and seting Text field value manual:
swtTextField.setText(entity.getIntegerField().toString());
But this also didnt work! Looks like it's not JFace binding problem, but SWT text problem? Debuggin this situation :
entity.getIntegerField().toString() = "1234" before and after "setText" swtTextField.getText = "" before and after "setText"
(And when i run this debug not from Key combination-command call, all looks good and swtTextField.getText = "1234" after "setText")
Tried to change context of binding extention to default ("org.eclipse.ui.contexts.window") that didnt helped too.
So, summing up, all works fine, when i calling my command through button (or context menu). But there is a problem with Integer->Text fields (String fields works fine) when i calling my command through key combination binding extention.
Have any ideas what's wrong with it?
Added: I found out, that the problem is in key combination. When the key combination contains not-english key symbol (Ctrl+non-english-key my language key symbol, cause our application uses not-english key combinations) then the problem appears: SWT Text doesnt accept Integer values. When the key combinations is english (Ctrl+english-key) - all is ok.
All other commands (without SWT Text fields) works fine too, and they are binded to Ctrl+non-english-key combinations too...
That is very strange and I still dont understand, why that hanneps...
Upvotes: 4
Views: 1460
Reputation: 30528
I have bumped into this problem several months ago. The problem was with JFace Data Bindings. What helped:
org.eclipse.core.databinding.observable.value.IObservableValue
for observing your Text
. So you can write code like this: IObservableValue yourTextObserveTextObserveWidget = SWTObservables.observeText(yourText, SWT.Modify);
org.eclipse.core.databinding.beans.BeansObservables
to observe the value of your entity so you can write code like this: BeansObservables.observeValue(yourModel, "yourInt");
org.eclipse.core.databinding.DataBindingContext
and bind your IObservableValue
like this: bindingContext.bindValue(yourTextObserveTextObserveWidget, yourModelTemplateObserveValue, null, null)
So the final code for binding your model to a Text
will be like this:
DataBindingContext bindingContext = new DataBindingContext();
IObservableValue yourTextObserveTextObserveWidget = SWTObservables.observeText(yourText, SWT.Modify);
IObservableValue yourModelTemplateObserveValue = BeansObservables.observeValue(yourModel, "yourInt");
bindingContext.bindValue(yourTextObserveWidget, yourModelTemplateObserveValue, null, null);
Please check the documentation of the data binding if you have any further questions. This is working in my program with String
, boolean
and Integer
types. I haven't tested anythig else though.
Upvotes: 1