简体   繁体   English

从eventHandler中显示GWT对话框

[英]Displaying GWT DialogBox from within an eventHandler

I am trying to display a GWT DialogBox when I capture an exception by an event handler. 我试图通过事件处理程序捕获异常时显示GWT对话框。 The DialogBox does not display. 对话框不显示。 I've confirmed the event handler is called because 我已经确认事件处理程序被调用是因为

Window.alert("some msg") 

does display. 确实显示。 The DialogBox does display when I create it outside the event handler in a View object. 当我在View对象的事件处理程序之外创建对话框时,对话框确实会显示。 I assume the DialogBox does not have access to the current display. 我假设DialogBox无法访问当前显示。 Is there a way to get this displayed? 有没有办法显示这个?

Here is a code snippet: 这是一个代码片段:

eventBus.addHandler(ProcessingExceptionEvent.TYPE, new ProcessingExceptionEventHandler() {
    public void onProcessingException(ProcessingExceptionEvent event) {
        // Window.alert("some msg");
        final WiseAlertPanel errorAlert = new WiseAlertPanel("ERROR MESSAGE: " + event.getMessage());
        errorAlert.autoPositionAndShow();
    }
});

public class WiseAlertPanel extends DialogBox {
    VerticalPanel vpPopupl = new VerticalPanel();

    public WiseAlertPanel(String text) {
        setGlassEnabled(true);
        Button button = new Button("Close");
        button.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                WiseAlertPanel.this.hide();
            }
        });

        HorizontalPanel hPanel = new HorizontalPanel();
        hPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
        hPanel.add(button);

        TextArea label = new TextArea();
        label.setText(text);
        label.setReadOnly(true);
        label.setVisibleLines(5);

        vpPopupl.add(label);
        vpPopupl.add(hPanel);
        setWidget(vpPopupl);
    }

    public void autoPositionAndShow() {
        setPopupPositionAndShow(new PopupPanel.PositionCallback() {
            public void setPosition(int offsetWidth, int offsetHeight) {
                int left = (Window.getClientWidth() - offsetWidth) / 3;
                int top = (Window.getClientHeight() - offsetHeight) / 3;
                WiseAlertPanel.this.setPopupPosition(left, top);
            }
        });
    }

Looks like you have just create the DialogBox "WiseAlertPanel errorAlert" in memory. 看起来您刚刚在内存中创建了对话框“ WiseAlertPanel errorAlert”。

Try call the show method in "autoPositionAndShow" like below 尝试如下所示在“ autoPositionAndShow”中调用show方法

public void autoPositionAndShow() {
    setPopupPositionAndShow(new PopupPanel.PositionCallback() {
        public void setPosition(int offsetWidth, int offsetHeight) {
            int left = (Window.getClientWidth() - offsetWidth) / 3;
            int top = (Window.getClientHeight() - offsetHeight) / 3;
            WiseAlertPanel.this.setPopupPosition(left, top);
            show();
        }
    });
}

Reference GWT DialogBox show() 参考GWT对话框show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM