Hi,
I'm aware of multiple topics on the "DialogBox with a close button in
the caption" subject and multiple alternatives (other libraries
extending GWT) but I've got a question.
In my testing class I extended DialogBox like follows:
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
public class MyDialogBox extends DialogBox {
Cross cross = new Cross(); // Close button
HTML caption = new HTML(); // The caption aka title
HorizontalPanel captionPanel = new HorizontalPanel(); // Contains
caption and cross
private class crossHandler implements ClickHandler, MouseOverHandler,
MouseOutHandler
{
@Override
public void onClick(ClickEvent event) {
Object sender = event.getSource();
// Element e = event.getRelativeElement();
if(event.getRelativeElement() == cross.getElement())
{
Window.alert("get relative");
}
if(sender == cross)
{
hide();
}
}
@Override
public void onMouseOver(MouseOverEvent event) {
DOM.setStyleAttribute(cross.getElement(),
"font-weight", "bold");
}
@Override
public void onMouseOut(MouseOutEvent event) {
DOM.setStyleAttribute(cross.getElement(),
"font-weight", "normal");
}
}
private class Cross extends Label
{
crossHandler crosshandler = new crossHandler();
public Cross()
{
super("X");
addHandler(crosshandler, ClickEvent.getType());
this.sinkEvents(Event.ONCLICK);
this.getElement().dispatchEvent(evt);
}
}
/**
* Creates an empty dialog box. It should not be shown until its
child widget
* has been added using {...@link #add(Widget)}.
*/
public MyDialogBox()
{
this(false);
}
/**
* Creates an empty dialog box specifying its "auto-hide" property.
It should
* not be shown until its child widget has been added using
* {...@link #add(Widget)}.
*
* @param autoHide <code>true</code> if the dialog should be
automatically
* hidden when the user clicks outside of it
*/
public MyDialogBox(boolean autoHide) {
this(autoHide, true);
}
/**
* Creates an empty dialog box specifying its "auto-hide"
property. It should
* not be shown until its child widget has been added using
* {...@link #add(Widget)}.
*
* @param autoHide <code>true</code> if the dialog should be
automatically
* hidden when the user clicks outside of it
* @param modal <code>true</code> if keyboard and mouse events for
widgets not
* contained by the dialog should be ignored
*/
public MyDialogBox(boolean autoHide, boolean modal)
{
super(autoHide, modal);
DOM.setStyleAttribute(cross.getElement(), "background",
"green");
/* this.addDomHandler(crosshandler, ClickEvent.getType());
this.addHandler(crosshandler, ClickEvent.getType());
cross.addClickHandler(crosshandler);
cross.addMouseOutHandler(crosshandler);
cross.addMouseOverHandler(crosshandler);
*/
captionPanel.add(caption);
captionPanel.add(cross);
captionPanel.setStyleName("caption");
Element td = getCellElement(0, 1); // Get the cell element that
holds the caption
td.setInnerHTML(""); // Remove the old caption (FIXME: there's
probably a better way to do this)
td.appendChild(captionPanel.getElement());
}
@Override
public void setText(String text)
{
caption.setText(text);
}
public String getText()
{
return caption.getText();
}
public void setHtml(String html)
{
caption.setHTML(html);
}
public String getHtml()
{
return caption.getHTML();
}
The ClickEvent isn't fired from "cross" when it's clicked but it's
fired from the DialogBox.
Why does this happen?
Can I force the event to be fired from cross?
What line in DialogBox or its "super" causes this?
Please don't respond with the "Use the search" or "This has been
discussed before" answers I've seen on most of the threads on this
subject. I saw them, and these answers weren't helpful! This is more
of a question about the behavior of Events in GWT than about extending
DialogBox.
Do you know? Any input would be appreciated!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---