使用 EMF 和 RCP 进行多级主/详细数据绑定
我使用 EMF 制作了一个模型,代表设备的设置和 RCP GUI。在 GUI 中,我有一个列表可以选择模型类型(主设备)的不同设备。
该模型有一个小类的对象列表,应显示在表格中(详细信息)。
tableItems 本身需要编辑,所以我有一个带有复选框等的小 GUI 部分来更改设置。这里表项是主项,GUI 中显示的所有字段都是详细信息。
可观察设备列表:
IObservableValue selection = ViewersObservables.observeSingleSelection(availableDevicesList);
表:
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));
更改设备选择时,表项将被替换。但 tableSelection 似乎有这个问题。有时它仍然包含来自不同设备的表项的值,有时它只包含 null。 我还有一个按钮,可以根据所有字段的验证状态启用/禁用。当 tableSelection 将 null 放入这些字段时,验证将不起作用,并且该按钮将被禁用,直到选择表中的条目。
我尝试使用列表上的侦听器手动将选择设置为空,并且:
tableViewer.setSelection(StructuredSelection.EMPTY, true);
但这并不能完成全部工作。至少所有“旧”值都被替换,但空问题仍然发生。
我所需要的只是在应用程序启动后,当尚未选择任何表项时,将 tableSelection 设置为空状态。
I made a model with EMF, representing the settings of a device, and a RCP GUI. In the GUI I have a list to select different devices of the type of the model (Master).
The model has a List of Objects of a small class which should be displayed in a table (Detail).
The tableItems itself need to be edited so I have a small GUI part with checkboxes etc. to change the settings. Here the tableitem is master and all fields shown in the GUI are details.
Observable for the List of devices:
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);
Editing:
Spinner field1 = new Spinner(parent, SWT.BORDER);
dbc.bindValue(SWTObservables.observeSelection(field1), EMFObservables.observeDetailValue(Realm.getDefault(), tableSelection, DevicePackage.Literals.Value1));
When changing the device selection the tableitems get replaced. But the tableSelection seems to have a problem with this. Sometimes it still contains values of a a tableitem from a different device and sometimes it just contains null.
I also have a button which gets enabled/disabled according the validation status of all fields. When the tableSelection puts null into these fields the validation does not work and the button is disabled until a entry in the table is selected.
I tried to manually set the selection empty with a listener on the list and:
tableViewer.setSelection(StructuredSelection.EMPTY, true);
but this does not do the full job. At least all "old" values are replaced but the null problem still occurs.
All I need is to set the tableSelection to an empty state as after the launch of the application, when no tableitem was selected yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己找到了解决方案。问题实际上出在旋转器本身。当选择为空并且没有值时,它会抛出一个空指针。
我通过给它一个自定义转换器(从 int 到 int...)解决了这个问题,如果源为空,我将返回默认值。
现在验证工作正常,并且我的按钮的启用状态设置正确。
I found the solution by myself. The problem was actually the spinner itself. It threw a nullpointer when the selection was empty and there was no value.
I solved it by giving it a custom converter (from int to int...) where I return a default value if the source is null.
Now the validation works fine and my button's enable state is set correct.