jface.preference.FileFieldEditor can't specify a new file

无人久伴 提交于 2019-12-31 05:10:50

问题


I'm setting up a series of preferences in my Eclipse (3.5.2) application and I'm having a problem with the FileFieldEditor. I want to allow the user to specify a log file to print output to. Often, this will be a new file. But when I use the file select dialog with FileFieldEditor, it complains that the file doesn't exists ("Value must be an existing file"). Is there a way, without extending the FileFieldEditor class, to suppress this error and have Java create that file if it doesn't exist? Thanks!


回答1:


When I look the source code of org.eclipse.jface.preference.FileFieldEditor, the only solution would be to extend it and write your own version of a FileFieldEditor, with:

  • an overwritten changePressed() method in order to keep the file path even if the file does not exists
  • an overwritten checkState() method in order to avoid that error message.

So I do not see a way to avoid that FileFieldEditor extension here.



来源:https://stackoverflow.com/questions/2536362/jface-preference-filefieldeditor-cant-specify-a-new-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!