Just wrapping it is not going to work, as just HTML doesn't place the
widget in GWT's widget hierarchy.  I don't think the clickhandler
should even work?  You need to have the dialog adopt your "widget".

FYI here's my working sol'n for getting a close button in the upper
left corner, just extending DialogBox:

/**
* Adopted from http://code.google.com/p/synthfuljava/, at
* 
http://code.google.com/p/synthfuljava/source/browse/trunk/gwt/widgets/org/synthful/gwt/widgets/client/ui/ScrollableDialogBox.java
*/
public abstract class ClosableDialog extends DialogBox
{
    private HorizontalPanel m_captionPane;
    private Button m_closeBut;
    private CaptionTitle m_titleHTML;

    protected class CaptionTitle extends HTML implements Caption {}

    public ClosableDialog() {this(false);}

    public ClosableDialog(boolean autoHide) {this(autoHide, true);}

    public ClosableDialog(boolean autoHide, boolean modal)
    {
        super(autoHide, modal);

        m_captionPane = new HorizontalPanel();
        m_captionPane.setStyleName("Caption");
        m_captionPane.setWidth("100%");
 
m_captionPane.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);

        Element td01 = getCellElement(0, 1);
        Widget caption = (Widget)this.getCaption();
        DOM.removeChild(td01, caption.getElement());
        DOM.appendChild(td01, this.m_captionPane.getElement());
        adopt(m_captionPane);

        m_titleHTML = new CaptionTitle();

        m_captionPane.add(this.m_titleHTML);
        m_captionPane.setCellWidth(m_titleHTML, "100%");

        m_closeBut = new Button("X");

        m_captionPane.add(this.m_closeBut);
    }


    @Override
    public String getHTML() {return m_titleHTML.getHTML();}

    @Override
    public String getText() {return m_titleHTML.getText();}

    @Override
    public void setHTML(String html) {m_titleHTML.setHTML(html);}

    @Override
    public void setText(String text) {m_titleHTML.setText(text);}

    protected boolean isCaptionControlEvent(NativeEvent event)
    {
        return isWidgetEvent(event, this.m_captionPane.getWidget(1));
    }

    static protected boolean isWidgetEvent(NativeEvent event, Widget
w)
    {
        EventTarget target = event.getEventTarget();
        if (Element.is(target))
        {
            boolean t =
w.getElement().isOrHasChild(Element.as(target));
            return t;
        }
        return false;
    }

    @Override
    public void onBrowserEvent(Event event)
    {
        if (isCaptionControlEvent(event))
        {
            switch (event.getTypeInt())
            {
            case Event.ONMOUSEUP:
            case Event.ONCLICK:
                hide();
                break;
            }
        }
        super.onBrowserEvent(event);
    }
}

On Apr 16, 4:00 am, David <[email protected]> wrote:
> I wanted to add a Label with ClickHandler to the title of a
> DialogBox.
> There is no direct support for adding widgets to the titlebar, but
> there is support for HTML.
>
> I tried out a little trick - before going on a queste to replace yet
> another widget in GWT:
>
> I use this as a content for the title:
> "<div style='float:right' id='helpid'>Help</div> The title"
>
> in the onload of my customized dialog I wrap the helpid div into a
> Label widget and then attach a ClickHandler.
> This seems to work fine except in DevMode where I get an assertion
> error:
>
> java.lang.AssertionError: A widget that has an existing parent widget
> may not be added to the detach list
>         at
> com.google.gwt.user.client.ui.RootPanel.detachOnWindowClose(RootPanel.java:
> 136)
>         at com.google.gwt.user.client.ui.Label.wrap(Label.java:79)
>         at com.acme.gwt.widget.client.ActionDialog.onLoad(ActionDialog.java:
> 166)
>         at com.google.gwt.user.client.ui.Widget.onAttach(Widget.java:294)
>         at com.google.gwt.user.client.ui.Widget.setParent(Widget.java:417)
>         at com.google.gwt.user.client.ui.Panel.adopt(Panel.java:119)
>         at com.google.gwt.user.client.ui.ComplexPanel.add(ComplexPanel.java:
> 93)
>         at com.google.gwt.user.client.ui.AbsolutePanel.add(AbsolutePanel.java:
> 75)
>         at com.google.gwt.user.client.ui.PopupPanel
> $ResizeAnimation.onInstantaneousRun(PopupPanel.java:311)
>         at com.google.gwt.user.client.ui.PopupPanel
> $ResizeAnimation.setState(PopupPanel.java:208)
>         at com.google.gwt.user.client.ui.PopupPanel.setState(PopupPanel.java:
> 1374)
>         at com.google.gwt.user.client.ui.PopupPanel.show(PopupPanel.java:969)
>         at com.google.gwt.user.client.ui.DialogBox.show(DialogBox.java:347)
>         at com.acme.gwt.widget.client.ActionDialog.show(ActionDialog.java:
> 226)
>         at com.google.gwt.user.client.ui.PopupPanel.center(PopupPanel.java:
> 488)
>
> Am I not allowed to use this wrap method in such scenario ? Is there
> an alternative to the restricted DialogBox ? Or is this a bug in the
> wrap method for which I should file an incident report ?
>
> David
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/google-web-toolkit?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to