UiCommandBindingBuilder - bindEndalbed() / Watermark restricted to TextBox

12 views
Skip to first unread message

RAlfoeldi

unread,
Jul 24, 2010, 4:33:13 PM7/24/10
to GWT Pectin
Hi Andrew,

first of all thanks for building (and opensourcing) a great framework
that is definitely worth "a bottle of wine" :-)

I've noticed one or two details where I don't understand the
motivation for certain limitations.

You've restricted binding a UiCommand to either a FocusWidget or an
instance of HasEnabled (UiCommandBindingBuilder.bindEnabled()) and
throw an Exception if the HasClickHandler button isn't one of these
two. If I want to bind a UiCommand to an Image which implements
HasClickHandlers I get kicked out. If you leave out the Exception an
Image would work as a charm.

Same thing with WaterMark. MetadataManager.onWidgetBinding() will only
bind a watermark to an instance of TextBox. Anything that's not an
instance of TextBox doesn't get hooked up. Wouldn't a check for
HasText or HasValue<String> and HasAllFocusHandlers work out as well?
Then you could watermark more complex widgets that support Strings?

Just nitpicking a great project ...

Greetings from Bern

Rainer

Andrew Pietsch

unread,
Jul 24, 2010, 11:09:35 PM7/24/10
to gwt-pecti...@googlegroups.com
Hi Rainer,

first of all thanks for building (and opensourcing) a great framework
that is definitely worth "a bottle of wine" :-)

You're welcome, and thanks for you donation, it's always nice to get them.  I'll have to get ambitious an suggest it might be worth two bottles (c:

I've noticed one or two details where I don't understand the
motivation for certain limitations.

You've restricted binding a UiCommand to either a FocusWidget or an
instance of  HasEnabled (UiCommandBindingBuilder.bindEnabled()) and
throw an Exception if the HasClickHandler button isn't one of these
two. If I want to bind a UiCommand to an Image which implements
HasClickHandlers I get kicked out. If you leave out the Exception an
Image would work as a charm.
 
This is mainly because I've been bitten by the case where I was using a third party button and spent ages trying to find the bug in my condition logic but it was actually that the button wasn't the correct type (and the binding was silently ignoring it).  There are other cases in pectin where types are silently ignored (and I'm happy with that) so I think in this case the issue needs a bit more thought.

There are a couple of options here, I could remove automatic binding of enabled state from the binder (i.e. make binding the enabled state an additional operation), or add an option for binding only the click aspect.  Version 0.8 has syntax of the form bind(value).toTextOf(HasText) so something like bind(Command).toClicksOf(HasClickHandlers) might be the way to go (in conjunction with the existing bind(command).to(HasClickHandlers) method that would barf if enabled can't be bound).  The latter would be nice too since it would work with plain old Commands.  There would also be scope here to bind commands to other events like key events, focus & blur etc.

Same thing with WaterMark. MetadataManager.onWidgetBinding() will only
bind a watermark to an instance of TextBox. Anything that's not an
instance of TextBox doesn't get hooked up. Wouldn't a check for
HasText or HasValue<String> and HasAllFocusHandlers work out as well?
Then you could watermark more complex widgets that support Strings?

Watermarks were a bit of a "quick make it go" feature that haven't been subsequently improved.  I'm not sure if I'm able to bind to a HasValue<String> since the binding callbacks have to make this check at runtime.   HasText in conjunction with HasAllFocusHandlers would probably work ok.  There's an issue (8) against them to "make them better" but I need to revisit it and have a bit more of a think about it.  I had thinking about a HasWatermark style interface for widgets but I'm not yet clear on how it should work (should the widget be responsible for tracking focus etc or should pectin do it as it currently does - the latter is easy for implementing the interface, but feels not quite right).  Ultimately it would be nice things like style/image based watermarks as well as support for HTML 5 placeholder text.

Cheers
Andrew

RAlfoeldi

unread,
Jul 26, 2010, 12:04:15 PM7/26/10
to GWT Pectin
Hi Andrew,

thanks for the answer. You obviously had good reasons for your
approach.

I've extended Image (the object I wanted to bind the UiCommand to) to
implement HasEnabled and... its probably even the better approach now
(all the wizbang with opacity etc. nicely wrapped up)

Extending Watermark to support HasText and HasAllFocusHandlers would
be really cool. I - and probably a lot of other people - have wrapped
TextBox, etc. in more complex widgets with integrated name, error
message, icons, etc. => No watermarks :-(

Greeting from Zürich

Rainer

Andrew

unread,
Jul 27, 2010, 2:45:43 AM7/27/10
to GWT Pectin


On Jul 27, 2:04 am, RAlfoeldi <ralfoe...@gmail.com> wrote:
> Hi Andrew,
>
> thanks for the answer. You obviously had good reasons for your
> approach.
>
> I've extended Image (the object I wanted to bind the UiCommand to)  to
> implement HasEnabled and... its probably even the better approach now
> (all the wizbang with opacity etc. nicely wrapped up)

Cool, at some point I hope to get around to adding bindings like
binder.onClicking(HasClickHandlers).invoke(Command) so this scenario
can be supported without a full bind to a UiCommand. Such an approach
would also work with things like onBlur(..).invoke(..) etc too.

>
> Extending Watermark to support HasText and HasAllFocusHandlers would
> be really cool. I - and probably a lot of other people - have wrapped
> TextBox, etc. in more complex widgets with integrated name, error
> message, icons, etc. => No watermarks :-(

After looking at it this is actually a bit harder since HasText isn't
observable and it becomes a bit weird if I'm binding to a
HasValue<String> but sending the watermark to the HasText interface
method. Since you're working with a custom widget anyway a new
interface is probably a better way to go. Possibly a HasWatermarkText
interface where the widget is responsible for displaying it, and
perhaps something like `interface Watermarkable extends
HasValue<String>, HasAllFocusHandlers` where the bindings can do it
automatically.

Would that work for you?

RAlfoeldi

unread,
Jul 27, 2010, 9:36:43 AM7/27/10
to GWT Pectin
Hi Andrew,

why ask? The way I see it (r680) its already done! Gee, you're fast
and I'm impressed.

I'm sure that will work, even if I don't have the time right now to
check/implement.

Greetings and thanks from Bern again (Switzerland is small and has a
great railway system....)

Andrew

unread,
Jul 27, 2010, 7:56:22 PM7/27/10
to GWT Pectin
On Jul 27, 11:36 pm, RAlfoeldi <ralfoe...@gmail.com> wrote:
> Hi Andrew,
>
> why ask? The way I see it (r680) its already done! Gee, you're fast
> and I'm impressed.

I'm spending a couple of days trying to get 0.8 out the door so you
caught me at a good time.

> I'm sure that will work, even if I don't have the time right now to
> check/implement.

It's not exhaustively tested but I refactored the existing
implementation to wrap the TextBox in a Watermarkable so it should
work.

> Greetings and thanks from Bern again (Switzerland is small and has a
> great railway system....)

I had a quick look at Bern in google maps and it's looks to be quite a
beautiful city. Australia is large so I've been in Melbourne the
whole time (c:

Cheers
Reply all
Reply to author
Forward
0 new messages