开发者

JFace wizard passing variables

开发者 https://www.devze.com 2023-01-05 04:28 出处:网络
I\'m trying to produce a wizard using the Wizard class (org.eclipse.jface.wizard.Wizard) Basically whe开发者_运维知识库re I extend the Wizard in the constructor I addPage the two pages I want.

I'm trying to produce a wizard using the Wizard class (org.eclipse.jface.wizard.Wizard)

Basically whe开发者_运维知识库re 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?


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.


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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消