我是 Eclipse PreferencePages
的新手,目前正在为我的项目创建一个新的 FieldEditorPreferencePage
。但是,使用 FileFieldEditors()
或 DirectoryFieldEditors()
会使我的自定义首选项页面中的“应用”和“确定”按钮变灰。另一方面,其他FieldEditors
( boolean 型和组合型)不会禁用“应用”和“确定”按钮。
此外,将所有内容更改为 Xtext 的 LanguageRootPreferencePage 似乎也有效(尽管我不想使用它,因为我希望自定义首选项页面显示在它自己的选项卡中)。
例如:
//Simplified example of code
public class XPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, IWorkbenchPropertyPage {
public XPreferencePage() {
super(FieldEditorPreferencePage.GRID);
setDescription("something");
}
protected void initialize() {
super.initalize();
//IPropertyChangeListeners go here
}
protected void createFieldEditors() {
//"Apply" and "OK" works here
g = new BooleanFieldEditor(SConstants.GENERATOR, "Generate Bindings", getFieldEditorParent());
addField(g);
//"Apply" and "OK" is greyed-out starting here
gp = new FileFieldEditor(SConstants.GENERATOR_PATH, "Generator Path:", false, 0, getFieldEditorParent());
gp.setEmptyStringAllowed(true);
addField(gp);
...
}
...
}
有办法解决这个问题吗?我按照 Eclipse Article-Field-Editors 的教程进行操作但这似乎对我不起作用。在线阅读说这可能是由于负数 IntegerField
(我没有)或者我正在尝试更改默认设置(我也没有)。
我使用的是 Eclipse Mars 4.5.0。
更新:上面的代码(部分)适用于FileFieldEditors
。但是,由于某种原因,我需要单击 FileFieldEditor
字段,并选中和取消选中首选项页面中每个 FileFieldEditor
正上方的复选框,然后“应用”和“确定”按钮再次可用。
此外,我还实现了一个IPropertyChangeListener
,当某些复选框未被选中时,它会停用某些字段,这意味着这种“检查和取消选中”的解决方法对我不起作用。我还尝试将默认焦点设置为我的复选框之一,但这不起作用
最佳答案
FileFieldEditor(String name, String labelText, Composite parent)
当文本小部件失去焦点时,default 会验证路径,这就是您提供的无效默认值。
例如如果你给C:\\User\\XXX
那么这个路径应该物理存在,并且只有它不会变灰,确定并应用按钮。
您还可以通过设置验证策略来使用下面的构造函数。
FileFieldEditor(String name, String labelText,boolean enforceAbsolute, int validationStrategy, Composite parent)
validationStrategy
的值
- 1 编辑器仅在文本小部件时执行验证 失去焦点。
- 0 表示编辑器在每个按键后执行验证 中风。
关于java - Eclipse PreferencePage "Apply"和 "OK"灰显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32841131/