jface.preference.FileFieldEditor can't specify

2020-04-21 06:53发布

问题:

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.