java - Vaadin ConfirmDialog 自定义
问题描述
我对对话框的问题是有时第三个按钮不显示。它在测试期间显示出来,但让代码在 git 中腐烂一天并重新测试它,它只显示两个按钮。
package com.xxx.bpspkpibpcheck.dialog;
import org.vaadin.dialogs.ConfirmDialog;
import com.xxx.bpspkpibpcheck.message.UIMessageByLocaleService;
import com.vaadin.ui.UI;
/**
* Class representing the save as disabled dialog
*/
public class SaveAsDisabledDialog {
//translation prefixes
//private static final String DIALOG = "Dialog.";
private static final String SAVEASDISABLEDDIALOG = "SaveAsDisabledDialog.";
//translation postfixes
//private static final String MESSAGE_DISACTIVATE = "message.disactivate";
private static final String MESSAGE_CANCEL = "message.cancel";
private static final String CAPTION_SAVEASDISABLED = "caption.saveasdisabled";
protected static final String MESSAGE_YES = "message.yes";
protected static final String MESSAGE_NO = "message.no";
private static final String MESSAGE_SAVEASDISABLED = "message.saveasdisabled";
protected static final String TOOLTIP_YES = "tooltip.yes";
protected static final String TOOLTIP_NO = "tooltip.no";
protected static final String TOOLTIP_CANCEL = "tooltip.cancel";
//factories
ConfirmDialog.Factory oldFactory;
ConfirmDialog.Factory factory;
/**
* Construct a SaveAsDisabledDialog
* @param messageByLocaleService
*/
public SaveAsDisabledDialog(UIMessageByLocaleService messageByLocaleService) {
oldFactory = ConfirmDialog.getFactory();
factory = new ConfirmDialog.Factory() {
private static final long serialVersionUID = 1L;
@Override
public ConfirmDialog create(String arg0, String arg1, String arg2, String arg3, String arg4) {
ConfirmDialog cd = oldFactory.create(messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + CAPTION_SAVEASDISABLED),
"message",
"xxx", //messageByLocaleService.getMessage(DIALOG + MESSAGE_CANCEL),
"yyy", //messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + MESSAGE_YES),
"zzz");
cd.setMessage(messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + MESSAGE_SAVEASDISABLED));
/*
System.err.println("cd.getCancelButton()=" + cd.getCancelButton());
System.err.println("cd.getNotOkButton()=" + cd.getNotOkButton());
*/
cd.getOkButton().setCaption(messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + MESSAGE_YES));
cd.getOkButton().setDescription(messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + TOOLTIP_YES));
if(cd.getNotOkButton() != null) {
cd.getNotOkButton().setCaption(messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + MESSAGE_NO));
cd.getNotOkButton().setDescription(messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + TOOLTIP_NO));
}
cd.getCancelButton().setCaption(messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + MESSAGE_CANCEL));
cd.getCancelButton().setDescription(messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + TOOLTIP_CANCEL));
return cd;
}
};
}
public interface MyListener {
/**
* Receive an event
*/
public void receive();
}
/**
* Show the save as disabled dialog
* @param ui UI
* @param messageByLocaleService UIMessageByLocaleService
* @param yes SaveAsDisabledDialog.MyListener
* @param no SaveAsDisabledDialog.MyListener
* @param cancel SaveAsDisabledDialog.MyListener
*/
public void show(UI ui, UIMessageByLocaleService messageByLocaleService, MyListener yes, MyListener no, MyListener cancel) {
ConfirmDialog.setFactory(factory);
ConfirmDialog.show(ui,
messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + CAPTION_SAVEASDISABLED),
messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + MESSAGE_SAVEASDISABLED),
messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + MESSAGE_YES),
messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + MESSAGE_NO),
messageByLocaleService.getMessage(SAVEASDISABLEDDIALOG + MESSAGE_CANCEL),
new ConfirmDialog.Listener() {
private static final long serialVersionUID = 1L;
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
// Confirmed to continue
yes.receive();
} else if (dialog.isCanceled()) {
// User did not confirm
cancel.receive();
} else {
// Confirmed to continue without saving
no.receive();
}
}
});
}
}
解决方案
推荐阅读
- apache-spark - 如何安全地删除不属于架构的列?
- angularjs - 为什么 Angular 中没有显示表单验证错误?
- javascript - 在 css javascript 中创建切换按钮
- ruby - 我不知道如何解决这个问题
- python - 正则表达式 - 检查字符串中是否存在模式
- node.js - 检索存在于语音通道中的成员
- c# - 从 WebBrowser 获取完整的 cookie 列表
- javascript - 如何匹配两个数字之间的格式
- javascript - 有没有更好的方法来执行此代码?也许使用过滤器或减少?
- c# - 除非立即启动另一个完全不相关的进程,否则进程不会启动时的奇怪行为