【问题标题】:How to store global preferences at project level如何在项目级别存储全局首选项
【发布时间】:2016-04-06 06:22:52
【问题描述】:

我正在对如何在项目级别存储全局级别首选项进行 POC。

我已经创建了示例应用程序,其中我创建了MyPreferencePage 页面并使用org.eclipse.ui.preferencePages 扩展在eclipse 首选项中添加了这个页面。

我还可以保存页面数据并使用代码setPreferenceStore(Activator.getDefault().getPreferenceStore()) 检索它。 现在我想在项目属性级别下创建新页面,并且应该能够在项目级别存储页面值。

下面是MyPreferencePagepreferencePages 扩展的代码。

<extension
 point="org.eclipse.ui.preferencePages">
 <page
 class="com.vogella.preference.MyPreferencePage"
 id="com.vogella.preference.page1"
 name="MyPreferencePage">
 </page>
 </extension>
public class MyPreferencePage extends FieldEditorPreferencePage implements
 IWorkbenchPreferencePage {

 public MyPreferencePage() {
 super(GRID);

 }

 @Override
 public void createFieldEditors() {
 addField(new DirectoryFieldEditor(PreferenceConstants.P_PATH,
 "&Directory preference:", getFieldEditorParent()));

 addField(new BooleanFieldEditor(PreferenceConstants.P_BOOLEAN,
 "&An example of a boolean preference", getFieldEditorParent()));

 addField(new RadioGroupFieldEditor(PreferenceConstants.P_CHOICE,
 "An example of a multiple-choice preference", 1,
 new String[][] { { "&Choice 1", "choice1" },
 { "C&hoice 2", "choice2" } }, getFieldEditorParent()));

 addField(new StringFieldEditor(PreferenceConstants.P_STRING,
 "A &text preference:", getFieldEditorParent()));

 addField(new StringFieldEditor(PreferenceConstants.P_STRING,
 "A &text preference:", getFieldEditorParent()));

 }

 @Override
 public void init(IWorkbench workbench) {
 setPreferenceStore(Activator.getDefault().getPreferenceStore());
 setDescription("A demonstration of a preference page implementation");
 } 

【问题讨论】:

    标签: eclipse-pde


    【解决方案1】:

    您可以为项目使用ScopedPreferenceStore 作为传递给setPreferenceStore 的首选项存储。像这样创建它:

    new ScopedPreferenceStore(new ProjectScope(project), "your plugin id");
    

    其中project 是项目的IProject

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-29
      • 2020-03-11
      • 1970-01-01
      • 1970-01-01
      • 2015-04-10
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      相关资源
      最近更新 更多