data-binding - 使用 EMF 和 RCP 的多级主/详细数据绑定(bind)

标签 data-binding rcp master-detail eclipse-emf

我用 EMF 制作了一个模型,表示设备的设置和 RCP GUI。在 GUI 中,我有一个列表来选择模型(主)类型的不同设备。

该模型有一个小类的对象列表,应显示在表格中(详细信息)。

tableItems 本身需要编辑,所以我有一个带有复选框等的小 GUI 部分来更改设置。在这里,tableitem 是主项,GUI 中显示的所有字段都是详细信息。

可观察到的设备列表:

IObservableValue selection = ViewersObservables.observeSingleSelection(availableDevicesList);

table :

IObservableList list = EMFObservables.observeDetailList(Realm.getDefault(), selection,DevicePackage.Literals.LIST);

TableViewer tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION);
tableViewer.setInput(list);

IObservableValue tableSelection = ViewersObservables.observeSingleSelection(tableViewer);

编辑:

Spinner field1 = new Spinner(parent, SWT.BORDER);

dbc.bindValue(SWTObservables.observeSelection(field1), EMFObservables.observeDetailValue(Realm.getDefault(), tableSelection, DevicePackage.Literals.Value1));

当更改设备选择时,tableitems 会被替换。但是 tableSelection 似乎有这个问题。有时它仍然包含来自不同设备的 tableitem 的值,有时它只包含 null。
我还有一个按钮,可以根据所有字段的验证状态启用/禁用。当 tableSelection 将 null 放入这些字段时,验证不起作用并且按钮被禁用,直到选择表中的条目。

我尝试使用列表中的监听器手动将选择设置为空,并且:

tableViewer.setSelection(StructuredSelection.EMPTY, true);

但这并不能完成全部工作。至少所有“旧”值都被替换了,但 null 问题仍然存在。

我需要的只是在应用程序启动后将 tableSelection 设置为空状态,此时尚未选择任何 tableitem。

最佳答案

我自己找到了解决方案。问题实际上是微调器本身。 It threw a nullpointer when the selection was empty and there was no value.

我通过给它一个自定义转换器(从 int 到 int ...)来解决它,如果源为空,我将返回一个默认值。
现在验证工作正常,我的按钮的启用状态设置正确。

关于data-binding - 使用 EMF 和 RCP 的多级主/详细数据绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6175635/

相关文章:

data-binding - WinRT ImageSource 与 cookie 绑定(bind)

ASP.NET ListBox DataBind 先前选定的值

java - 按右上角的 x 为 eclipse-rcp 事件

Eclipse RCP 应用程序 : How to disable specific extensions?

winforms - 将具有主/详细信息的类绑定(bind)到两个 datagridview 中

wpf - ItemsControl MVVM 绑定(bind)

c# - 我应该在 Windows 窗体项目中使用数据绑定(bind)吗?

java - 同时运行多个 Netbeans RCP 应用程序实例

ios - 使用 iPhone 类的 iPad 主从 View

ios - Swift iOS -SplitViewController 不会让我隐藏 StatusBar?