Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [Databinding] Bind TextArea to EMF Collection (EList) ?
[Databinding] Bind TextArea to EMF Collection (EList) ? [message #333661] Sun, 21 December 2008 21:54 Go to next message
Florian Georg is currently offline Florian GeorgFriend
Messages: 27
Registered: July 2009
Junior Member
Hi,

how do I bind multiple lines of text in a SWT Text to an EMF
EStructuralFeature that is multivalued, e.g. uses an EList?
What I want to do is to split the text string and bind it to the list.


I tried a EMFValueObservable and had no luck... also "list" Observables
won't work, as source is a SWT Text (single String value) and target is
EStructuralFeature (EList).

I also tried to use a converter that converts the text string to/from
BasicEListImpl, but get some errors... perhaps there's something i forgot?


Any hint how to do that trick?

thanks & kind regards,
Florian
Re: [Databinding] Bind TextArea to EMF Collection (EList) ? [message #333662 is a reply to message #333661] Mon, 22 December 2008 02:03 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33188
Registered: July 2009
Senior Member
Florian,

I imagine you'll need to create your own observable value implementation
that converts the list of values to a multi-line string and back again.
There's nothing built-in to do this...


Florian Georg wrote:
> Hi,
>
> how do I bind multiple lines of text in a SWT Text to an EMF
> EStructuralFeature that is multivalued, e.g. uses an EList?
> What I want to do is to split the text string and bind it to the list.
>
>
> I tried a EMFValueObservable and had no luck... also "list"
> Observables won't work, as source is a SWT Text (single String value)
> and target is EStructuralFeature (EList).
>
> I also tried to use a converter that converts the text string to/from
> BasicEListImpl, but get some errors... perhaps there's something i
> forgot?
>
>
> Any hint how to do that trick?
>
> thanks & kind regards,
> Florian


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Databinding] Bind TextArea to EMF Collection (EList) ? [message #333665 is a reply to message #333662] Mon, 22 December 2008 06:04 Go to previous message
Matthew Hall is currently offline Matthew HallFriend
Messages: 368
Registered: July 2009
Senior Member
Here's an approach that _may_ work. Create a detail observable list
from using the SWTObservables.observeText(text) observable as the master:

Text text = ..
final IObservableValue text_text = SWTObservables.observeText(text,
SWT.Modify);
IObservableList text_lines = MasterDetailObservables.detailList(
text_text,
new IObservableFactory() {
public IObservable createObservable(Object target) {
String[] lines = ((String)target).split("\n");
final IObservableList list = new WritableList();
list.addAll(Arrays.asList(lines));

// Here you must add a list change listener to list so that
// any changes pushed to the inner observable list cause the
// lines to be spliced and the result set as the value of
// text_text
list.addListChangeListener(new IListChangeListener() {
public void handleListChange(ListChangeEvent) {
String[] lines = (String[])list.toArray(
new String[list.size()]);
StringBuilder b = new StringBuilder();
for (int i = 0; i < lines.length; i++) {
if (i > 0) b.append("\n");
b.append(lines[i]);
}
text_text.setValue(b.toString());
}
}
// In theory this should not cause an infinite loop since a
// change in the master observable will cause the inner
// observable to be immediately disposed and a new inner
// observable to be created

return list;
}
},
String.class);

At this point your should be able to bind text_lines directly to your
EList structural feature.

Hope this helps,

Matthew

Ed Merks wrote:
> Florian,
>
> I imagine you'll need to create your own observable value implementation
> that converts the list of values to a multi-line string and back again.
> There's nothing built-in to do this...
>
>
> Florian Georg wrote:
>> Hi,
>>
>> how do I bind multiple lines of text in a SWT Text to an EMF
>> EStructuralFeature that is multivalued, e.g. uses an EList?
>> What I want to do is to split the text string and bind it to the list.
>>
>>
>> I tried a EMFValueObservable and had no luck... also "list"
>> Observables won't work, as source is a SWT Text (single String value)
>> and target is EStructuralFeature (EList).
>>
>> I also tried to use a converter that converts the text string to/from
>> BasicEListImpl, but get some errors... perhaps there's something i
>> forgot?
>>
>>
>> Any hint how to do that trick?
>>
>> thanks & kind regards,
>> Florian
Previous Topic:How to disable Popupmenu dynamically
Next Topic:Editing Manifest programmatically
Goto Forum:
  


Current Time: Sat Jul 27 12:35:38 GMT 2024

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

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

Back to the top