Eclipse SWT - WizardPage 小部件验证
验证 Eclipse 向导中包含的文本、组合和任何其他 SWT 小部件的最佳方法是什么?最近,我进入了一个项目,其中有许多不同的向导。我尝试添加 FocusListeners、ModifyListeners 等,但是代码的大小及其复杂性并不是我所期望的。
假设 WizardPage 中有两个 Text 元素。它们都不能为空,并且只能包含小写字母。如何编写一个验证器来检查字段是否为空或包含意外字符,并在出现问题时显示错误消息。
完成它的方式必须是复杂的、优雅的和有用的。
What is the best way to validate Text, Combo and any other SWT widget included in Eclipse Wizard? Recently, I got into a project in which there are many different wizards. I tried to add FocusListeners, ModifyListeners etc. however the size of code and it's complexity was not what I expected.
Let's say there are two Text elements in WizardPage. They both cannot be empty and should contain only small letters. How to write a validator which checks if fields are empty or contain unexpected characters and display an error message in case something went wrong.
The way it has to be done must be sophisticated, elegant and useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用 JFace 数据绑定(我自己也使用它们)。您将能够向特定绑定添加验证器,并在向导中自动显示验证错误/警告。
I would recommend using JFace databindings (I use them myself). You will be able to add validators to particular binding and automatically show validation errors/warnings in the wizard.
除了 Eugene 之外,我还可以推荐以下站点,在向导页面的上下文中提供一个不错的 JFace 数据绑定示例。
但不要错过将这些插件插入到你的plugin.xml中
In addition to Eugene I can recommend following site for a nice JFace databinding example in context with wizard pages.
http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet014WizardDialog.java?view=markup
But don't miss to insert those plugins into your plugin.xml