RCP II: Extended Universal Workbench (4)

xiaoxiao2021-03-06  63

4, define wizard

(1) Wizard Overview

l JFACE Toolbox Support Wizard to provide a flexible mechanism to collect user input information, and perform input verification

l This tutorial creates a JFACE wizard to collect the license key used by Google search, and the collection of License Key will use in the serchview view of the SerachView view.

Search.setKey (licenseKeywizard.getlicenseKey ());

(2) Create a licenseKeyWizard class

Package com.xqtu.google.wizards;

Import org.eclipse.jface.wizard.wizard;

Public class licenseKeywizard extends wizard {

PRIVATE STATIC STRING LICENSEKEY;

Private licenseKeyWizardPage Page;

Public licenseKeywizard () {

Super ();

This.SetWindowTitle ("license key");

}

Public boolean performfinish () {

IF (page.GetLicenseKeyText (). getText (). Equalsignorecase ("))

{

"You Must Provide a license key.");

Page.SetPageComplete (false);

Return False;

}

Else

{

LicenseKey = page.getlicenseKeyText (). getText ();

Return True;

}

}

Public void addpages () {

Page = New licenseKeyWizardPage ("licenseKey");

AddPage (PAGE);

}

Public static string getLicenseKey () {

Return licenseKey;

}

Public static void setLicenseKey (String licenseKey) {

LicenseKeyWizard.LicenseKey = licenseKey;

}

}

licenseKeyWizard WiZard class (Abstract base class for IWizard interface), you need to implement the addpages and PerformFiniSh methods, and the former will be sent to the wizard object to the wizard, the latter is executed when the user clicks the finish button, complete the specific function

licenseKeyWizard class defines the Static's property licenseKey, used to save the collection of license keys

l Addpages method is relatively simple, create a licenseKeyWizardPage (later introduction) object, add it to the wizard

l PerformFinish method First, the text domain content provided in LicenseKeyWizardPage is verified. If the data is invalid, the error message is prompted, otherwise save to the licenseKey property.

(3) Create a licenseKeyWizardPage class

Package com.xqtu.google.wizards;

Import org.eclipse.jface.wizard.wizardpage;

Import org.eclipse.swt.swt; import org.eclipse.swt.Layout.Griddata;

Import org.eclipse.swt.Layout.GridLayout;

Import org.eclipse.swt.widgets.composite;

Import org.eclipse.swt.widgets.label;

Import org.eclipse.swt.widgets.text;

Public class licenseKeyWizardPage Extends WizardPage {

Private text licenseKeyText;

Protected licenseKeyWizardPage (String Pagename) {

Super (PageName);

Settitle ("license key");

SetDescription ("Define Your Google API License Key");

}

Public void createControl (Composite Parent) {

GridLayout PageLayout = New GridLayout ();

PageLayout.NumColumns = 2;

Parent.setLayout (PageLayout);

Parent.setLayOutdata (New GridData (GridData.Fill_horizontal);

Label Label = New Label (PARENT, SWT.NONE);

Label.Settext ("License Key:");

LicenseKeyText = New text (parent, swt.border);

LicenseKeyText.setLayOutdata (New GridData (GridData.Fill_hizontal);

SetControl (PARENT);

}

Public text getLicenseKeyText () {

Return licenseKeyText;

}

Public void setLicenseKeyText (Text licenseKeyText) {

THISLICENSEKEYTEXT = licenseKeyText;

}

}

l Extend the WizardPage class (abstract base class for the iWizardPage interface), you need to implement the CreateControl method to create controls; the guidance of this tutorial has only one wizard page LicenseKeyWizardPage

l Set the title and description of the wizard page in the construction method; create a license key label and the corresponding text domain in the CreateControl method (method similar to the same view)

转载请注明原文地址:https://www.9cbs.com/read-119529.html

New Post(0)