我有一个ReturnButton类,它在MenuItem Click上添加了一个新的弹出窗口,现在在该子窗口中,如果' Save'单击并关闭按钮,然后我想在ReturnButton类中执行一个函数。我只是不知道如何去做。目前,当单击返回菜单项时,它会打开子窗口并同时执行我拥有的所有三个功能。
} else if (selectedMenuItem.getText().equals("Return ")) {
RMeditor editor = new RMeditor(pSubmittal); // opensPopUp
UI.getCurrent().addWindow(editor);
PServices.getInstance().getDataService().getSDao().changeStatus(submittal,
Value.RETURNED);
PServices.getInstance().getDataService().getSDao().sendNotification(submittal,
Value.RETURN);
}
}
,这是弹出窗口中的保存按钮
public void buttonClick(ClickEvent event) {
if (hasChanges()) {
ConfirmDialog.show(
UI.getCurrent(),
"Confirmation",
"Do you want to discard changes ?",
"Yes",
"No",
new ConfirmDialog.Listener() {
private static final long serialVersionUID = 1L;
@Override
public void onClose(ConfirmDialog dialog) {
if (dialog.isConfirmed()) {
win.close();
}
dialog.close();
}
});
} else {
win.close();
}
}
});
// The Save Button
saveButton = UIUtils.createSaveButton();
saveButton.setEnabled(hasChanges() && isFormDataValid());
saveButton.addClickListener(new ClickListener() {
private static final long serialVersionUID = 1L;
@Override
public void buttonClick(ClickEvent event) {
if (isFormDataValid() && hasChanges()) {
FDao fDao = PServices.getInstance().getDataService().getFDao();
fdao.updatePersonTabInfo(pSubmittal, null, null, externalRemarksTextArea.getValue(), internalRemarksTextArea.getValue());
DefaultNotificationHandler.getInstance().showSuccessNotification("Your changes have been saved");
win.close();
close();
} else if (isFormDataValid()) {
win.close();
close();
}
}
});
saveButton.setEnabled(false);
persistButtonLayout.addComponents(saveButton, cancelButton);
}
答案 0 :(得分:0)
您可以使用与Vaadin用于按钮和其他组件类似的方法。在那里你添加一个监听器,以便在发生事件时得到通知。
创建用于收听成功保存的界面
interface RmSaveListener extends Serializable {
void onRmSave(Object submittal);
}
然后从你创建RMeditor的地方注册监听器:
RMeditor editor = new RMeditor(pSubmittal); // opensPopUp
editor.addSaveListener(this::onRmSave);
UI.getCurrent().addWindow(editor);
private void onRmSave(Object submittal) {
PServices.getInstance().getDataService().getSDao().changeStatus(
submittal,
Value.RETURNED);
PServices.getInstance().getDataService().getSDao().sendNotification(
submittal,
Value.RETURN);
}
然后你可以从保存按钮
调用你的监听器@Override
public void buttonClick(ClickEvent event) {
if (isFormDataValid() && hasChanges()) {
if (saveListener != null) {
saveListener.onRmSave(pSubmittal);
}
win.close();
close();
} else if (isFormDataValid()) {
win.close();
close();
}
}