Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF databinding] set binding problem
[EMF databinding] set binding problem [message #521644] Thu, 18 March 2010 06:58 Go to next message
Eclipse UserFriend
Originally posted by: Thomas.Kowatsch.ruag.com

Hi.

I have a databinding problem where I don't know how to bind it.

I have the following model:
<eClassifiers xsi:type="ecore:EClass" name="MobileFilter">
<eStructuralFeatures xsi:type="ecore:EReference"
name="conditions"
lowerBound="1"
upperBound="-1"
eType="#//whitepage/FilterCondition"
containment="true"/>
</eClassifiers>

<eClassifiers xsi:type="ecore:EClass" name="FilterCondition"
abstract="true"
interface="true"/>

<eClassifiers xsi:type="ecore:EClass" name="UnitTypeCondition"
eSuperTypes="#//whitepage/FilterCondition">
<eStructuralFeatures xsi:type="ecore:EAttribute"
name="unitTypes" upperBound="-1"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>

So a MobileFilter contains a list of FilterCondition. FilterCondition
has many specialized implementation around the model, one is
UnitTypeCondition. The condition list of MobileFilter usually contains
one UnitTypeCondition. UnitTYpeCondition has a list of unitTypes (Strings).
I'm also in a master detail context where the master value is a
MobileFilter that can change.

What I need now is an editable observable set of unitTypes (Strings)
from the UnitTypeCondition.

Using a feature path didn't work:
EMFEditProperties.set(editingDomain,
FeaturePath.fromList(WhitepagePackage.Literals.MOBILE_FILTER __CONDITIONS,
WhitepagePackage.Literals.UNIT_TYPE_CONDITION__UNIT_TYPES)). observeDetail(masterObservable);

What would be the best thing to bind something like this?
I need a set, as I want to use a CheckBoxTableViewer to bind to the set.

Cheers.
--Thomas
Re: [EMF databinding] set binding problem [message #521655 is a reply to message #521644] Thu, 18 March 2010 12:06 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 18.03.10 12:48, schrieb Thomas Kowatsch:
> Hi.
>
> I have a databinding problem where I don't know how to bind it.
>
> I have the following model:
> <eClassifiers xsi:type="ecore:EClass" name="MobileFilter">
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="conditions"
> lowerBound="1"
> upperBound="-1"
> eType="#//whitepage/FilterCondition"
> containment="true"/>
> </eClassifiers>
>
> <eClassifiers xsi:type="ecore:EClass" name="FilterCondition"
> abstract="true"
> interface="true"/>
>
> <eClassifiers xsi:type="ecore:EClass" name="UnitTypeCondition"
> eSuperTypes="#//whitepage/FilterCondition">
> <eStructuralFeatures xsi:type="ecore:EAttribute"
> name="unitTypes" upperBound="-1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> </eClassifiers>
>
> So a MobileFilter contains a list of FilterCondition. FilterCondition
> has many specialized implementation around the model, one is
> UnitTypeCondition. The condition list of MobileFilter usually contains
> one UnitTypeCondition. UnitTYpeCondition has a list of unitTypes (Strings).
> I'm also in a master detail context where the master value is a
> MobileFilter that can change.
>
> What I need now is an editable observable set of unitTypes (Strings)
> from the UnitTypeCondition.
>
> Using a feature path didn't work:
> EMFEditProperties.set(editingDomain,
> FeaturePath.fromList(WhitepagePackage.Literals.MOBILE_FILTER __CONDITIONS, WhitepagePackage.Literals.UNIT_TYPE_CONDITION__UNIT_TYPES)). observeDetail(masterObservable);
>

The problem is that databinding cann't deal with a path which has an
MultiValued feature. If you know that you have always only set index 0
then you could:
a) add a volatile, transient feature named MOBILE_FILTER_CONDITION_0
which is a single valued feature but naturally clutters you model

b) or do the transiation using a WritableValue:

