1

我有一个用我的按钮来装饰用户 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();
            }
        });
}

当我单击一个按钮时,它会被禁用并出现对话框。但是当我关闭对话框时,我的按钮仍然处于禁用状态。如何在对话框关闭时重新启用按钮?为了实现这一目标,我应该在哪里处理什么事件?

4

1 回答 1

1

如果您的 SomeDialogWindow 扩展 DIAlogBox..您可以这样做

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

                            };
                        });
于 2013-03-25T14:10:58.593 回答