Eclipse DataBinding:延迟模型更新直到对话框确认

发布于 2024-09-13 09:44:08 字数 97 浏览 3 评论 0 原文

我有一个带有默认按钮的 TitleAreaDialog,我在其中使用数据绑定来同步模型和小部件。如何延迟模型更新直到用户单击“确定”按钮?

谢谢!

I have a TitleAreaDialog with default buttons where I use data binding to synchronize the model and the widgets. How do I delay model updates until the user clicks the 'OK' button?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二货你真萌 2024-09-20 09:44:08

我不知道怎么拖延。另一种方式是注册 DisposeListener 以检查用户选择“确定”或“取消”。如果结果不好,我就会放弃改变。

就我而言,我绑定了从 hibernate 获取的模型。当“确定”时是否保持休眠状态,当按下取消时是否刷新模型(从数据库中重新读取数据)。

但是,我也希望该函数能够延迟或撤消更改。

I don't know how to delay. In another way, to register the DisposeListener to check the user select ok or cancel. If the result is not ok, I give up the changes.

In my case, I binded the model fetched from hibernate. Do hibernate persist when 'ok', do refresh model (re-read data from database) when cancel is pressed.

However, I want the function to delay or undo changes, too.

冬天旳寂寞 2024-09-20 09:44:08

您必须为绑定设置 POLICY_CONVERTPOLICY_ON_REQUESTUpdateValueStrategy 来“延迟”模型更新:

DataBindingContext dbc = new DataBindingContext();
final Binding binding = dbc.bindValue(target, model, 
    new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);

然后您可以通过像这样的“确定”按钮:

Button btnOK = mToolkit.createButton(parent, "OK", SWT.NONE);
btnOK.addSelectionListener(new SelectionAdapter()
{
    @Override
    public void widgetSelected(SelectionEvent e)
    {
        binding.updateModelToTarget();
    }
});

或者您可以通过调用 DataBindingContext.updateTargets() 来更新 DataBindingContext 中的所有绑定

You have to set the UpdateValueStrategy of POLICY_CONVERT or POLICY_ON_REQUEST for your binding to 'delay' the model updates:

DataBindingContext dbc = new DataBindingContext();
final Binding binding = dbc.bindValue(target, model, 
    new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT), null);

Then you can update the target via the OK button like this:

Button btnOK = mToolkit.createButton(parent, "OK", SWT.NONE);
btnOK.addSelectionListener(new SelectionAdapter()
{
    @Override
    public void widgetSelected(SelectionEvent e)
    {
        binding.updateModelToTarget();
    }
});

Or you can update all bindings within the DataBindingContext by calling DataBindingContext.updateTargets()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文