--------8<--------
WritableValue w = new WritableValue();
IEMFListProperty prop = EMFEditProperties.list(
WhitepagePackage.Literals.MOBILE_FILTER__CONDITIONS
);
IObservableList l = prop.observeDetail(masterObservable);
l.addListChangeListener( new IListChangeListener() {
public void handleListChange(ListChangeEvent event) {
if( event.getObservableList().size() > 0 ) {
if( event.getObservableList() instanceof UnitTypeCondition ) {
w.setValue(event.getObservableList().get(0));
} else {
w.setValue(null);
}
} else {
w.setValue(null);
}
}
}
IEMFSetProperty prop = EMFEditProperties.set(
WhitepagePackage.Literals.UNIT_TYPE_CONDITION__UNIT_TYPES
);
prop.observeDetail(w);
--------8<--------


>
> What would be the best thing to bind something like this?
> I need a set, as I want to use a CheckBoxTableViewer to bind to the set.
>
> Cheers.
> --Thomas
Re: [EMF databinding] set binding problem [message #521656 is a reply to message #521655] Thu, 18 March 2010 12:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Thomas.Kowatsch.ruag.com

Thx Tom.
I thought about that (WritableValue) already, but was not sure if there
is another "easier" solution.
Cheers.
--Thomas

Tom Schindl schrieb:
> Am 18.03.10 12:48, schrieb Thomas Kowatsch:
>> Hi.
>>
>> I have a databinding problem where I don't know how to bind it.
>>
>> I have the following model:
>> <eClassifiers xsi:type="ecore:EClass" name="MobileFilter">
>> <eStructuralFeatures xsi:type="ecore:EReference"
>> name="conditions"
>> lowerBound="1"
>> upperBound="-1"
>> eType="#//whitepage/FilterCondition"
>> containment="true"/>
>> </eClassifiers>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="FilterCondition"
>> abstract="true"
>> interface="true"/>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="UnitTypeCondition"
>> eSuperTypes="#//whitepage/FilterCondition">
>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>> name="unitTypes" upperBound="-1"
>> eType="ecore:EDataType
>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>> </eClassifiers>
>>
>> So a MobileFilter contains a list of FilterCondition. FilterCondition
>> has many specialized implementation around the model, one is
>> UnitTypeCondition. The condition list of MobileFilter usually contains
>> one UnitTypeCondition. UnitTYpeCondition has a list of unitTypes (Strings).
>> I'm also in a master detail context where the master value is a
>> MobileFilter that can change.
>>
>> What I need now is an editable observable set of unitTypes (Strings)
>> from the UnitTypeCondition.
>>
>> Using a feature path didn't work:
>> EMFEditProperties.set(editingDomain,
>> FeaturePath.fromList(WhitepagePackage.Literals.MOBILE_FILTER __CONDITIONS, WhitepagePackage.Literals.UNIT_TYPE_CONDITION__UNIT_TYPES)). observeDetail(masterObservable);
>>
>
> The problem is that databinding cann't deal with a path which has an
> MultiValued feature. If you know that you have always only set index 0
> then you could:
> a) add a volatile, transient feature named MOBILE_FILTER_CONDITION_0
> which is a single valued feature but naturally clutters you model
>
> b) or do the transiation using a WritableValue:
>
> --------8<--------
> WritableValue w = new WritableValue();
> IEMFListProperty prop = EMFEditProperties.list(
> WhitepagePackage.Literals.MOBILE_FILTER__CONDITIONS
> );
> IObservableList l = prop.observeDetail(masterObservable);
> l.addListChangeListener( new IListChangeListener() {
> public void handleListChange(ListChangeEvent event) {
> if( event.getObservableList().size() > 0 ) {
> if( event.getObservableList() instanceof UnitTypeCondition ) {
> w.setValue(event.getObservableList().get(0));
> } else {
> w.setValue(null);
> }
> } else {
> w.setValue(null);
> }
> }
> }
> IEMFSetProperty prop = EMFEditProperties.set(
> WhitepagePackage.Literals.UNIT_TYPE_CONDITION__UNIT_TYPES
> );
> prop.observeDetail(w);
> --------8<--------
>
>
>> What would be the best thing to bind something like this?
>> I need a set, as I want to use a CheckBoxTableViewer to bind to the set.
>>
>> Cheers.
>> --Thomas
>
Re: [EMF databinding] set binding problem [message #521667 is a reply to message #521655] Thu, 18 March 2010 12:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: Thomas.Kowatsch.ruag.com

Hmm.. the WritableValue solution gives me a class cast exception in
EMFSetProperty#doGetSet(Object source) when casting to EObject.
The problem ist that the source for the property is the WritableValue
and not the EObject which the WritableValue stores!?
Cheers.
--Thomas

Tom Schindl schrieb:
> Am 18.03.10 12:48, schrieb Thomas Kowatsch:
>> Hi.
>>
>> I have a databinding problem where I don't know how to bind it.
>>
>> I have the following model:
>> <eClassifiers xsi:type="ecore:EClass" name="MobileFilter">
>> <eStructuralFeatures xsi:type="ecore:EReference"
>> name="conditions"
>> lowerBound="1"
>> upperBound="-1"
>> eType="#//whitepage/FilterCondition"
>> containment="true"/>
>> </eClassifiers>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="FilterCondition"
>> abstract="true"
>> interface="true"/>
>>
>> <eClassifiers xsi:type="ecore:EClass" name="UnitTypeCondition"
>> eSuperTypes="#//whitepage/FilterCondition">
>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>> name="unitTypes" upperBound="-1"
>> eType="ecore:EDataType
>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>> </eClassifiers>
>>
>> So a MobileFilter contains a list of FilterCondition. FilterCondition
>> has many specialized implementation around the model, one is
>> UnitTypeCondition. The condition list of MobileFilter usually contains
>> one UnitTypeCondition. UnitTYpeCondition has a list of unitTypes (Strings).
>> I'm also in a master detail context where the master value is a
>> MobileFilter that can change.
>>
>> What I need now is an editable observable set of unitTypes (Strings)
>> from the UnitTypeCondition.
>>
>> Using a feature path didn't work:
>> EMFEditProperties.set(editingDomain,
>> FeaturePath.fromList(WhitepagePackage.Literals.MOBILE_FILTER __CONDITIONS, WhitepagePackage.Literals.UNIT_TYPE_CONDITION__UNIT_TYPES)). observeDetail(masterObservable);
>>
>
> The problem is that databinding cann't deal with a path which has an
> MultiValued feature. If you know that you have always only set index 0
> then you could:
> a) add a volatile, transient feature named MOBILE_FILTER_CONDITION_0
> which is a single valued feature but naturally clutters you model
>
> b) or do the transiation using a WritableValue:
>
> --------8<--------
> WritableValue w = new WritableValue();
> IEMFListProperty prop = EMFEditProperties.list(
> WhitepagePackage.Literals.MOBILE_FILTER__CONDITIONS
> );
> IObservableList l = prop.observeDetail(masterObservable);
> l.addListChangeListener( new IListChangeListener() {
> public void handleListChange(ListChangeEvent event) {
> if( event.getObservableList().size() > 0 ) {
> if( event.getObservableList() instanceof UnitTypeCondition ) {
> w.setValue(event.getObservableList().get(0));
> } else {
> w.setValue(null);
> }
> } else {
> w.setValue(null);
> }
> }
> }
> IEMFSetProperty prop = EMFEditProperties.set(
> WhitepagePackage.Literals.UNIT_TYPE_CONDITION__UNIT_TYPES
> );
> prop.observeDetail(w);
> --------8<--------
>
>
>> What would be the best thing to bind something like this?
>> I need a set, as I want to use a CheckBoxTableViewer to bind to the set.
>>
>> Cheers.
>> --Thomas
>
Re: [EMF databinding] set binding problem [message #521679 is a reply to message #521667] Thu, 18 March 2010 13:36 Go to previous message
Eclipse UserFriend
Originally posted by: Thomas.Kowatsch.ruag.com

ÄHHH sorry, my mistake. I wrongly set the WritableValue to itself, i.e.
w.setValue(w) :-)
Not my day today ....

Thomas Kowatsch schrieb:
> Hmm.. the WritableValue solution gives me a class cast exception in
> EMFSetProperty#doGetSet(Object source) when casting to EObject.
> The problem ist that the source for the property is the WritableValue
> and not the EObject which the WritableValue stores!?
> Cheers.
> --Thomas
>
> Tom Schindl schrieb:
>> Am 18.03.10 12:48, schrieb Thomas Kowatsch:
>>> Hi.
>>>
>>> I have a databinding problem where I don't know how to bind it.
>>>
>>> I have the following model:
>>> <eClassifiers xsi:type="ecore:EClass" name="MobileFilter">
>>> <eStructuralFeatures xsi:type="ecore:EReference"
>>> name="conditions"
>>> lowerBound="1"
>>> upperBound="-1"
>>> eType="#//whitepage/FilterCondition"
>>> containment="true"/>
>>> </eClassifiers>
>>>
>>> <eClassifiers xsi:type="ecore:EClass" name="FilterCondition"
>>> abstract="true"
>>> interface="true"/>
>>>
>>> <eClassifiers xsi:type="ecore:EClass" name="UnitTypeCondition"
>>> eSuperTypes="#//whitepage/FilterCondition">
>>> <eStructuralFeatures xsi:type="ecore:EAttribute"
>>> name="unitTypes" upperBound="-1"
>>> eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
>>> </eClassifiers>
>>>
>>> So a MobileFilter contains a list of FilterCondition. FilterCondition
>>> has many specialized implementation around the model, one is
>>> UnitTypeCondition. The condition list of MobileFilter usually contains
>>> one UnitTypeCondition. UnitTYpeCondition has a list of unitTypes
>>> (Strings).
>>> I'm also in a master detail context where the master value is a
>>> MobileFilter that can change.
>>>
>>> What I need now is an editable observable set of unitTypes (Strings)
>>> from the UnitTypeCondition.
>>>
>>> Using a feature path didn't work:
>>> EMFEditProperties.set(editingDomain,
>>> FeaturePath.fromList(WhitepagePackage.Literals.MOBILE_FILTER __CONDITIONS,
>>> WhitepagePackage.Literals.UNIT_TYPE_CONDITION__UNIT_TYPES)). observeDetail(masterObservable);
>>>
>>>
>>
>> The problem is that databinding cann't deal with a path which has an
>> MultiValued feature. If you know that you have always only set index 0
>> then you could:
>> a) add a volatile, transient feature named MOBILE_FILTER_CONDITION_0
>> which is a single valued feature but naturally clutters you model
>>
>> b) or do the transiation using a WritableValue:
>>
>> --------8<--------
>> WritableValue w = new WritableValue();
>> IEMFListProperty prop = EMFEditProperties.list(
>> WhitepagePackage.Literals.MOBILE_FILTER__CONDITIONS
>> );
>> IObservableList l = prop.observeDetail(masterObservable);
>> l.addListChangeListener( new IListChangeListener() {
>> public void handleListChange(ListChangeEvent event) {
>> if( event.getObservableList().size() > 0 ) {
>> if( event.getObservableList() instanceof UnitTypeCondition ) {
>> w.setValue(event.getObservableList().get(0));
>> } else {
>> w.setValue(null);
>> }
>> } else {
>> w.setValue(null);
>> }
>> }
>> }
>> IEMFSetProperty prop = EMFEditProperties.set(
>> WhitepagePackage.Literals.UNIT_TYPE_CONDITION__UNIT_TYPES
>> );
>> prop.observeDetail(w);
>> --------8<--------
>>
>>
>>> What would be the best thing to bind something like this?
>>> I need a set, as I want to use a CheckBoxTableViewer to bind to the set.
>>>
>>> Cheers.
>>> --Thomas
>>
Previous Topic:[CDO] missing org.eclipse.net4j.db.derby
Next Topic:Serialize CDO Resource
Goto Forum:
  


Current Time: Fri Apr 26 11:05:22 GMT 2024

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

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

Back to the top