jface.preference.FileFieldEditor 无法指定新文件

发布于 2024-08-27 10:12:47 字数 214 浏览 4 评论 0原文

我正在 Eclipse (3.5.2) 应用程序中设置一系列首选项,但 FileFieldEditor 出现问题。我想允许用户指定一个日志文件来打印输出。通常,这将是一个新文件。但是当我使用 FileFieldEditor 的文件选择对话框时,它抱怨该文件不存在(“值必须是现有文件”)。有没有办法在不扩展 FileFieldEditor 类的情况下抑制此错误并让 Java 创建该文件(如果该文件不存在)?谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下伊人醉 2024-09-03 10:12:47

当我查看 的源代码时org.eclipse.jface.preference.FileFieldEditor,唯一的解决方案是扩展它并编写您自己的 FileFieldEditor 版本,其中:

  • 覆盖 changePressed () 方法,以便即使文件不存在也保留文件路径,
  • 覆盖 checkState() 方法以避免出现该错误消息。

所以我在这里没有找到避免使用 FileFieldEditor 扩展的方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文