且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 SWT/Java 中将数据附加到 TreeItem?

更新时间:2022-05-27 21:39:25

答案是:使用纯 SWT 你不能.
Standard Widget Toolkit 只处理小部件、它们的层次结构和视觉表示.将数据绑定到小部件是构建在 SWT 之上的更高级的 JFace 框架(尤其是它的数据绑定工具)的主题.您需要一些时间来掌握它,但因此您获得了 Eclipse 平台的强大功能.它使您可以绑定模型以进行查看,即使是双向查看
(→ 对模型对象的更改会立即反映在 UI 上,反之亦然).
目前,您必须保留一个单独的项目列表,并且需要使用索引.

The answer is: with pure SWT you cant't.
The Standard Widget Toolkit only takes care of the widgets, their hierarchy and the visual representation. Binding data to widgets is topic of the more advanced JFace framework (especially it's databinding facilities) which builds on top of SWT. You need some time to master it, but therefore you gain the power of the Eclipse platform. It enables you to bind a model to view, even in both direction
(→ change to model object are immediately reflected on the UI and vice versa).
Currently, you would have to keep a seperate list of items and need to work with indices.