关闭对话框后,GWT按钮保持禁用状态

时间:2013-03-25 14:00:22

标签: java gwt

我有一个按钮,用我的控件按钮状态装饰用户ClickHandler - >使其在点击时禁用,防止多次点击。当用户点击它时 - 打开相应的DialogBox并禁用按钮。这是我的按钮:

public class MyButton extends Button {
    private boolean isButtonClicked = false;
    private ClickHandler clickHandler;

    public MyButton(String html) {
        this(html, null);
    }

    public MyButton(String html, final ClickHandler handler) {
        super(html);
        addClickHandler(handler);
    }

    public HandlerRegistration addClickHandler(final ClickHandler handler) {
        clickHandler = handler;

        ClickHandler ch = new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                if(!isButtonClicked) {
                    isButtonClicked = true;
                    setEnabled(false);
                    clickHandler.onClick(event); //Here is a click handler initiated on fly
                }
            }
        };
        return super.addClickHandler(ch);
    }
}

这就是它的用法:

public TestClass {
    protected OneClickButton button = new OneClickButton("Test Button);

    //...

    button.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                SomeDialogWindow dialog = new SomeDialogWindow(/*args*/);
                dialog.center();
            }
        });
}

当我点击某个按钮时,它会被禁用并出现对话框。但是当我关闭对话框时,我的按钮仍处于禁用状态。如何在关闭对话框时设置按钮启用?为了达到这个目的,我应该处理什么事件以及在哪里处理?

1 个答案:

答案 0 :(得分:1)

如果您的SomeDialog窗口扩展了DIalog Box ..您可以这样做

dialog.addCloseHandler(new CloseHandler<PopupPanel>() {
public void onClose(com.google.gwt.event.logical.shared.CloseEvent<PopupPanel> event) {
             yourbutton.setEnabled(true);           

                            };
                        });