JFace 向导传递变量
我正在尝试使用 Wizard
类 (org.eclipse.jface.wizard.Wizard) 生成一个向导,
基本上我在构造函数中扩展 Wizard
,我 addPage
我想要的两个页面。
在我的第一页上,我拿了一些凭证。
在第二页上,我想使用第一页中的凭据对数据库运行查询,以用名称填充表。
如何将这些值从第一页传递到第二页?
出于所有意图和目的,我目前的代码与 http 相同://www.java2s.com/Code/Java/SWT-JFace-Eclipse/Asurveyusingawizard.htm ,除了我从第一页上的一些文本框中获取一些字符串并在第二页上有一个表格。
我读过有关容器的内容,发现有一个 setData() 方法,这是我可以利用的吗?
I'm trying to produce a wizard using the Wizard
class (org.eclipse.jface.wizard.Wizard)
Basically where I extend the Wizard
in the constructor I addPage
the two pages I want.
On my first page I take some credentials.
On the second page I want to run a query against the database using the credentials from the first page to populate a table with names.
How do I go about passing these values from the first to the second page?
To all intents and purposes my code at present is the same as http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/Asurveyusingawizard.htm except I obtain some strings from some text boxes on the first page and have a table on the second page.
I have read about containers and see there is a setData() method, is this something I can utilize?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我喜欢在向导中创建数据对象并将其传递到每个 WizardPages 的构造函数中。例如:
此方法的一个优点是您可以在向导执行完成期间访问数据对象。
I like to create my data object in the Wizard and pass it into the constructor of each of my WizardPages. For example:
One advantage to this approach is you have access to your data object during your wizard's performFinish.
这是另一种方法:
假设您在 PageTwo 上,并且在 PageOne 中您已经为您希望在 PageTwo 上使用的值定义了 getter。
Here's another way to do this:
Supposing you are on PageTwo, and in PageOne you have defined your getters for the values you wish to use on PageTwo.
另一种方法是使用带有静态变量的数据类。例如,如果您有 NewVehicleWizard,则可能必须实例化 Car、Truck 或 SUV(Vehicle 的所有子类)。但当向导被实例化时,这一点是未知的;该决定将在 VehicleTypePage 中做出,当选择 Truck 选项时,它可以调用以下方法:
MyWizardData 将具有一个带有静态 getter 和 setter 的私有静态车辆变量。如果后续页面或 NewVehicleWizard 本身需要车辆对象,则可以简单地使用静态 getter:
Another approach is to use a data class with static variables. For example, if you have a NewVehicleWizard, you may have to instantiate Car, Truck, or SUV (all subclasses of Vehicle). But that will not be known when the wizard is instantiated; that decision will be made in a VehicleTypePage, which could make the following method call when the option Truck is selected:
MyWizardData will have a private static vehicle variable with static getter and setter. If the vehicle object is needed by a subsequent page or by the NewVehicleWizard itself, you can simply use the static getter: