如何在 IPreferenceStore 中存储首选项的多个实例?
我想将多个复杂项目的参数存储在 Eclipse 应用程序中作为首选项,该应用程序已经使用 IPreferenceStore 作为其首选项存储。 对于一项,我想存储多个参数。 我们是否有一些内置方法来存储多个实例并将它们作为 java 列表进行操作,或者我应该采用以下解决方法之一:
存储项目数量的首选项和命名约定,例如
“mypreference.numitems”-> 2
“mypreference.0.foo”-> ...
“mypreference.0.bar”-> ...
“mypreference.1.foo”-> ...
...
将整个数组序列化为首选项中的一个值 (brr...)
I would like to store the parameters of multiple complex items in an eclipse application as preferences, which already uses IPreferenceStore as its preference store.
For one item I would like to store multiple parameters.
Do we have some built-in method to store multiple instances and manipulate them as a java list, or should I resort to one of the following workarounds:
a preference storing the number of items, and a naming convention, like
"mypreference.numitems" -> 2
"mypreference.0.foo" -> ...
"mypreference.0.bar" -> ...
"mypreference.1.foo" -> ...
...
serialize the whole array into one value in a preference (brr...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我更喜欢后一种方法并且经常使用它。看看
PreferenceConverter
来了解一些标准类型的类似转换,例如Color
和Font
...在某些情况下,我如果需要保存更复杂的结构,我使用了 JSON 编码的值。很简单!
I prefer the later method and often use it. Have a look at
PreferenceConverter
for the similar conversions for some of the standard types likeColor
andFont
...In a few cases, where I need to save even more complex structures, I have used JSON-encoded values. Pretty easy!