Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Databinding for CheckboxTableViewer.checkedElements
EMF Databinding for CheckboxTableViewer.checkedElements [message #1425766] Wed, 17 September 2014 20:25 Go to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 289
Registered: July 2009
Senior Member

Hi,

I'm sure I just miss some little detail but I wasn't able to find it yet in the web.

I try to bind the checked elements of a checkboxtableviewer to an EMF model entity as follows:

IViewerObservableSet vChecked = ViewersObservables.observeCheckedElements(tableViewer, SomeClass.class);
IObservableList eChecked = EMFObservables.observeList(settings,
ModelPackage.eINSTANCE.getSettings_Source());
bindingContext.bind[Set|List|Value](vChecked, eChecked);

Unfortunately this does not compile since I'm not allowed to mix IViewerObservableSet (which comes from ViewersObservables.observeCheckedElements) and IViewerObservableList (which comes from EMFObservables.observeList). There is no such thing like EMFObservables.observeSet, so I'm a bit lost at the moment.

Any advice would be greatly appreciated.

Thanks,
Marcel

[Updated on: Wed, 17 September 2014 20:27]

Report message to a moderator

Re: EMF Databinding for CheckboxTableViewer.checkedElements [message #1425808 is a reply to message #1425766] Wed, 17 September 2014 21:46 Go to previous messageGo to next message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 289
Registered: July 2009
Senior Member

Okay, I found the solution in Tom Seidel's remus project:

public class List2SetConverter {
    public static IObservableSet create(final IObservableList source) {
        final IObservableSet set = new WritableSet(source, null);
        source.addListChangeListener(new IListChangeListener() {
            @Override
            public void handleListChange(final ListChangeEvent event) {
                event.diff.accept(new ListDiffVisitor() {
                    @Override
                    public void handleRemove(final int index, final Object element) {
                        set.remove(element);
                    }

                    @Override
                    public void handleAdd(final int index, final Object element) {
                        set.add(element);
                    }
                });
            }
        });
        set.addSetChangeListener(new ISetChangeListener() {
            @Override
            public void handleSetChange(final SetChangeEvent event) {
                SetDiff diff = event.diff;
                source.addAll(diff.getAdditions());
                source.removeAll(diff.getRemovals());
            }
        });
        return set;
    }
}


which then allows me to do:
IViewerObservableSet vChecked = ViewersObservables.observeCheckedElements(viewer, Type.class);
IObservableSet eChecked = List2SetConverter.create(EMFObservables.observeList(settings, ModelPackage.eINSTANCE.getSettings_Source()));
bindingContext.bindSet(vChecked, eChecked);


Marcel
Re: EMF Databinding for CheckboxTableViewer.checkedElements [message #1426144 is a reply to message #1425808] Thu, 18 September 2014 09:56 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6505
Registered: July 2009
Senior Member
There's util class in core.databinding.observable which is named
ListToSetAdapter.

Tom

On 17.09.14 23:46, Marcel Bruch wrote:
> Okay, I found the solution in Tom Seidel's remus project:
>
>
> public class List2SetConverter {
> public static IObservableSet create(final IObservableList source) {
> final IObservableSet set = new WritableSet(source, null);
> source.addListChangeListener(new IListChangeListener() {
> @Override
> public void handleListChange(final ListChangeEvent event) {
> event.diff.accept(new ListDiffVisitor() {
> @Override
> public void handleRemove(final int index, final
> Object element) {
> set.remove(element);
> }
>
> @Override
> public void handleAdd(final int index, final Object
> element) {
> set.add(element);
> }
> });
> }
> });
> set.addSetChangeListener(new ISetChangeListener() {
> @Override
> public void handleSetChange(final SetChangeEvent event) {
> SetDiff diff = event.diff;
> source.addAll(diff.getAdditions());
> source.removeAll(diff.getRemovals());
> }
> });
> return set;
> }
> }
>
>
> which then allows me to do:
>
> IViewerObservableSet vChecked =
> ViewersObservables.observeCheckedElements(viewer, Type.class);
> IObservableSet eChecked =
> List2SetConverter.create(EMFObservables.observeList(settings,
> ModelPackage.eINSTANCE.getSettings_Source()));
> bindingContext.bindSet(vChecked, eChecked);
>
>
> Marcel
Re: EMF Databinding for CheckboxTableViewer.checkedElements [message #1426146 is a reply to message #1426144] Thu, 18 September 2014 10:00 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6505
Registered: July 2009
Senior Member
on another note by default multi-valued features fullfill the Set
contract so we might do better than copying stuff around and make the
observable we create also implement the IObservableSet semantics and so
reduce the copying done (in your and the ListToSetAdapter approach).

You can file a bugzilla - I can not promise I have the time to implement
it but so at least we don't forget about it ;-)

Tom

On 18.09.14 11:56, Tom Schindl wrote:
> There's util class in core.databinding.observable which is named
> ListToSetAdapter.
>
> Tom
>
> On 17.09.14 23:46, Marcel Bruch wrote:
>> Okay, I found the solution in Tom Seidel's remus project:
>>
>>
>> public class List2SetConverter {
>> public static IObservableSet create(final IObservableList source) {
>> final IObservableSet set = new WritableSet(source, null);
>> source.addListChangeListener(new IListChangeListener() {
>> @Override
>> public void handleListChange(final ListChangeEvent event) {
>> event.diff.accept(new ListDiffVisitor() {
>> @Override
>> public void handleRemove(final int index, final
>> Object element) {
>> set.remove(element);
>> }
>>
>> @Override
>> public void handleAdd(final int index, final Object
>> element) {
>> set.add(element);
>> }
>> });
>> }
>> });
>> set.addSetChangeListener(new ISetChangeListener() {
>> @Override
>> public void handleSetChange(final SetChangeEvent event) {
>> SetDiff diff = event.diff;
>> source.addAll(diff.getAdditions());
>> source.removeAll(diff.getRemovals());
>> }
>> });
>> return set;
>> }
>> }
>>
>>
>> which then allows me to do:
>>
>> IViewerObservableSet vChecked =
>> ViewersObservables.observeCheckedElements(viewer, Type.class);
>> IObservableSet eChecked =
>> List2SetConverter.create(EMFObservables.observeList(settings,
>> ModelPackage.eINSTANCE.getSettings_Source()));
>> bindingContext.bindSet(vChecked, eChecked);
>>
>>
>> Marcel
>
Re: EMF Databinding for CheckboxTableViewer.checkedElements [message #1426164 is a reply to message #1426146] Thu, 18 September 2014 10:34 Go to previous message
Marcel Bruch is currently offline Marcel BruchFriend
Messages: 289
Registered: July 2009
Senior Member

Thanks Tom. That was the missing pointer.
Previous Topic:Problem with comparing models
Next Topic:[CDO] MySQL database is broken after restart of CDO server
Goto Forum:
  


Current Time: Mon Oct 21 09:40:47 GMT 2019

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

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

Back to the top