当允许空字符串时,FieldEditorPreferencePage无效

时间:2016-10-13 17:50:37

标签: java validation eclipse-rcp

我正在开发基于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。为什么空字段无效? 我怎么解决它?

0 个答案:

没有答案