Java – SWT text field setting and RCP command bound to key

I have an RCP application. I have a command that starts an entity Wizard (the edit wizard displays all fields of the entity, and the user can change it and complete the wizard to save the entity) I'm using Jface data binding to bind the entity's fields to SWT texts and combos

The command has a handler (including a wizard call), and the handler is bound to a button and everything is OK

Then I need to bind this command to a key combination (for example, Ctrl E) I'm using org eclipse. ui. Bindings extension:

<key
commandId="com.project.command"
contextId="com.project.view.context"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+E">
</key>

"Com. Project. View. Context" is bound to the same key combination in two different views. It looks ok (and activates different commands in these two views)

But when I open my wizard through this key combination, there is a problem:

SWT text fields are not bound to entity integer fields Using string fields, everything is normal and their binding is good But the integer field is not (there are only spaces in it)

What I've tried:

>I debugged my wizard and wizard pages, and all time entity states are fine (their integer fields are correct, not 0 or null) > I tried to write integers to the string converter for Jface binding No help. > I tried to disable Jface binding for this field and set the text field value book:

swtTextField.setText(entity.getIntegerField().toString());

But it's no use! It seems that this is not a Jface binding problem, but is there a problem with the SWT text? Debuggin this case:

entity. getIntegerField(). Tostring() = "1234" before and after "settext" swttextfield getText =“”

(when I call and run this debugging from the key combination command, everything looks good, and swttextfield.gettext = "1234" > after "settext" tries to change the context of the binding extension to the default value ("org. Eclipse. UI. Contexts. Window")

So, to sum up, when I call my command through a button (or context menu), everything is normal However, when I call my command through the key combination binding extension, there is a problem with the integer - > text field (string field works normally)

Any ideas?

I find that the problem is the key combination When the key combination contains non English key symbols (ctrl non English key is my language key symbol, which causes our application to use non English key combinations), the problem occurs: SWT text does not accept integer values When the key combination is Ctrl English key – everything is OK

All other commands (without SWT text fields) work as well, and they are also bound to Ctrl non English key combinations

It's strange. I still don't understand why that hanneps

Solution

I had this problem a few months ago The problem is Jface data bindings How does it help:

>Use org eclipse. core. databinding. observable. value. Iobserveablevalue observe text So you can write the following code: iobservervablevalue yourtextobservetextobservewidget = swtobservables observeText(yourText,SWT.Modify); > Use org eclipse. core. databinding. beans. Beansobservables to observe the value of the entity, so you can write the following code: beansobservables observeValue(yourModel,“yourInt”); > Use org eclipse. core. databinding. Databindingcontext and bind your iobservervablevalue as follows: bindingcontext bindValue(yourTextObserveTextObserveWidget,yourModelTemplateObserveValue,null,null)

Therefore, the final code to bind the model to text will be as follows:

DataBindingContext bindingContext = new DataBindingContext();
IObservableValue yourTextObserveTextObserveWidget = SWTObservables.observeText(yourText,SWT.Modify);
IObservableValue yourModelTemplateObserveValue = BeansObservables.observeValue(yourModel,"yourInt");
bindingContext.bindValue(yourTextObserveWidget,null);

If you have any other questions, please check the data binding documentation This uses string, Boolean and integer types in my program I haven't tested anything else

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>