我正在开发基于Eclipse RCP的应用程序。 我用两个字段编辑器创建了FieldEditorPreferencePage。两个编辑都可以有空页:
protected void createFieldEditors() {
DirectoryFieldEditor pythonDirectoryFieldEditor = new DirectoryFieldEditor(MyPreferenceConstants.PYTHON_DIRECTORY_PATH,
PreferenceLabelMessages.getString(MyPreferenceConstants.PYTHON_DIRECTORY_PATH),
getFieldEditorParent());
pythonDirectoryFieldEditor.setEmptyStringAllowed(true);
addField(pythonDirectoryFieldEditor);
DirectoryFieldEditor libraryDirectoryFieldEditor =new DirectoryFieldEditor(MyPreferenceConstants.LIBRARY_DIRECTORY_PATH,
PreferenceLabelMessages.getString(MyPreferenceConstants.LIBRARY_DIRECTORY_PATH),
getFieldEditorParent());
libraryDirectoryFieldEditor.setEmptyStringAllowed(true);
addField(libraryDirectoryFieldEditor);
}
但是,当我将有效的目录路径引入其中一个字段而另一个字段为空时,我无法按“确定”或“应用”按钮,因为页面无效。在调试模式下,我看到isValid()
方法调用时,空字段返回false。为什么空字段无效?
我怎么解决它?