Home » Modeling » EMF » Problem with databinding
| |
Re: Problem with databinding [message #421362 is a reply to message #421347] |
Tue, 05 August 2008 15:07 |
Eclipse User |
|
|
|
Originally posted by: tskaufma.gmail.com
Hello,
Assuming viewer is a TableViewer, eObject is your EObject, and
eStructuralFeature is your feature do:
ObservableListContentProvider contentProvider = new
ObservableListContentProvider(); // this is from JFace Databinding
viewer.setContentProvider(contentProvider);
viewer.setInput(EMFObservables.observeList(eObject, eStructuralFeature));
This uses a default LabelProvider which uses the Object's toString method.
If this is acceptable, your good to go.
Otherwise, try doing
IObserableMap[] columnMaps = new IObservableMap[numOfColumns];
then for each attribute you want displayed in a column do:
columnMaps[i] =
EMFObservables.observeMap(contentProvider.getKnownElements() , eAttribute);
where contentProvider is from above, and eAttribute is the attribute of the
Object in the list you want to display is the ith column.
Then:
viewer.setLabelProvider(new ObservableMapLabelProvider(columnMaps));
I hope this helps,
Trevor Kaufman
"Mario Cervera" <mcervera@integranova.com> wrote in message
news:g79ck8$drc$1@build.eclipse.org...
> Hi everybody.
>
> I want to bind a feature of an EObject (type List) to a Table of JFace so
> that the table shows the elements of the List (using a TableViewer). Is it
> possible? I've managed to bind features (of any type but collections) to
> swt widgets but I can't seem to make it in this case.
>
> Any help or code snippet would be appreciated.
>
> Thanks in advance.
>
> Mario.
|
|
| |
Re: Problem with databinding [message #421373 is a reply to message #421362] |
Wed, 06 August 2008 07:36 |
Mario Cervera Messages: 66 Registered: July 2009 |
Member |
|
|
Thank you so much, that was very helpful.
Now I am trying to add elements to my list just by adding items to the
table (that is, without using commands). The same idea as when you bind
a EAttribute of type String to a Text and modify the attribute by
writting on the Text. I've had problems so far but I'll keep trying.
Thanks again
Mario
Trevor Kaufman escribió:
> Hello,
>
> Assuming viewer is a TableViewer, eObject is your EObject, and
> eStructuralFeature is your feature do:
>
> ObservableListContentProvider contentProvider = new
> ObservableListContentProvider(); // this is from JFace Databinding
> viewer.setContentProvider(contentProvider);
> viewer.setInput(EMFObservables.observeList(eObject, eStructuralFeature));
>
> This uses a default LabelProvider which uses the Object's toString
> method. If this is acceptable, your good to go.
> Otherwise, try doing
>
> IObserableMap[] columnMaps = new IObservableMap[numOfColumns];
>
> then for each attribute you want displayed in a column do:
>
> columnMaps[i] =
> EMFObservables.observeMap(contentProvider.getKnownElements() , eAttribute);
>
> where contentProvider is from above, and eAttribute is the attribute of
> the Object in the list you want to display is the ith column.
> Then:
> viewer.setLabelProvider(new ObservableMapLabelProvider(columnMaps));
>
> I hope this helps,
> Trevor Kaufman
>
> "Mario Cervera" <mcervera@integranova.com> wrote in message
> news:g79ck8$drc$1@build.eclipse.org...
>> Hi everybody.
>>
>> I want to bind a feature of an EObject (type List) to a Table of JFace
>> so that the table shows the elements of the List (using a
>> TableViewer). Is it possible? I've managed to bind features (of any
>> type but collections) to swt widgets but I can't seem to make it in
>> this case.
>>
>> Any help or code snippet would be appreciated.
>>
>> Thanks in advance.
>>
>> Mario.
>
|
|
|
Re: Problem with databinding [message #421374 is a reply to message #421373] |
Wed, 06 August 2008 07:43 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
How do you add the elements? You should only modify the original EList
and then ObservalListContentProvider will update the viewer.
Tom
Mario Cervera schrieb:
> Thank you so much, that was very helpful.
>
> Now I am trying to add elements to my list just by adding items to the
> table (that is, without using commands). The same idea as when you bind
> a EAttribute of type String to a Text and modify the attribute by
> writting on the Text. I've had problems so far but I'll keep trying.
>
> Thanks again
>
> Mario
>
> Trevor Kaufman escribió:
>> Hello,
>>
>> Assuming viewer is a TableViewer, eObject is your EObject, and
>> eStructuralFeature is your feature do:
>>
>> ObservableListContentProvider contentProvider = new
>> ObservableListContentProvider(); // this is from JFace Databinding
>> viewer.setContentProvider(contentProvider);
>> viewer.setInput(EMFObservables.observeList(eObject,
>> eStructuralFeature));
>>
>> This uses a default LabelProvider which uses the Object's toString
>> method. If this is acceptable, your good to go.
>> Otherwise, try doing
>>
>> IObserableMap[] columnMaps = new IObservableMap[numOfColumns];
>>
>> then for each attribute you want displayed in a column do:
>>
>> columnMaps[i] =
>> EMFObservables.observeMap(contentProvider.getKnownElements() ,
>> eAttribute);
>>
>> where contentProvider is from above, and eAttribute is the attribute
>> of the Object in the list you want to display is the ith column.
>> Then:
>> viewer.setLabelProvider(new ObservableMapLabelProvider(columnMaps));
>>
>> I hope this helps,
>> Trevor Kaufman
>>
>> "Mario Cervera" <mcervera@integranova.com> wrote in message
>> news:g79ck8$drc$1@build.eclipse.org...
>>> Hi everybody.
>>>
>>> I want to bind a feature of an EObject (type List) to a Table of
>>> JFace so that the table shows the elements of the List (using a
>>> TableViewer). Is it possible? I've managed to bind features (of any
>>> type but collections) to swt widgets but I can't seem to make it in
>>> this case.
>>>
>>> Any help or code snippet would be appreciated.
>>>
>>> Thanks in advance.
>>>
>>> Mario.
>>
--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
|
|
|
Re: Problem with databinding [message #421375 is a reply to message #421374] |
Wed, 06 August 2008 07:56 |
Mario Cervera Messages: 66 Registered: July 2009 |
Member |
|
|
My idea is the following:
Imagine I have an EObject which has a feature of type String, then in my
editor I want to modify the value of this feature by writting on a text
box. I can do it using databinding very easily.
Now I have a feature of type List and the widget where I am showing the
content is a TableViewer, I should be able to modify the list by adding
(tableViewer.add(object)) or removing items from the Table, shouldn't I?
If I modify the EList directly I need a write transaction so I need to
use Commands which I want to avoid.
Thanks.
Mario
Tom Schindl escribió:
> How do you add the elements? You should only modify the original EList
> and then ObservalListContentProvider will update the viewer.
>
> Tom
>
> Mario Cervera schrieb:
>> Thank you so much, that was very helpful.
>>
>> Now I am trying to add elements to my list just by adding items to the
>> table (that is, without using commands). The same idea as when you
>> bind a EAttribute of type String to a Text and modify the attribute by
>> writting on the Text. I've had problems so far but I'll keep trying.
>>
>> Thanks again
>>
>> Mario
>>
>> Trevor Kaufman escribió:
>>> Hello,
>>>
>>> Assuming viewer is a TableViewer, eObject is your EObject, and
>>> eStructuralFeature is your feature do:
>>>
>>> ObservableListContentProvider contentProvider = new
>>> ObservableListContentProvider(); // this is from JFace Databinding
>>> viewer.setContentProvider(contentProvider);
>>> viewer.setInput(EMFObservables.observeList(eObject,
>>> eStructuralFeature));
>>>
>>> This uses a default LabelProvider which uses the Object's toString
>>> method. If this is acceptable, your good to go.
>>> Otherwise, try doing
>>>
>>> IObserableMap[] columnMaps = new IObservableMap[numOfColumns];
>>>
>>> then for each attribute you want displayed in a column do:
>>>
>>> columnMaps[i] =
>>> EMFObservables.observeMap(contentProvider.getKnownElements() ,
>>> eAttribute);
>>>
>>> where contentProvider is from above, and eAttribute is the attribute
>>> of the Object in the list you want to display is the ith column.
>>> Then:
>>> viewer.setLabelProvider(new ObservableMapLabelProvider(columnMaps));
>>>
>>> I hope this helps,
>>> Trevor Kaufman
>>>
>>> "Mario Cervera" <mcervera@integranova.com> wrote in message
>>> news:g79ck8$drc$1@build.eclipse.org...
>>>> Hi everybody.
>>>>
>>>> I want to bind a feature of an EObject (type List) to a Table of
>>>> JFace so that the table shows the elements of the List (using a
>>>> TableViewer). Is it possible? I've managed to bind features (of any
>>>> type but collections) to swt widgets but I can't seem to make it in
>>>> this case.
>>>>
>>>> Any help or code snippet would be appreciated.
>>>>
>>>> Thanks in advance.
>>>>
>>>> Mario.
>>>
>
>
|
|
| | | | |
Re: Problem with databinding [message #421390 is a reply to message #421379] |
Wed, 06 August 2008 11:58 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
Mario,
Yes, without using commands in some way, you'd not be able to undo your
changes. If you add to the observing list though, the commands are made
for you automatically, which I think is what you wanted. So if you
used EMFEditObservables.observeList, modified that list, and then
disposed that list, this would do the trick I think...
Mario Cervera wrote:
> Ok I think will use commands... doesn't matter. Thanks for all your
> help :)
>
> Mario
>
> Tom Schindl escribió:
>> Ok. You are using a TransactionEditingDomain then I think you need to
>> use Commands but I'm not an expert in this :-)
>>
>> Tom
>>
>> Mario Cervera schrieb:
>>> I see your point and sounds nice but if I do
>>> myEObject#getMyList()#add() I get:
>>>
>>> java.lang.IllegalStateException: Cannot modify resource set without
>>> a write transaction
>>> at
>>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:338)
>>>
>>> at
>>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ppendNotification(TransactionChangeRecorder.java:300)
>>>
>>> at
>>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.p rocessObjectNotification(TransactionChangeRecorder.java:282)
>>>
>>> at
>>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.n otifyChanged(TransactionChangeRecorder.java:238)
>>>
>>> at
>>> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>>>
>>> at
>>> org.eclipse.emf.ecore.util.EcoreEList.dispatchNotification(E coreEList.java:255)
>>>
>>> at
>>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:300)
>>>
>>> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
>>>
>>> .............
>>>
>>> :(
>>>
>>> What can I do??
>>>
>>> Mario
>>>
>>> Tom Schindl escribió:
>>>> Mario Cervera schrieb:
>>>>> My idea is the following:
>>>>>
>>>>> Imagine I have an EObject which has a feature of type String, then
>>>>> in my editor I want to modify the value of this feature by
>>>>> writting on a text box. I can do it using databinding very easily.
>>>>>
>>>>> Now I have a feature of type List and the widget where I am
>>>>> showing the content is a TableViewer, I should be able to modify
>>>>> the list by adding (tableViewer.add(object)) or removing items
>>>>> from the Table, shouldn't I? If I modify the EList directly I need
>>>>> a write transaction so I need to use Commands which I want to avoid.
>>>>
>>>> That's not correct tableViewer#add()/remove() won't modify the
>>>> underlying data structure the way is always model => View in
>>>> JFace-Viewers.
>>>>
>>>> You are never forced to use commands (another reason way the view
>>>> => model does work where from should the TableViewer know which
>>>> command it should execute). You don't have to use a command if
>>>> don't want to
>>>> myEObject#getMyList()#add() allows you to add the element and the
>>>> databinding framework keeps your TableViewer in sync with your model.
>>>>
>>>> Tom
>>>>
>>
>>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Problem with databinding [message #421392 is a reply to message #421390] |
Wed, 06 August 2008 12:14 |
Mario Cervera Messages: 66 Registered: July 2009 |
Member |
|
|
Cool! It worked! thank you :D
Mario
Ed Merks escribió:
> Mario,
>
> Yes, without using commands in some way, you'd not be able to undo your
> changes. If you add to the observing list though, the commands are made
> for you automatically, which I think is what you wanted. So if you
> used EMFEditObservables.observeList, modified that list, and then
> disposed that list, this would do the trick I think...
>
>
> Mario Cervera wrote:
>> Ok I think will use commands... doesn't matter. Thanks for all your
>> help :)
>>
>> Mario
>>
>> Tom Schindl escribió:
>>> Ok. You are using a TransactionEditingDomain then I think you need to
>>> use Commands but I'm not an expert in this :-)
>>>
>>> Tom
>>>
>>> Mario Cervera schrieb:
>>>> I see your point and sounds nice but if I do
>>>> myEObject#getMyList()#add() I get:
>>>>
>>>> java.lang.IllegalStateException: Cannot modify resource set without
>>>> a write transaction
>>>> at
>>>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ssertWriting(TransactionChangeRecorder.java:338)
>>>>
>>>> at
>>>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.a ppendNotification(TransactionChangeRecorder.java:300)
>>>>
>>>> at
>>>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.p rocessObjectNotification(TransactionChangeRecorder.java:282)
>>>>
>>>> at
>>>> org.eclipse.emf.transaction.impl.TransactionChangeRecorder.n otifyChanged(TransactionChangeRecorder.java:238)
>>>>
>>>> at
>>>> org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify (BasicNotifierImpl.java:247)
>>>>
>>>> at
>>>> org.eclipse.emf.ecore.util.EcoreEList.dispatchNotification(E coreEList.java:255)
>>>>
>>>> at
>>>> org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUniq ue(NotifyingListImpl.java:300)
>>>>
>>>> at org.eclipse.emf.common.util.BasicEList.add(BasicEList.java:6 26)
>>>>
>>>> .............
>>>>
>>>> :(
>>>>
>>>> What can I do??
>>>>
>>>> Mario
>>>>
>>>> Tom Schindl escribió:
>>>>> Mario Cervera schrieb:
>>>>>> My idea is the following:
>>>>>>
>>>>>> Imagine I have an EObject which has a feature of type String, then
>>>>>> in my editor I want to modify the value of this feature by
>>>>>> writting on a text box. I can do it using databinding very easily.
>>>>>>
>>>>>> Now I have a feature of type List and the widget where I am
>>>>>> showing the content is a TableViewer, I should be able to modify
>>>>>> the list by adding (tableViewer.add(object)) or removing items
>>>>>> from the Table, shouldn't I? If I modify the EList directly I need
>>>>>> a write transaction so I need to use Commands which I want to avoid.
>>>>>
>>>>> That's not correct tableViewer#add()/remove() won't modify the
>>>>> underlying data structure the way is always model => View in
>>>>> JFace-Viewers.
>>>>>
>>>>> You are never forced to use commands (another reason way the view
>>>>> => model does work where from should the TableViewer know which
>>>>> command it should execute). You don't have to use a command if
>>>>> don't want to
>>>>> myEObject#getMyList()#add() allows you to add the element and the
>>>>> databinding framework keeps your TableViewer in sync with your model.
>>>>>
>>>>> Tom
>>>>>
>>>
>>>
|
|
|
Goto Forum:
Current Time: Fri Apr 26 23:03:44 GMT 2024
Powered by FUDForum. Page generated in 0.03888 seconds
|