我想更改标题"确认"一个ConfirmDialog用我的语言的东西。我看了this,但代码对我来说没有意义,因为我的vaadin插件中的show方法是一个静态方法,似乎无法显示工厂返回的对话框。
我使用此代码来包装对话框:
package com.xxx.dialog;
import org.vaadin.dialogs.ConfirmDialog;
import com.xxx.message.MessageByLocaleService;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
public class DeleteDialog {
private ConfirmDialog cd;
public DeleteDialog(MessageByLocaleService messageByLocaleService) {
cd = ConfirmDialog.getFactory()
.create(messageByLocaleService.getMessage("caption.confirm"),
"", "OK", "Cancel", "");
}
public abstract static class MyListener {
public abstract void receive();
}
public void show(UI ui, MessageByLocaleService messageByLocaleService, MyListener yes, MyListener cancel) {
//this.setCaption(messageByLocaleService.getMessage("caption.confirm"));
//this.setMessageLabel(new Label(messageByLocaleService.getMessage("caption.confirm")));
cd.show(ui, messageByLocaleService.getMessage("confirm.delete"),
new ConfirmDialog.Listener() {
private static final long serialVersionUID = 1L;
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
// Confirmed to continue
yes.receive();
} else {
// User did not confirm
cancel.receive();
}
}
});
}
}
我将此class DeleteDialog
作为extends ConfirmDialog
一段时间,这就是为什么我做出的一些注释被注释掉的原因并不合理。
答案 0 :(得分:0)
我设法通过设置一个新的默认工厂来实现我的目标。
package com.xxx.dialog;
import org.vaadin.dialogs.ConfirmDialog;
import com.xxx.message.MessageByLocaleService;
import com.vaadin.ui.UI;
public class DeleteDialog {
ConfirmDialog.Factory oldFactory;
ConfirmDialog.Factory factory;
public DeleteDialog(MessageByLocaleService 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("caption.confirm"),
"", messageByLocaleService.getMessage("message.ok"),
messageByLocaleService.getMessage("message.cancel"), null);
cd.setMessage(messageByLocaleService.getMessage("confirm.delete"));
return cd;
}
};
}
public abstract static class MyListener {
public abstract void receive();
}
public void show(UI ui, MessageByLocaleService messageByLocaleService, MyListener yes, MyListener cancel) {
ConfirmDialog.setFactory(factory);
ConfirmDialog.show(ui, messageByLocaleService.getMessage("confirm.delete"),
new ConfirmDialog.Listener() {
private static final long serialVersionUID = 1L;
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
// Confirmed to continue
yes.receive();
} else {
// User did not confirm
cancel.receive();
}
}
});
}
}