Jface wizard dialog box on the fourth day

Source: Internet
Author: User

Content density:
Target dialog box
Content:
1. In the dialog box, each tutorial teaches how to construct a self-wizardpage class and implements
Createcontrol abstract method:
2. There are two constructor methods:
A.
Wizardpage (string pagename );
B.
Wizardpage (string pagename, String title, imagedescriptor titleimage)
3. Do not forget to call the setcontrol method after creating the control in the Wizard dialog box in the createcontrol method.
Otherwise, the control cannot be displayed,

4. When creating and assembling various Wizard Page classes, pay attention to the following issues:
The wizard must be disconnected from the wizard class, And the restore mfinish method must be implemented,
This method is called after you click "finish.
The addpage method is used to add the wizard pages to the wizard.
You must add them in order.

In addition, you can overwrite the canfinish method in the parent class to set the available status of the "finish" button.

Wizard Page:

 

Package com. swtjface. wizardpage;

Import org. Eclipse. jface. Resource. imagedescriptor;
Import org. Eclipse. jface. Wizard. iwizard;
Import org. Eclipse. jface. Wizard. wizarddialog;
Import org. Eclipse. jface. Wizard. wizardpage;
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. layout. gridlayout;
Import org. Eclipse. SWT. Widgets. Button;
Import org. Eclipse. SWT. Widgets. composite;
Import org. Eclipse. SWT. Widgets. label;
Import org. Eclipse. SWT. Widgets. shell;

Public class wq1 extends wizardpage {

Protected wq1 (){
Super (bookwizard. Q1, "title", imagedescriptor. createfromfile (wq1.class,
"Icons \ customer.gif "));

This. setmessage ("how is this message ");
}

Public void createcontrol (composite parent ){
// Todo auto-generated method stub
Composite composite = new composite (parent, SWT. None );
Composite. setlayout (New gridlayout (2, false ));
New label (composite, SWT. Left). settext (".");
Button b1 = new button (composite, SWT. Radio );
B1.settext ("too simple ");
B1.setselection (true );

Wizardtest. putds ("wq1", "test1 ");
Setcontrol (composite );
}
}

 

Page 2:

 

Package com. swtjface. wizardpage;

Import org. Eclipse. jface. Resource. imagedescriptor;
Import org. Eclipse. jface. Wizard. iwizard;
Import org. Eclipse. jface. Wizard. wizarddialog;
Import org. Eclipse. jface. Wizard. wizardpage;
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. layout. gridlayout;
Import org. Eclipse. SWT. Widgets. Button;
Import org. Eclipse. SWT. Widgets. composite;
Import org. Eclipse. SWT. Widgets. label;
Import org. Eclipse. SWT. Widgets. shell;

Public class wq2 extends wizardpage {

Protected wq2 (){
Super (bookwizard. Q2, "title", imagedescriptor. createfromfile (wq1.class,
"Icons \ customer.gif "));

This. setmessage ("how ");
}

Public void createcontrol (composite parent ){
// Todo auto-generated method stub
Composite composite = new composite (parent, SWT. None );
Composite. setlayout (New gridlayout (2, false ));
New label (composite, SWT. Left). settext (".");
Button b1 = new button (composite, SWT. Radio );
B1.settext ("too simple ");
B1.setselection (true );

Wizardtest. putds ("wq2", "Test2 ");
Setcontrol (composite );
}
}

Page 3:

 

Package com. swtjface. wizardpage;

Import org. Eclipse. jface. Resource. imagedescriptor;
Import org. Eclipse. jface. Wizard. iwizard;
Import org. Eclipse. jface. Wizard. wizarddialog;
Import org. Eclipse. jface. Wizard. wizardpage;
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. layout. gridlayout;
Import org. Eclipse. SWT. Widgets. Button;
Import org. Eclipse. SWT. Widgets. composite;
Import org. Eclipse. SWT. Widgets. label;
Import org. Eclipse. SWT. Widgets. shell;

