MenuItem - setCommand always includes a ToggleCommand

10 views
Skip to first unread message

Alan Hadsell

unread,
Jun 15, 2010, 3:56:54 PM6/15/10
to GWTLib
Sander --

I was just looking over the source of MenuItem, and noticed that the
setCommand() method always wraps the supplied command in a
ToggleCommand. Shouldn't this be conditioned on something like a
Type.TOGGLE? (I know there is no such type, but...)

Just curious about the reason for this. I'm writing some new code
that will make use of the setCommand() method, and the ToggleCommand
might interfere with what I'm doing.

Regards,
Alan Hadsell

Sander Berents

unread,
Jun 16, 2010, 6:49:33 PM6/16/10
to gwt...@googlegroups.com
Hi Alan,

I wrap it to support the menu item toggling (radio & check) while still just subclassing the GWT MenuItem. You should be able to use setCommand as usual. getCommand will always return a ToggleCommand though, containing the original command, or when the menu item is disabled a dummy command.

Sander

> --
> You received this message because you are subscribed to the Google Groups "GWTLib" group.
> To post to this group, send email to gwt...@googlegroups.com.
> To unsubscribe from this group, send email to gwtlib+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/gwtlib?hl=en.
>

Alan Hadsell

unread,
Jun 16, 2010, 9:06:57 PM6/16/10
to GWTLib


On Jun 16, 6:49 pm, Sander Berents <sanderbere...@gmail.com> wrote:

> I wrap it to support the menu item toggling (radio & check) while still just subclassing the GWT MenuItem. You should be able to use setCommand as usual. getCommand will always return a ToggleCommand though, containing the original command, or when the menu item is disabled a dummy command.

OK. I worry, though, about the additional overhead from creating a
new ToggleCommmand for each call to setCommand. Maybe we could come
up with a way that would avoid the need for same; for instance, we
could keep an instance variable to remember the ToggleCommand, so that
when we need to turn it back on we can re-use the old one. We could
also add a ToggleCommand.setCommand method, to allow the "inner"
command to be changed when MenuItem.setCommand is called.

Want me to take a hack at the changes I'm talking about and send them
to you?

Regards,
Alan Hadsell

Sander Berents

unread,
Jun 17, 2010, 8:45:17 AM6/17/10
to gwt...@googlegroups.com
You are right, we don't need to create a *new* ToggleCommand every time setCommand is being called. Please go ahead with the changes.

Thanks,

Sander

Reply all
Reply to author
Forward
0 new messages