[Databinding] Bind TextArea to EMF Collection (EList) ? [message #333661] |
Sun, 21 December 2008 16:54  |
Eclipse User |
|
|
|
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 #333665 is a reply to message #333662] |
Mon, 22 December 2008 01:04  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.02999 seconds