[Databinding] Nested properties with master-observable [message #1744391] |
Mon, 26 September 2016 13:02 |
Olivier L. Larouche Messages: 4 Registered: September 2016 |
Junior Member |
|
|
I have a data structure with a rover containing a camera which has a initialized(boolean) property. I'm creating a UI to control the robot and it's camera.
I'm using a WritableValue to bind the UI with my data. This writable value is set to the robot. I use this WritableValue to enable/disable buttons that control the rover and for indicators that tell the rover's status.
This is an example of a binding on the rover that works:
IObservableValue observeTextTxtStatusObserveWidget = WidgetProperties.text().observe(txtStatus);
IObservableValue roverInitializedObserveValue = EMFProperties.value(Literals.ROVER__INITIALIZED).observeDetail(roverBinder);
bindingContext.bindValue(observeTextTxtStatusObserveWidget , roverInitializedObserveValue ,
null,
new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE).setConverter(new Converter(Boolean.class, String.class)
{
@Override
public Object convert(Object fromObject) {
return ((Boolean)fromObject).booleanValue() ? "Ready" : "Not ready";
}
}));
My master-observable (WritableValue roverBinder) is set when it is selected in a menu of variables with this method:
public void setRover(Rover rover){
if(roverBinder.getValue == null || rover != roverBinder.getValue()){
roverBinder.setValue(rover);
}
}
What I want to do now, is bind a button which makes the camera take a snapshot. I want this button to be disabled when my camera is not initialized and be enabled when the camera is initialized.
What I have now is (which does not work properly):
IObservableValue observeEnabledTakeSnapshotObserveWidget = WidgetProperties.enabled().observe(btnTakeSnapshot);
IObservableValue roverCameraInitializedObserveValue = EMFProperties.value(FeaturePath.fromList(
(EStructuralFeature) Literals.ROVER__FRONT_CAMERA,
(EStructuralFeature) Literals.CAMERA__INITIALIZED)).observeDetail(roverBinder);
bindingContext.bindValue(observeEnabledTakeSnapshotObserveWidget, roverCameraInitializedObserveValue,
null,
new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE).setConverter(new Converter(Boolean.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
if(fromObject != null){
return (Boolean) fromObject;
}else{
return false;
}
}
}));
I'm using the converter here to help me debug
This code only updates the button when I close my view and reopen it or change the selected rover and go back to this rover. This is because when I reload my view or change to another rover, setRover() is called and since now my camera is initialized, the button is enabled.
I think the problem is that my binder only updates the UI on the bindings that are directly on the Rover's class and not on the Camera.
My camera is initialized when my rover is initialised (rover.init() calls camera.init()).
Any ideas on how I can enable my button with bindings?
Thank you.
Olivier
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04428 seconds