Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » CheckboxTreeViewer data binding with EMF
CheckboxTreeViewer data binding with EMF [message #424097] Thu, 16 October 2008 07:24 Go to next message
Dénes Harmath is currently offline Dénes Harmath
Messages: 153
Registered: July 2009
Senior Member
Hi,
I want to bind the checkboxes of a CheckboxTreeViewer to a boolean
property of EMF objects displayed by the tree with JFace/EMF databinding.
How can I do this? I am aware of
ViewerObservables.observeCheckedElements(), but it returns an
IObservableSet, and I don't know any EMFObservables observer that returns
that type. I would need an example to bind it to an EMF structural
property... Thanks in advance,
thSoft
Re: CheckboxTreeViewer data binding with EMF [message #424114 is a reply to message #424097] Thu, 16 October 2008 12:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 24549
Registered: July 2009
Senior Member
Dennis,

What's the Set supposed to contain?


Dennis Harmath wrote:
> Hi,
> I want to bind the checkboxes of a CheckboxTreeViewer to a boolean
> property of EMF objects displayed by the tree with JFace/EMF
> databinding. How can I do this? I am aware of
> ViewerObservables.observeCheckedElements(), but it returns an
> IObservableSet, and I don't know any EMFObservables observer that
> returns that type. I would need an example to bind it to an EMF
> structural property... Thanks in advance,
> thSoft
>
Re: CheckboxTreeViewer data binding with EMF [message #424115 is a reply to message #424114] Thu, 16 October 2008 13:03 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 4462
Registered: July 2009
Senior Member
The checked-elements and it is an ObservableSet because Databinding
can't guarantee the order which is an often forgotten nature of Lists.

Tom

Ed Merks schrieb:
> Dennis,
>
> What's the Set supposed to contain?
>
>
> Dennis Harmath wrote:
>> Hi,
>> I want to bind the checkboxes of a CheckboxTreeViewer to a boolean
>> property of EMF objects displayed by the tree with JFace/EMF
>> databinding. How can I do this? I am aware of
>> ViewerObservables.observeCheckedElements(), but it returns an
>> IObservableSet, and I don't know any EMFObservables observer that
>> returns that type. I would need an example to bind it to an EMF
>> structural property... Thanks in advance,
>> thSoft
>>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: CheckboxTreeViewer data binding with EMF [message #424119 is a reply to message #424115] Thu, 16 October 2008 13:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 24549
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010404080502080405000801
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Tom,

I see. It sounds like the set of checked elements would need to be
computed somehow anyway; it doesn't correspond directly to a feature.
Some type of new hand utility class would be needed where
adding/removing from the set would toggle some feature's state and
listeners to the feature's state would add/remove the object from the
set (all without getting into a loop).


Tom Schindl wrote:
> The checked-elements and it is an ObservableSet because Databinding
> can't guarantee the order which is an often forgotten nature of Lists.
>
> Tom
>
> Ed Merks schrieb:
>
>> Dennis,
>>
>> What's the Set supposed to contain?
>>
>>
>> Dennis Harmath wrote:
>>
>>> Hi,
>>> I want to bind the checkboxes of a CheckboxTreeViewer to a boolean
>>> property of EMF objects displayed by the tree with JFace/EMF
>>> databinding. How can I do this? I am aware of
>>> ViewerObservables.observeCheckedElements(), but it returns an
>>> IObservableSet, and I don't know any EMFObservables observer that
>>> returns that type. I would need an example to bind it to an EMF
>>> structural property... Thanks in advance,
>>> thSoft
>>>
>>>
>
>
>

--------------010404080502080405000801
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Tom,<br>
<br>
I see.
Re: CheckboxTreeViewer data binding with EMF [message #424120 is a reply to message #424119] Thu, 16 October 2008 13:44 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 4462
Registered: July 2009
Senior Member
Ed,

Right you need a Converter from List to Set and back. Fortunately this
is already possible.

Something like this might do the Job.

private boolean flag = false;

final IObservable list = EMFObservableList.observeDetailList(....);

final IObservableSet set = new WritableSet();
list.addListChangeListener(new ListChangeListener() {
public void listChanged(ListChangeEvent evt) {
if( flag )
return;

flag = true;

for( ListDiff diff: evt.diffs ) {
if( diff.add ) {
set.add(diff.value);
} else {
set.remove(diff.value);
}
}

flag = false;
}
});


set.addSetChangeListener( new SetChangeListener() {
public void setChanged(SetChangeEvent ev) {
for( SetDiff diff: evt.diffs ) {
if( diff.add ) {
list.add(diff.value);
} else {
list.remove(diff.value);
}
}
}
});


The class-names, listeners might not be correct but the idea should be
clear. The only real problem is IIRC that WritableSet is not available
as of 3.4 but got added in 3.5.

Tom


Ed Merks schrieb:
> Tom,
>
> I see. It sounds like the set of checked elements would need to be
> computed somehow anyway; it doesn't correspond directly to a feature.
> Some type of new hand utility class would be needed where
> adding/removing from the set would toggle some feature's state and
> listeners to the feature's state would add/remove the object from the
> set (all without getting into a loop).
>
>
> Tom Schindl wrote:
>> The checked-elements and it is an ObservableSet because Databinding
>> can't guarantee the order which is an often forgotten nature of Lists.
>>
>> Tom
>>
>> Ed Merks schrieb:
>>
>>> Dennis,
>>>
>>> What's the Set supposed to contain?
>>>
>>>
>>> Dennis Harmath wrote:
>>>
>>>> Hi,
>>>> I want to bind the checkboxes of a CheckboxTreeViewer to a boolean
>>>> property of EMF objects displayed by the tree with JFace/EMF
>>>> databinding. How can I do this? I am aware of
>>>> ViewerObservables.observeCheckedElements(), but it returns an
>>>> IObservableSet, and I don't know any EMFObservables observer that
>>>> returns that type. I would need an example to bind it to an EMF
>>>> structural property... Thanks in advance,
>>>> thSoft
>>>>
>>>>
>>
>>
>>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: CheckboxTreeViewer data binding with EMF [message #424121 is a reply to message #424120] Thu, 16 October 2008 13:45 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 4462
Registered: July 2009
Senior Member
Tom Schindl schrieb:
> Ed,
>
> Right you need a Converter from List to Set and back. Fortunately this
> is already possible.
>
> Something like this might do the Job.
>
> private boolean flag = false;
>
> final IObservable list = EMFObservableList.observeDetailList(....);
>
> final IObservableSet set = new WritableSet();
> list.addListChangeListener(new ListChangeListener() {
> public void listChanged(ListChangeEvent evt) {
> if( flag )
> return;
>
> flag = true;
>
> for( ListDiff diff: evt.diffs ) {
> if( diff.add ) {
> set.add(diff.value);
> } else {
> set.remove(diff.value);
> }
> }
>
> flag = false;
> }
> });
>
>
> set.addSetChangeListener( new SetChangeListener() {
> public void setChanged(SetChangeEvent ev) {
> for( SetDiff diff: evt.diffs ) {
> if( diff.add ) {
> list.add(diff.value);
> } else {
> list.remove(diff.value);
> }
> }
> }
> });
>
>

Oops looping.

set.addSetChangeListener( new SetChangeListener() {
public void setChanged(SetChangeEvent ev) {
if( flag )
return;

flag = true;

for( SetDiff diff: evt.diffs ) {
if( diff.add ) {
list.add(diff.value);
} else {
list.remove(diff.value);
}
}

flag = false;
}
});



> The class-names, listeners might not be correct but the idea should be
> clear. The only real problem is IIRC that WritableSet is not available
> as of 3.4 but got added in 3.5.
>
> Tom
>
>
> Ed Merks schrieb:
>> Tom,
>>
>> I see. It sounds like the set of checked elements would need to be
>> computed somehow anyway; it doesn't correspond directly to a feature.
>> Some type of new hand utility class would be needed where
>> adding/removing from the set would toggle some feature's state and
>> listeners to the feature's state would add/remove the object from the
>> set (all without getting into a loop).
>>
>>
>> Tom Schindl wrote:
>>> The checked-elements and it is an ObservableSet because Databinding
>>> can't guarantee the order which is an often forgotten nature of Lists.
>>>
>>> Tom
>>>
>>> Ed Merks schrieb:
>>>
>>>> Dennis,
>>>>
>>>> What's the Set supposed to contain?
>>>>
>>>>
>>>> Dennis Harmath wrote:
>>>>
>>>>> Hi,
>>>>> I want to bind the checkboxes of a CheckboxTreeViewer to a boolean
>>>>> property of EMF objects displayed by the tree with JFace/EMF
>>>>> databinding. How can I do this? I am aware of
>>>>> ViewerObservables.observeCheckedElements(), but it returns an
>>>>> IObservableSet, and I don't know any EMFObservables observer that
>>>>> returns that type. I would need an example to bind it to an EMF
>>>>> structural property... Thanks in advance,
>>>>> thSoft
>>>>>
>>>>>
>>>
>>>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: CheckboxTreeViewer data binding with EMF [message #424148 is a reply to message #424121] Fri, 17 October 2008 06:09 Go to previous messageGo to next message
Dénes Harmath is currently offline Dénes Harmath
Messages: 153
Registered: July 2009
Senior Member
Ed, Tom,
thanks for your quick and helpful response.
Fortunately WritableSet implementation is available 3.4.1 also.
The only missing link is the

final IObservable list = EMFObservableList.observeDetailList(....);

operation. I don't know what its IObservableValue value argument should
be, regarding I have a CheckboxTreeViewer and an EMF model. Any clues?

thSoft
Re: CheckboxTreeViewer data binding with EMF [message #424150 is a reply to message #424148] Fri, 17 October 2008 06:18 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 4462
Registered: July 2009
Senior Member
If you are not in master detail then EMFObservableList#observeList() is
the right one.

Tom

Dennis Harmath schrieb:
> Ed, Tom, thanks for your quick and helpful response.
> Fortunately WritableSet implementation is available 3.4.1 also.
> The only missing link is the
>
> final IObservable list = EMFObservableList.observeDetailList(....);
>
> operation. I don't know what its IObservableValue value argument should
> be, regarding I have a CheckboxTreeViewer and an EMF model. Any clues?
>
> thSoft
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: CheckboxTreeViewer data binding with EMF [message #424182 is a reply to message #424150] Mon, 20 October 2008 04:12 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 4462
Registered: July 2009
Senior Member
Sorry should be EMFObservables#observeList()

Tom

Tom Schindl schrieb:
> If you are not in master detail then EMFObservableList#observeList() is
> the right one.
>
> Tom
>
> Dennis Harmath schrieb:
>> Ed, Tom, thanks for your quick and helpful response.
>> Fortunately WritableSet implementation is available 3.4.1 also.
>> The only missing link is the
>>
>> final IObservable list = EMFObservableList.observeDetailList(....);
>>
>> operation. I don't know what its IObservableValue value argument should
>> be, regarding I have a CheckboxTreeViewer and an EMF model. Any clues?
>>
>> thSoft
>>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: CheckboxTreeViewer data binding with EMF [message #430127 is a reply to message #424182] Mon, 11 May 2009 14:52 Go to previous messageGo to next message
Salva is currently offline Salva
Messages: 29
Registered: July 2009
Junior Member
Hi,

I'm trying to do same, that is, binding a boolean property of my
EMFObjects to Check Boxes of a CheckBoxTreeViewer (All the elements showed
in the tree subclases the element with the boolean feature). I have follow
the explanations given by Tom Schindl but I don't know how to initialize
the ObservableList.

final IObservable list = EMFObservableList.observeDetailList(....);

I can't use EMFObservables.ObserveList(MyRoot, EStructuralFeature). It
throws an exception because a multivalued feature is expected and of
course my boolean feature isn't it. I'm a bit puzzled. ¿I am supposed to
build that list by hand?


Cheers!

Salva.
Re: CheckboxTreeViewer data binding with EMF [message #834440 is a reply to message #424120] Sun, 01 April 2012 20:23 Go to previous messageGo to next message
Wojciech Trocki is currently offline Wojciech Trocki
Messages: 64
Registered: May 2010
Member
Updated version (needs editing domain for model changes):

observableList.addListChangeListener(new IListChangeListener() {
@Override
public void handleListChange(ListChangeEvent evt) {
final ListDiffEntry[] differences = evt.diff.getDifferences();
for (final ListDiffEntry diff : differences) {
if (diff.isAddition()) {
editingDomain.getCommandStack().execute(
new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
set.add(diff.getElement());
}
});

} else {
editingDomain.getCommandStack().execute(
new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
set.remove(diff.getElement());
}
});
}
}
}
});

set.addSetChangeListener(new ISetChangeListener() {
@Override
@SuppressWarnings("rawtypes")
public void handleSetChange(SetChangeEvent evt) {
Set additions = evt.diff.getAdditions();
for (final Object object : additions) {
editingDomain.getCommandStack().execute(
new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
observableList.add(object);
}
});
}
Set removals = evt.diff.getRemovals();
for (final Object object : removals) {
editingDomain.getCommandStack().execute(
new RecordingCommand(editingDomain) {
@Override
protected void doExecute() {
observableList.remove(object);
}
});
}
}
});
Re: CheckboxTreeViewer data binding with EMF [message #834849 is a reply to message #834440] Mon, 02 April 2012 09:22 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 24549
Registered: July 2009
Senior Member
I imagine you'd want to composed all the differences into a single
command (so that a single undo undoes all the changes).

On 01/04/2012 5:23 PM, Wojciech Trocki wrote:
> Updated version (needs editing domain for model changes):
>
> observableList.addListChangeListener(new IListChangeListener() {
> @Override
> public void handleListChange(ListChangeEvent evt) {
> final ListDiffEntry[] differences = evt.diff.getDifferences();
> for (final ListDiffEntry diff : differences) {
> if (diff.isAddition()) {
> editingDomain.getCommandStack().execute(
> new RecordingCommand(editingDomain) {
> @Override
> protected void doExecute() {
> set.add(diff.getElement());
> }
> });
>
> } else {
> editingDomain.getCommandStack().execute(
> new RecordingCommand(editingDomain) {
> @Override
> protected void doExecute() {
> set.remove(diff.getElement());
> }
> });
> }
> }
> }
> });
>
> set.addSetChangeListener(new ISetChangeListener() {
> @Override
> @SuppressWarnings("rawtypes")
> public void handleSetChange(SetChangeEvent evt) {
> Set additions = evt.diff.getAdditions();
> for (final Object object : additions) {
> editingDomain.getCommandStack().execute(
> new RecordingCommand(editingDomain) {
> @Override
> protected void doExecute() {
> observableList.add(object);
> }
> });
> }
> Set removals = evt.diff.getRemovals();
> for (final Object object : removals) {
> editingDomain.getCommandStack().execute(
> new RecordingCommand(editingDomain) {
> @Override
> protected void doExecute() {
> observableList.remove(object);
> }
> });
> }
> }
> });
Previous Topic:EMF Commands vs GEF Commands
Next Topic:[EMF][Teneo][Transaction] what's the best way to combine them...
Goto Forum:
  


Current Time: Wed May 22 12:52:57 EDT 2013

Powered by FUDForum. Page generated in 0.05811 seconds