简体   繁体   中英

Eclipse RCP Data Binding with WritableValue - Int vs. Integer

I'm using Eclipse RCP 4 and I've little problem with my WritableValue :

I use the WritableValue in a data binding (see below) and whenever I set the value of my WritableValue with an object that contains an int attribute (part of the binding), then I receive a ClassCastException :

Caused by: java.lang.ClassCastException: Cannot cast java.lang.Integer to int
 at java.lang.Class.cast(Unknown Source)
 at org.eclipse.core.internal.databinding.beans.PojoValueProperty.doGetValue(PojoValueProperty.java:62)
 at org.eclipse.core.databinding.property.value.ValueProperty.getValue(ValueProperty.java:60)
 at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.notifyIfChanged(SimplePropertyObservableValue.java:119)
 at org.eclipse.core.internal.databinding.property.value.SimplePropertyObservableValue.doGetValue(SimplePropertyObservableValue.java:101)
 at org.eclipse.core.databinding.observable.value.AbstractObservableValue.getValue(AbstractObservableValue.java:81)
 at org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableValue.doGetValue(DetailObservableValue.java:150)
 at org.eclipse.core.internal.databinding.observable.masterdetail.DetailObservableValue$2.handleValueChange(DetailObservableValue.java:96)
 at org.eclipse.core.databinding.observable.value.ValueChangeEvent.dispatch(ValueChangeEvent.java:71)
 at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:127)
 at org.eclipse.core.databinding.observable.value.AbstractObservableValue.fireValueChange(AbstractObservableValue.java:76)
 at org.eclipse.core.databinding.observable.value.WritableValue.doSetValue(WritableValue.java:94)
 at org.eclipse.core.databinding.observable.value.AbstractObservableValue.setValue(AbstractObservableValue.java:60)

This is my binding:

IObservableValue<?> model2 = PojoProperties.value(PlantBE.class,
            "maxAge").observeDetail(getModel().getWritableValue());
ISWTObservableValue<String> view2 = WidgetProperties.textText(SWT.Modify)
            .observe(getDialogView().getTxtMaxAge().getText());
this.getDataBindingContext().bindValue(model2, view2);

The Entity (PlantBE) looks like that:

public class PlantBE implements Serializable {
private int maxAge;

public int getMaxAge() {
    return maxAge;
}

public void setMaxAge(int maxAge) {
    this.maxAge = maxAge;
}
}

It would be great to get some help on that. Maybe you've an idea what the issue could be.

Thanks and best regards

What does the getModel().getWritableValue() return? Why wouldn't you do it like this:

IObservableValue model= BeanProperties.value(PlantBE.class,"maxAge").observe(model);
IObservableValue view = WidgetProperties.text(SWT.Modify).observe(getDialogView().getTxtMaxAge());
this.getDataBindingContext().bindValue(model, view);

ALso, take a look at this holy Eclipse RCP grail, aka Vogella's tutorial , it should help you a lot understanding this whole data binding mess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM