gpt4 book ai didi

java - Eclipse 首选项页面

转载 作者:行者123 更新时间:2023-12-01 12:08:26 26 4
gpt4 key购买 nike

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

  1. 服务器网址
  2. 商店位置

如果用户打开此首选项对话框,更改 url 的值并应用它,产品将重新启动,重新启动后,当我检查 url 字段中的值时,它会按预期更改。当我更改 url 和目录的值时,仅更新其中之一,具体取决于稍后更改哪一项。这是我的 init 方法,它初始化首选项

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 文件中的更改值?

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

谢谢

最佳答案

等到调用 performOkperformApply 后再检查是否重新启动。

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

IPreferenceStore store = getPreferenceStore();

String dir = store.getString(WORKSPACE_DIR);

String url = store.getString(SERVER_URL);

关于java - Eclipse 首选项页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27404611/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com