Public class Thanks extends wizardpage {

Protected thanks (){
Super (bookwizard. Q3, "thanks", imagedescriptor. createfromfile (
Thanks. class, "icons \ customer.gif "));

This. setmessage ("how ");
}

Public void createcontrol (composite parent ){
// Todo auto-generated method stub
Composite composite = new composite (parent, SWT. None );
Composite. setlayout (New gridlayout (2, false ));
New label (composite, SWT. Left). settext ("Thanks !!! ");

Wizardtest. putds ("wq3", "test3"); // record information to the XML document
Setcontrol (composite );
}
}

 

 

 

 

 

 

Assembly program:

 

Package com. swtjface. wizardpage;

Import org. Eclipse. jface. Wizard. Wizard;

Public class bookwizard extends wizard {
Public static final string Q1 = "wq_1 ";
Public static final string q2 = "wq_2 ";
Public static final string Q3 = "thanks ";
Private wq1 wq1;
Private wq2 wq2;
Private thanks;

Public bookwizard (){
Wq1 = new wq1 ();
Wq2 = new wq2 ();
Thanks = new thanks ();
This. addpage (wq1 );
This. addpage (wq2 );
This. addpage (thanks );
This. setwindowtitle ("Wizard Page !! ");
}

@ Override
Public Boolean canfinish (){
If (this. getcontainer (). getcurrentpage () = Thanks ){
Return true;
} Else {
Return false;
}
}

@ Override
Public Boolean initialize mfinish (){
Wizardtest. saveds (); // save

Return false;
}

}

 

Main Program:

 

Package com. swtjface. wizardpage;

Import org. Eclipse. jface. Window. applicationwindow;
Import org. Eclipse. jface. Wizard. wizarddialog;
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. Events. selectionadapter;
Import org. Eclipse. SWT. Events. selectionevent;
Import org. Eclipse. SWT. layout. rowlayout;
Import org. Eclipse. SWT. Widgets. Button;
Import org. Eclipse. SWT. Widgets. composite;
Import org. Eclipse. SWT. Widgets. Control;
Import org. Eclipse. SWT. Widgets. display;
Import org. Eclipse. SWT. Widgets. shell;

Public class wizardtest extends applicationwindow {

 

Static dialogsettings DS = new dialogsettings (null );

Public static void putds (string key, string Str ){
DS. Put (Key, STR );
}

Public static void saveds (){
Try {
DS. Save ("D: \ test. xml ");
} Catch (ioexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}

 

 

Public wizardtest (){
Super (null );
// Todo auto-generated constructor stub
}

Protected control createcontents (composite parent ){
Parent. setlayout (New rowlayout (SWT. Vertical ));
Button BTN = new button (parent, SWT. None );
BTN. settext ("open to Pipeline ");
BTN. addselectionlistener (New selectionadapter (){
Public void widgetselected (selectionevent e ){
Wizarddialog DLG = new wizarddialog (display. getcurrent ()
. Getactiveshell (), new bookwizard ());
DLG. open ();
}

});
Return parent;
}

Public static void main (string [] ARGs ){
Wizardtest test = new wizardtest ();
Test. setblockonopen (true );
Test. open ();
Display. getcurrent (). Dispose ();
}
}

 

 

How to implement a variety of Prompt Windows? SWT provides a class
Messagedialog
Only one OK
Messagedialog. openinformation (shell, "title", "message ");
Yes/No
Messagedialog. openconfirm (shell, "title", "message ");
Yes/No/cancel
Messagedialog dialog = new messagedialog (shell, "title", null, "message ",
Messagedialog. Question, new string [] {idialogconstants. yes_label,
Idialogconstants. no_label, idialogconstants. cancel_label}, 0 );
Dialog. open ();
You can also add more options. You only need to add more content to the array.
How can I obtain the button I clicked?
Direct int result = dialog. open ();
Or int result = dialog. getreturncode ();
The returned result value is the index of the selected button in the array.

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.