Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Databinding] Nested properties with master-observable
[Databinding] Nested properties with master-observable [message #1744391] Mon, 26 September 2016 13:02 Go to next message
Olivier L. Larouche is currently offline Olivier L. LaroucheFriend
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
Re: [Databinding] Nested properties with master-observable [message #1744489 is a reply to message #1744391] Tue, 27 September 2016 12:20 Go to previous messageGo to next message
Olivier L. Larouche is currently offline Olivier L. LaroucheFriend
Messages: 4
Registered: September 2016
Junior Member
Another way to put it is like this:
http://i.imgur.com/KwLoYfu.png

Is there a way to bind the value of a contained class. In a case where, when the instantiation of the container is made, the contained class is null and only created afterwards?

I have another similar case in my code where my rover has a position and this position is initialized in the constructor of the rover. This way, when my writableValue is updated, position is not null and the binding works.
I don't want to do the same thing with my camera, since it needs to be initialized with another method and not in the constructor of the rover. Eventually, even the initialization of the position could change.

Is there a pattern I can apply here?

Olivier

[Updated on: Tue, 27 September 2016 12:31]

Report message to a moderator

Re: [Databinding] Nested properties with master-observable [message #1744735 is a reply to message #1744391] Thu, 29 September 2016 18:17 Go to previous message
Olivier L. Larouche is currently offline Olivier L. LaroucheFriend
Messages: 4
Registered: September 2016
Junior Member
Nevermind, I found my problem.

I was not calling the setter when I was instantiating my camera in my simulator. Rookie mistake Embarrassed

I was doing: frontCamera = new Camera()
I needed to do: this.setFrontCamera(new Camera())
Previous Topic:Class cast exception when saving to XML
Next Topic:Unordered list of children
Goto Forum:
  


Current Time: Tue Jun 22 20:49:19 GMT 2021

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

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

Back to the top