How do I set a preference value?

本文介绍了三种在Eclipse中设置自动构建的方法:通过向后兼容层、通过从根节点导航和通过作用域上下文。这些方法适用于不同场景,帮助用户灵活地配置Eclipse的自动构建功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ps:内容来自Eclipse Preferences FAQ。代码简单,直接贴了。

 

1.

Through the backwards compatibility layer.

Again, all the old APIs exist and are fully functional.

String key = ResourcesPlugin.PREF_AUTO_BUILDING;
boolean value = true;
ResourcesPlugin.getPluginPreferences().setValue(key, value);

2.Via navigation from the root node.

If the user knows which scope they wish to store the preference in and knows the path structure for the hierarchy of that scope, then they are able to navigate directly to that preference node and set their preference value. In the example below we are setting the auto-build setting in the INSTANCE scope.

String qualifier = ResourcesPlugin.getDescriptor().getUniqueIdentifier();
String key = ResourcesPlugin.PREF_AUTO_BUILDING;
boolean value = true;
IEclipsePreferences root = Platform.getPreferencesService().getRootNode();
root.node(InstanceScope.SCOPE).node(qualifier).putBoolean(key, value);

3.Through the scope context.

If the user knows which scope they wish to set the preference value in but doesn't know the path structure for that scope, (or prefers not to navigate it themselves) then they can use the convenience methods in IScopeContext to determine the correct preference node. This is the method in which we envision most clients setting preference values. In the example below we are storing the preference in the project preferences for "MyProject".

String qualifier = ResourcesPlugin.getDescriptor().getUniqueIdentifier();
String key = ResourcesPlugin.PREF_AUTO_BUILDING;
boolean value = true;
IScopeContext context = new ProjectScope(MyProject);
IEclipsePreferences node = context.getNode(qualifier);
if (node != null)
    node.putBoolean(key, value);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值