Eclipse首选项页面

时间:2014-12-10 15:20:56

标签: java eclipse-rcp preferences rcp

我在eclipse中创建了一个首选项页面,首选项页面有两个字段

  1. 服务器网址
  2. 商店位置
  3. 如果用户打开此首选项对话框,请更改url的值并应用它重新启动产品,重新启动后,当我检查url字段中的值时,它会按预期更改。当我更改url和目录的值时,只更新其中一个值取决于稍后更改的那个。 这是初始化首选项的初始化方法

    public class DataStorePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
    
    public static final String SERVER_URL = "prefs_server_url";
    public static final String WORKSPACE_DIR = "prefs_workspace_dir";
    public static final String KEEP_LOCKS = "prefs_keep_locks";
    //public static final String RELEASE = "prefs_release";
    public DataStorePreferencePage() {
        super(GRID);
    }
    
    
    @Override
    public void init(IWorkbench workbench) {
        setPreferenceStore(Activator.getDefault().getPreferenceStore());
        getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent event) {
                String property = event.getProperty();
                System.setProperty("datastoreserver_url", property);
                if (property.equals(DataStorePreferencePage.WORKSPACE_DIR) ||
                        property.equals(DataStorePreferencePage.SERVER_URL)) {
    
                    if(MessageDialog.openConfirm(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Information", "New settings will be applied after a restart.\nRestart now?"))
                        PlatformUI.getWorkbench().restart();
    
                }
            }
        });                     
    }
    
    @Override
    protected void createFieldEditors() {
        StringFieldEditor urlEditor = new StringFieldEditor(SERVER_URL, "DataStore Server URL", getFieldEditorParent());
        StringFieldEditor workspaceDirEditor = new DirectoryFieldEditor(WORKSPACE_DIR, "Workspace directory:", getFieldEditorParent());
        BooleanFieldEditor keepLocksEditor = new BooleanFieldEditor(KEEP_LOCKS, "Keep locks (default setting):", getFieldEditorParent());
        //BooleanFieldEditor releaseEditor = new BooleanFieldEditor(RELEASE, "Release (default setting):", getFieldEditorParent());
    
        addField(workspaceDirEditor);
        addField(urlEditor);
        addField(keepLocksEditor);
        //addField(releaseEditor);
    }
    
    @Override
    public boolean performOk() {
    
        return super.performOk();
    
    }
    
    
    }
    

    问题:

    新值存储在哪里?从哪里eclipse在任何.ini文件中获得此更改值?

    如何同时更改这两个属性?

    由于

1 个答案:

答案 0 :(得分:1)

等到performOkperformApply被调用,然后再检查重启。

首选项值存储在首选项存储中。你可以通过以下方式获得它们:

IPreferenceStore store = getPreferenceStore();

String dir = store.getString(WORKSPACE_DIR);

String url = store.getString(SERVER_URL);