批量编辑
属性
下列参数可以在 XML 或 Java 中设置:
- 
openMode- 批量编辑界面的打开模式,是OpenMode枚举类型的值:NEW_TAB、DIALOG等。默认情况下,用DIALOG模式打开界面。 - 
columnsMode- 批量编辑界面列的数量,是ColumnsMode枚举类型值。默认是TWO_COLUMNS。 - 
exclude- 一个正则表达式,排除某些实体属性,不显示在编辑器。 - 
includeProperties- 编辑器需要展示实体属性列表。该列表比exclude表达式优先级高。 - 
loadDynamicAttributes- 是否在编辑界面展示 动态属性。默认为true。 - 
useConfirmDialog- 是否在保存改动之前显示确认对话框。默认为true。 
示例:
<action id="bulk" type="bulkEdit">
    <properties>
        <property name="openMode" value="THIS_TAB"/>
        <property name="includeProperties" value="rewardPoints,email"/>
        <property name="columnsMode" value="ONE_COLUMN"/>
    </properties>
</action>
或者,可以在界面控制器注入该操作,然后用 setter 配置:
@Named("custTable.bulk")
private BulkEditAction custTableBulk;
@Subscribe
public void onInit(InitEvent event) {
    custTableBulk.setOpenMode(OpenMode.THIS_TAB);
    custTableBulk.setIncludeProperties(Arrays.asList("rewardPoints", "email"));
    custTableBulk.setColumnsMode(ColumnsMode.ONE_COLUMN);
}
处理器
下面了解这些只能用 Java 配置的参数。用 Studio 能为这些参数正确生成带注解的方法。
fieldSorter
接收表示实体属性的 MetaProperty 对象列表,返回按照编辑界面需要顺序的这些对象。示例:
@Install(to = "custTable.bulk", subject = "fieldSorter")
private Map<MetaProperty, Integer> custTableBulkFieldSorter(List<MetaProperty> properties) {
    Map<MetaProperty, Integer> result = new HashMap<>();
    for (MetaProperty property : properties) {
        switch (property.getName()) {
            case "email": result.put(property, 0); break;
            case "rewardPoints": result.put(property, 1); break;
            default:
        }
    }
    return result;
}
使用 ActionPerformedEvent
如果需要在该操作执行前做一些检查或者与用户做一些交互,可以订阅操作的 ActionPerformedEvent 事件并按需调用操作的 execute() 方法。下面的例子中,我们在执行操作前展示了一个自定义确认对话框:
@Named("custTable.bulk")
private BulkEditAction custTableBulk;
@Subscribe("custTable.bulk")
public void onCustTableBulk(Action.ActionPerformedEvent event) {
    dialogs.createOptionDialog()
            .withCaption("Please confirm")
            .withMessage("Are you sure you want to edit the selected entities?")
            .withActions(
                    new DialogAction(DialogAction.Type.YES)
                            .withHandler(e -> custTableBulk.execute()), // execute action
                    new DialogAction(DialogAction.Type.NO)
            )
            .show();
}
另外,还可以先订阅 ActionPerformedEvent,但是不调用操作的 execute() 方法,而是使用 ScreenBuilders API 直接打开查找界面。此时,会忽略所有特殊的操作参数和行为,只能用其通用参数,比如 caption、icon 等。示例:
@Autowired
private BulkEditors bulkEditors;
@Autowired
private Metadata metadata;
@Autowired
private GroupTable<Customer> custTable;
@Subscribe("custTable.bulkEdit")
public void onCustTableBulkEdit(Action.ActionPerformedEvent event) {
    bulkEditors.builder(metadata.getClass(Customer.class), custTable.getSelected(), this)
            .withListComponent(custTable)
            .withColumnsMode(ColumnsMode.ONE_COLUMN)
            .withIncludeProperties(Arrays.asList("rewardPoints", "email"))
            .create()
            .show();
}
本页是否有帮助?
        
        
    感谢您的反馈