Extending dialog box to have a close button

134 views
Skip to first unread message

Simal

unread,
Jul 3, 2008, 4:27:43 PM7/3/08
to Google Web Toolkit
Hi all,

Previously, with GWT 1.4, I was extending "DialogBox" class to have a
close button in the caption area. To get a handle to the caption and
override it, I was using:
FlexTable dialogPanel = (FlexTable) super.getWidget();
Image closeImg = new Image("imageUrl");
dialogPanel.setWidget(0, 1, closeImg);

However, with GWT 1.5, I see that the internal structure of the
DialogBox has changed. The dialog no longer contains a FlexTable
panel, so I cannot really set whatever widget I want to.

Is there anyone who faces this problem and/or has any suggestions?

Thanks,
Simal

Kurposkano

unread,
Jul 3, 2008, 5:09:44 PM7/3/08
to Google Web Toolkit
Do you have to stick the close button in that exact spot? Can't you
just create a button anywhere inside of the Dialog Box and have it do
the closing?

krishna

unread,
Jul 4, 2008, 12:18:39 AM7/4/08
to Google Web Toolkit

Hi Simal,

You can make it work without extending DialogBox (somewhat).

...
final DialogBox dialogBox = new DialogBox();
dialogBox.setHTML("Your Caption<img style=\"margin-top:
0px;cursor:pointer;cursor:hand\" src=\"close.png\" onclick=
\"closeDialog()\"></img>");
redefineClose(dialogBox);
...
...

// Define closeDialog using JSNI
private native void redefineClose(DialogBox dialogBox) /*-{
$wnd['closeDialog'] = function () {
dialogBox.@com.google.gwt.user.client.ui.DialogBox::hide()();
}
}-*/;


Code will not work if you have more than one dialog at a time, since
we redefine the close method each time a new dialog is created.


Regards,
Krishna

Simal

unread,
Jul 8, 2008, 2:57:09 PM7/8/08
to Google Web Toolkit
Thanks Krishna! Looks like it is working.

I try to avoid the usage of JSNI but I think in this case it is very
helpful.
Another thing.. I don't understand why it is not working when I have
more than one dialog at a time. I am redefining the close method for
each dialog I create, right? So, why doesn't each dialog close the way
it is defined?

- Simal

On Jul 4, 12:18 am, krishna <krishnakum...@gmail.com> wrote:
> HiSimal,
>
> You can make it work without extending DialogBox (somewhat).
>
> ...
> final DialogBox dialogBox = new DialogBox();
> dialogBox.setHTML("Your Caption<img style=\"margin-top:
> 0px;cursor:pointer;cursor:hand\" src=\"close.png\" onclick=
> \"closeDialog()\"></img>");
> redefineClose(dialogBox);
> ...
> ...
>
> // Define closeDialog using JSNI
> private native void redefineClose(DialogBox dialogBox) /*-{
>    $wnd['closeDialog'] = function () {
>        dialogB...@com.google.gwt.user.client.ui.DialogBox::hide()();
>    }
>
> }-*/;
>
> Code will not work if you have more than one dialog at a time, since
> we redefine the close method each time a new dialog is created.
>
> Regards,
> Krishna
>

Scott

unread,
Jul 10, 2008, 4:24:20 PM7/10/08
to Google Web Toolkit
Simal,

The *same* method is being redefined each time you create a dialog.
Think of it as a static reference to an instance of a dialog box; each
time you modify the static reference, each of the dialogs can only
close the most recently created dialog.

I'm working on a similar problem with a solution that will hopefully
be a little prettier, and I'll try to post it once I get it working.

Regards,
Scott
Reply all
Reply to author
Forward
0 new messages