如何新建弹窗,提交不写库?

如何新建-》弹窗,提交后不写库,但是列表上要显示?

比如对于clone的对象编辑,不需要写库,只是在列表展示。

首先,在编辑界面:

private boolean isClone = false;
  
public boolean isClone() {
    return isClone;
}

public void setClone(boolean clone) {
    isClone = clone;
}

@Subscribe
public void onBeforeCommitChanges(final BeforeCommitChangesEvent event) {
    // 如果是clone,则不提交。这一步也可以修改提交按钮的click事件,分别调用 closeWithCommit() 和 closeWithDiscard().
    if (isClone()) {
        event.preventCommit();
        closeWithDiscard();
    }
}

然后,列表页:

@Subscribe("clone")
public void onCloneClick(final Button.ClickEvent event) {

    if(ordersTable.getSelected().isEmpty()){
        return;
    }

    var clone = clone(ordersTable.getSelected().iterator().next());

    var editor = screenBuilders.editor(Order.class, this)
            .withScreenClass(OrderEdit.class)
            .editEntity(clone)
            .withOpenMode(OpenMode.DIALOG)
            .build();

    // 告诉editor是clone,此时不需要commit
    editor.setClone(true);

    editor.addAfterCloseListener(e->{
        // editor关闭后,更新表格
        ordersDc.getMutableItems().add(editor.getEditedEntity());
    });
    editor.show();
}
1 个赞