保存 SWT 小部件属性至工作区

huangapple 未分类评论43阅读模式
英文:

Save SWT widget properties to workspace

问题

我有一个包含多个视图的E4应用程序,其中包含许多SWT小部件,包括JFace TableViewers、TableViewerColumns、Tables等。文件workspace.xmi在关闭时被创建/更新,但仅包含视图的属性。是否有可能将有关这些小部件的属性存储在workspace.xmi中?因此,如果用户更改列的顺序并重新启动应用程序,列的顺序将保持不变。

英文:

I have an E4 app with multiple views, which contain many SWT widgets including JFace TableViewers, TableViewerColumns, Tables ect. The file workspace.xmi is created/updated on close, but only with the properties of the views. Is it possible to store properties regarding these widgets in the workspace.xmi? So if the users changes the order of the columns, and restarts the app, the columns would be in the same order.

答案1

得分: 0

e4 MApplicationElement元素(如MPart)具有一个方法:

Map<String, String> getPersistedState()

您可以在持久化状态中设置任何所需的值。这些值将保存在workbench.xmi中,并在应用程序重新启动时进行恢复。

您可以自行设计如何在地图中保存有关SWT控件的信息。

注意:在3.x兼容模式的视图或编辑器中,您可以使用以下方法获取MPart

EPartService partService = getSite().getService(EPartService.class);

MPart part = partService.findPart(getSite().getId());
英文:

e4 MApplicationElement elements (such as MPart) have a

Map<String, String> getPersistedState()

method. You can set any values you like in the persisted state. They will be saved in the workbench.xmi and restored with the application is restarted.

It is up to you to design how you save the information about the SWT controls in the map.

Note: In an 3.x compatability mode view or editor you can get the MPart using

EPartService partService = getSite().getService(EPartService.class);

MPart part = partService.findPart(getSite().getId());

huangapple
  • 本文由 发表于 2020年4月9日 02:27:10
  • 转载请务必保留本文链接:https://java.coder-hub.com/61107532.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定