Home » Eclipse Projects » Eclipse Platform » [DataBinding] Binding to map Entries like in JSF possible?
[DataBinding] Binding to map Entries like in JSF possible? [message #311589] |
Wed, 17 January 2007 07:51  |
Eclipse User |
|
|
|
Hi,
in JSF it is possible to bind a property of a UI Control to a Map Entry.
Example:
JSP:
<f:label ... value="#{myController.labelMap.label1}"...>
<f:label ... value="#{myController.labelMap.label2}"...>
<f:label ... value="#{myController.labelMap.label3}"...>
Controller:
private Map labelMap;
public Map getLabelMap() {
if (labelMap == null) {
initLabels();
}
return labelMap;
}
private void initLabels() {
labelMap = new Hashtable();
labelMap.put("label1", "Some Label");
labelMap.put("label2", "The next Label");
labelMap.put("label3", "And so on");
}
Is there any opportunity with the Databinding Framework to do anything
similar? The example with the labels is only an example, I want to use it
for some other behaviour (setting boolean flags for enabling/disabling UI
Controls like Text, Combos, ...).
regards
Wolfgang
|
|
| |
Re: [DataBinding] Binding to map Entries like in JSF possible? [message #311611 is a reply to message #311596] |
Thu, 18 January 2007 02:30   |
Eclipse User |
|
|
|
"Brad Reynolds" <bradleyjames@gmail.com> schrieb im Newsbeitrag
news:613cb789983bbd973eeb48bc83fae7a0$1@www.eclipse.org...
> We don't currently supporting bindings to maps but you can observe changes
> in maps. But I think you're referring to the JSP/JSTL expression
> language. We don't have support for the expression language.
>
> -brad
>
What I really wanted to do is something like this:
SWT:
text1 = new Text(parent, SWT.SINGLE|SWT.BORDER|SWT.LEFT);
text2 = new Text(parent, SWT.SINGLE|SWT.BORDER|SWT.LEFT);
text3 = new Text(parent, SWT.SINGLE|SWT.BORDER|SWT.LEFT);
dbc.bindValue(SWTObservables.observeEnabled(text1),
SomeObservableConstruct(enabledStateMap,"text1"), null);
dbc.bindValue(SWTObservables.observeEnabled(text2),
SomeObservableConstruct(enabledStateMap,"text2"), null);
dbc.bindValue(SWTObservables.observeEnabled(text3),
SomeObservableConstruct(enabledStateMap,"text3"), null);
// somewhere else in the code:
enabledStateMap.put("text1", someBooleanValue);
|
|
| | | |
Re: [DataBinding] Binding to map Entries like in JSF possible? [message #314941 is a reply to message #314936] |
Sun, 29 April 2007 10:22   |
Eclipse User |
|
|
|
I have developed the observable and named it MapEntryObservableValue. It
is quite a simple beast, as you said it would be. Nevertheless, there
are some complications surrounding it:
1. As I wrote a test for my class, I discovered a bug in WritableMap
where the old and new value are reversed:
public Object put(Object key, Object value) {
checkRealm();
Object result = wrappedMap.put(key, value);
if (result==null) {
fireMapChange(Diffs.createMapDiffSingleAdd(key, value));
} else {
fireMapChange(Diffs.createMapDiffSingleChange(key, value, result));
BUG --> ^^^^^^^^^^^^^
}
return result;
}
2. In order to be able to create an IObservableMap from a client's
already existing map, I had to add constructors to the WritableMap:
public WritableMap(Map mapToWrap) {
super(Realm.getDefault(), mapToWrap);
}
public WritableMap(Realm realm, Map mapToWrap) {
super(realm, mapToWrap);
}
I wonder if there was an important reason not to include such
constructors in the first place -- I hope not because without them the
WritableMap is useless for my purpose.
3. In my current design I require the client to wrap his map into an
IObservableMap before calling Observables.observeMapEntry. The
motivation for this is to allow the same Writable map to be reused in
more than one MapEntryObservableValue. Otherwise the client would not
have a single WritableMap that he can use to programmatically manipulate
it. I am not sure whether this is perfectly alright as API design.
4. I am not confident about the placement of the new stuff. I reasoned
that since my observable has no dependencies outside the JDK and core
Databinding, it belongs into org.eclipse.core.databinding. Accordingly,
I have placed a new static factory method inside Observables.
5. How should I proceed with all this stuff? I suppose I should file
three entries to Bugzilla:
1. A bug report concerning 1. above;
2. An enhancement request concerning 2. above;
3. An enhancement request concerning the new observable.
With each entry I would of course submit the relevant patches.
Marko Topolnik, Ph.D.
CROZ d.o.o.
mtopolnik@croz.net
Brad Reynolds wrote:
>> Has there been any activity regarding this issue?
>
> No and I don't remember seeing a bug logged.
>
>> I have encountered the same requirement in my project and if noone has
>> already started working on this, I might be up to making such an
>> observable.
>
> That would be great.
>
> -brad
|
|
|
Re: [DataBinding] Binding to map Entries like in JSF possible? [message #314995 is a reply to message #314941] |
Mon, 30 April 2007 22:07   |
Eclipse User |
|
|
|
Marko Topolnik wrote:
> I have developed the observable and named it MapEntryObservableValue. It
> is quite a simple beast, as you said it would be. Nevertheless, there
> are some complications surrounding it:
>
> 1. As I wrote a test for my class, I discovered a bug in WritableMap
> where the old and new value are reversed:
>
> public Object put(Object key, Object value) {
> checkRealm();
> Object result = wrappedMap.put(key, value);
> if (result==null) {
> fireMapChange(Diffs.createMapDiffSingleAdd(key, value));
> } else {
> fireMapChange(Diffs.createMapDiffSingleChange(key, value, result));
> BUG --> ^^^^^^^^^^^^^
> }
> return result;
> }
Yep, it's a bug and it's fixed. Thanks.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=184817
Feel free to log the bug when you find it. I got this in for 3.3M7 but
just barely. If it ends up not being a bug that's OK.
> 2. In order to be able to create an IObservableMap from a client's
> already existing map, I had to add constructors to the WritableMap:
>
> public WritableMap(Map mapToWrap) {
> super(Realm.getDefault(), mapToWrap);
> }
>
> public WritableMap(Realm realm, Map mapToWrap) {
> super(realm, mapToWrap);
> }
>
> I wonder if there was an important reason not to include such
> constructors in the first place -- I hope not because without them the
> WritableMap is useless for my purpose.
The reason is probably that it was overlooked. We can't add it at the
moment as we're in an API freeze so this won't get added for 1.0. You
should be able to just iterate over the keys of your existing map and
add them to the new with put(...). It's tedious but it will still
accomplish your goal.
> 5. How should I proceed with all this stuff? I suppose I should file
> three entries to Bugzilla:
>
> 1. A bug report concerning 1. above;
>
> 2. An enhancement request concerning 2. above;
>
> 3. An enhancement request concerning the new observable.
I say just log 3 and include 2 in your patch. I like it all in one for
the context and to be able to trace why the API was for 2 needed. It's
probably not a big deal but that's how I'd do it. I say once you do
that and things slow down we'll be able to give you some feedback.
Right now we're in an API freeze as we're trying to get Eclipse 3.3, and
JFace Data Binding 1.0, out the door.
-brad
|
|
|
Re: [DataBinding] Binding to map Entries like in JSF possible? [message #315006 is a reply to message #314995] |
Tue, 01 May 2007 05:50   |
Eclipse User |
|
|
|
> Yep, it's a bug and it's fixed. Thanks.
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=184817
>
> Feel free to log the bug when you find it. I got this in for 3.3M7 but
> just barely. If it ends up not being a bug that's OK.
OK, sorry, next time I'll be more trigger-happy :)
>> I wonder if there was an important reason not to include such
>> constructors in the first place -- I hope not because without them the
>> WritableMap is useless for my purpose.
>
> The reason is probably that it was overlooked. We can't add it at the
> moment as we're in an API freeze so this won't get added for 1.0. You
> should be able to just iterate over the keys of your existing map and
> add them to the new with put(...). It's tedious but it will still
> accomplish your goal.
You mean, if I have a Contact bean with a map for several emails, I
would write something like this:
WritableMap wMap = new WritableMap();
.... bind wMap to the GUI
.... let the GUI run
.... and when the user commits the changes:
for (Map.Entry<String, String> entry :
(Set<Map.Entry<String, String>>) wMap.entrySet())
{
contact.setEmail(entry.getKey(), entry.getValue());
}
I suppose this will work OK for a number of situations, but it requires
special processing on commit, which would not be necessary if the bean's
map was bound to the GUI directly.
Anyway, I hoped that "API freeze" meant "no API-breaking changes, but
API extensions are OK." If not, then the addition of the
MapEntryObservableValue class and a method to the existing Observables
class are also against the API freeze rule, making this whole
contribution out of scope for 1.0.
>> 5. How should I proceed with all this stuff? I suppose I should file
>> three entries to Bugzilla:
>>
>> 1. A bug report concerning 1. above;
>>
>> 2. An enhancement request concerning 2. above;
>>
>> 3. An enhancement request concerning the new observable.
>
> I say just log 3 and include 2 in your patch. I like it all in one for
> the context and to be able to trace why the API was for 2 needed. It's
> probably not a big deal but that's how I'd do it.
Yes, I agree. In fact, I came to the same conclusion the minute I
submitted my post. Here is the enhancement request:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=184830
Marko Topolnik, Ph.D.
CROZ d.o.o.
mtopolnik@croz.net
|
|
| |
Re: [DataBinding] Binding to map Entries like in JSF possible? [message #315117 is a reply to message #315115] |
Thu, 03 May 2007 04:10  |
Eclipse User |
|
|
|
Brad Reynolds wrote:
> > Anyway, I hoped that "API freeze" meant "no API-breaking changes, but
>> API extensions are OK." If not, then the addition of the
>> MapEntryObservableValue class and a method to the existing Observables
>> class are also against the API freeze rule, making this whole
>> contribution out of scope for 1.0.
>
> API freeze means no new API. So no, this won't be in 1.0 but it'll be
> there for 1.1.
>
> -brad
Now that I reread my words, they sound kind of belligerent :) What I
wanted to say is that the missing constructors in WritableMap pose no
problem after all because they'll be allowed into the API at the same
time as all the rest of this stuff.
--
Marko Topolnik, Ph.D.
CROZ d.o.o.
mtopolnik@croz.net
|
|
|
Goto Forum:
Current Time: Sat Sep 27 00:03:22 EDT 2025
Powered by FUDForum. Page generated in 0.28710 seconds
|