如何在项目级别

时间:2016-04-06 06:22:53

标签: eclipse-pde

我正在进行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");
 } 

1 个答案:

答案 0 :(得分:0)

您可以将ScopedPreferenceStore用作项目,因为首选项商店已传递给setPreferenceStore。像这样创建它:

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

其中project是项目的IProject