Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Databinding - Writable and the opposite path.
Databinding - Writable and the opposite path. [message #689103] Sun, 26 June 2011 20:17 Go to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Hi,

I am succesfully using a WritableValue to bind between UI widgets (i.e.
various Radio buttons, whereby the selected button will be reflected in
the WritableValue), and a model object in an indirect manner. This
happens by registering a IValueChangeListener on the UI Widgets, which
aggregates the value changes from several UI widgets and update the
WritableValue. So far so good.

I am however struggling to achieve the opposite, which is updating the
UI widgets from the model value. The WritableValue doesn't seem to sync
with the model value, and perhaps it shoudn't (It's a Writable after
all), but what would be the pattern for updating the UI widgets?

Do I need another binding with a change listener on the model
IValueProperty? (and in similar fashion update the UI widgets through a
value change listener on the property?).


Thank You, Christophe
Re: Databinding - Writable and the opposite path. [message #690919 is a reply to message #689103] Thu, 30 June 2011 12:21 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
Anyone please?

On 26-06-11 22:17, Christophe Bouhier wrote:
> Hi,
>
> I am succesfully using a WritableValue to bind between UI widgets (i.e.
> various Radio buttons, whereby the selected button will be reflected in
> the WritableValue), and a model object in an indirect manner. This
> happens by registering a IValueChangeListener on the UI Widgets, which
> aggregates the value changes from several UI widgets and update the
> WritableValue. So far so good.
>
> I am however struggling to achieve the opposite, which is updating the
> UI widgets from the model value. The WritableValue doesn't seem to sync
> with the model value, and perhaps it shoudn't (It's a Writable after
> all), but what would be the pattern for updating the UI widgets?
>
> Do I need another binding with a change listener on the model
> IValueProperty? (and in similar fashion update the UI widgets through a
> value change listener on the property?).
>
>
> Thank You, Christophe
>
>
Re: Databinding - Writable and the opposite path. [message #691103 is a reply to message #690919] Thu, 30 June 2011 17:55 Go to previous messageGo to next message
Eclipse user Chennai is currently offline Eclipse user ChennaiFriend
Messages: 15
Registered: May 2011
Junior Member
Kindly paste your code here, for the better understanding of your problem..
Re: Databinding - Writable and the opposite path. [message #691144 is a reply to message #691103] Thu, 30 June 2011 19:52 Go to previous message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 30-06-11 19:56, Barani Kumar wrote:
> Kindly paste your code here, for the better understanding of your problem..
Hi,

Below is the part which syncs the various UI widgets to a Writable.
The UI widgets are 4 radio buttons, depending on the which one is
selected an object is created with some settings. This works fine.
My question is how do I achieve the opposite? (How do I set the radio
buttons from the Object received).


Thanks / Christophe


// The writable.
IObservableValue dataKindWritableValue = new WritableValue();
DatakindAggregate aggregate = new DatakindAggregate( dataKindWritableValue);

//4 observables which aggregate through a value change listener.
IObservableValue identifierObservable =
SWTObservables.observeSelection(btnIdentifier);
identifierObservable.addValueChangeListener(aggregate);

IObservableValue timestampObservable =
SWTObservables.observeSelection(btnTimestamp);
timestampObservable.addValueChangeListener(aggregate);

IObservableValue metricvaluepObservable = SWTObservables
..observeSelection(btnMetricValue);
metricvaluepObservable.addValueChangeListener(aggregate);

IObservableValue periodObservable = SWTObservables
..observeSelection(this.btnPeriod);
periodObservable.addValueChangeListener(aggregate);


// Model Observable
IEMFValueProperty datatypeValueProperty = EMFProperties
.value(MetricsPackage.Literals.MAPPING_COLUMN__DATA_TYPE);

IObservableValue dataTypeObservable =
datatypeValueProperty.observe(mxlsColumn);



// Binding
context.bindValue(dataKindWritableValue,
dataTypeObservable);


// Change listener, sets the the dataKindObservable.

private class DatakindAggregate implements IValueChangeListener,
IValidator {

private IObservableValue dataKindObservable;

boolean timestamp = false;
boolean identifier = false;
boolean value = false;
boolean period = false;
DatakindAggregate(IObservableValue dataKindObservable) {
this.dataKindObservable = dataKindObservable;
}

/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.databinding.observable.value.IValueChangeListener
* #handleValueChange
* (org.eclipse.core.databinding.observable.value.ValueChangeEvent)
*/
public void handleValueChange(ValueChangeEvent event) {
System.out.println(event.getObservable());

Object newValue = event.diff.getNewValue();

if (event.getObservable() instanceof ISWTObservableValue) {
Control control = (Control) ((ISWTObservableValue) event
.getObservable()).getWidget();
System.out.println(control);
if (control.equals(btnIdentifier)) {
this.identifier = (Boolean) newValue;
}
if (control.equals(btnTimestamp)) {
this.timestamp = (Boolean) newValue;
}
if (control.equals(btnMetricValue)) {
this.value = (Boolean) newValue;
}
if (control.equals(btnPeriod)) {
this.period = (Boolean) newValue;
}

}
allSet();
}


// Set the value of the writable, using the options set by creating a
new object.

private boolean allSet() {
// Create the DataKindObject, actually only on save.
System.out.println("I T V P=" + identifier + timestamp + value + period);
DataKind dk = null;
if(period){
ValueDataKind vdk = MetricsFactory.eINSTANCE.createValueDataKind();
vdk.setValueKind(ValueKindType.PERIOD);
// Set more options.
dk = vdk;
}
if(identifier){
IdentifierDataKind idk =
MetricsFactory.eINSTANCE.createIdentifierDataKind();
// Set more options.
//idk.setObjectKind(value)
dk = idk;
}
if(value){
ValueDataKind vdk = MetricsFactory.eINSTANCE.createValueDataKind();
vdk.setValueKind(ValueKindType.METRIC);
//vdk.setMetricRef(value)
dk = vdk;
}
if(timestamp){
ValueDataKind vdk = MetricsFactory.eINSTANCE.createValueDataKind();
vdk.setValueKind(ValueKindType.DATETIME);
dk = vdk;
}

dataKindObservable.setValue(dk);
return true;
}
}
Previous Topic:Databinging - Writable and the opposite path.
Next Topic:Using EditingSupport.setValue(Object element, Object value) with strings.
Goto Forum:
  


Current Time: Thu Apr 25 12:05:58 GMT 2024

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

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

Back to the top