JFace 向导传递变量

发布于 2024-09-08 04:13:51 字数 544 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

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

发布评论

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

评论(3

离去的眼神 2024-09-15 04:13:51

我喜欢在向导中创建数据对象并将其传递到每个 WizardPages 的构造函数中。例如:

public void addPages() {
  data = new MyData()
  addPage(new FirstPage(data));
  addPage(new SecondPage(data));
  ...
}

此方法的一个优点是您可以在向导执行完成期间访问数据对象。

I like to create my data object in the Wizard and pass it into the constructor of each of my WizardPages. For example:

public void addPages() {
  data = new MyData()
  addPage(new FirstPage(data));
  addPage(new SecondPage(data));
  ...
}

One advantage to this approach is you have access to your data object during your wizard's performFinish.

狠疯拽 2024-09-15 04:13:51

这是另一种方法:

PageOne pageOne = (PageOne) getWizard().getPreviousPage(this);

假设您在 PageTwo 上,并且在 PageOne 中您已经为您希望在 PageTwo 上使用的值定义了 getter。

Here's another way to do this:

PageOne pageOne = (PageOne) getWizard().getPreviousPage(this);

Supposing you are on PageTwo, and in PageOne you have defined your getters for the values you wish to use on PageTwo.

音栖息无 2024-09-15 04:13:51

另一种方法是使用带有静态变量的数据类。例如,如果您有 NewVehicleWizard,则可能必须实例化 Car、Truck 或 SUV(Vehicle 的所有子类)。但当向导被实例化时,这一点是未知的;该决定将在 VehicleTypePage 中做出,当选择 Truck 选项时,它可以调用以下方法:

MyWizardData.setVehicle(new Truck());

MyWizardData 将具有一个带有静态 getter 和 setter 的私有静态车辆变量。如果后续页面或 NewVehicleWizard 本身需要车辆对象,则可以简单地使用静态 getter:

Truck truck = (Truck)MyWizardData.getVehicle();
// ...work with truck here

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.setVehicle(new Truck());

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:

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