Eclipse interface case (1) - extension TitleAreadialog

xiaoxiao2021-03-06  58

TitleAreadialog is a dialog provided in the JFACE package of Eclipse, which provides a region where the title, prompt information, and an icon are displayed, and an area containing the actual content and provides two buttons by default. The most prominent example is the new wizard and imported wizard (both particles are extended Wizard, but the dialog is extended by WizardDialog, and the latter is extension from TitleAdialog). This document describes how to create your own dialog from TitleAdialog. This example implements the interface as shown:

Create projects in a routine manner and prepare a resource file. The key icon file is ICons / Loginkey.gif. The dialog created by this example is WorklistLogindialog. Specific implementation can refer to ChooseworkSpaceDialog, this document implements the selection function of the workspace at Eclipse startup.

Default, you need to overwrite CreateDialogarea. This method creates the content above the OK and the CANCEL button. The code is the code implemented by this example, adds a detailed note:

Protected Control CreateDialogarea (Composite Parent) {

// Get the product name, you can refer to this paragraph code

String productname = NULL;

IProduct Product = Platform.getProduct ();

IF (Product! = null) {

ProductName = Product.getName (); // ProductName is the product name

}

IF (ProductName == null) {

ProductName = WorklistPlugin.getResourceString

"ESIP.DEFAULTPRODUCTNAME");

}

Composite composite = (Composite)

Super.createdialogarea (PARENT);

// Set icon, note that we use Abstractuiplugin.ImageDescriptorFromPlugin

// Load from the ICONS directory of the plugin, not directly using ImageDescriptor. CreateFromFile ()

// It requires an absolute path. And the former finally calls //imagedescriptor.createFromurl by establishing the correct path

SettitleImage (Abstractuiplugin.ImageDescriptorfrom) (). getpluginid (),

"icons / loginkey.gif"). CREATEIMAGE ());

// Set the title

Settitle (WorklistPlugin

.getResourceString ("Dialog.Title"));

// Set prompt information

SetMessage (MessageFormat.Format (WorklistPlugin

.getresourceString (

"Dialog.Message", new object [] {productname});

/ / Customize the content to be created

CreateContentPane (Composite);

CreateloginControls ();

Return Composite;

}

Custom CreateContentPane created a Composite to place the login tag and input box, CreateLogInTrols created the "User Name" Password "tab and the corresponding input box. as follows:

Private Void CreateContentPane (Composite Parent) {ContentPane = New Composite (Parent, Swt.Null);

// use three columns of GridLayout

GridLayout Layout = New GridLayout (3, FALSE);

// The following values ​​are derived by experimental adjustment, which looks like to make the input box in the middle position, more beautiful

Layout.Marginheight = 20;

Layout.MarginWidth = 70;

Layout.verticalspacing = 10;

Layout.horizontalspacing = 10;

ContentPane.setLayout (layout);

/ / Pay attention to Fill_Both

ContentPane.setLayOutdata (New GridData);

Contentpane.setfont (parent.getfont ());

}

Private vid createlogincontrols () {

// Label User

Label User = New Label; Contentpane, SWT.NULL;

// right alignment

GridData LayoutData = New GridData (GridData.horizontal_Align_end);

User.setLayOutdata (layoutdata);

User.setText (WorklistPlugin

.getResourceString ("Dialog.Login.user"));

// Set prompt information

User.SetTooltiptext (WorklistPlugin.getResourceString ("Dialog.login

. usrtooltip "));

// Text User

TEXT UserText = New Text (ContentPane, Swt.Border | SWT.LEAD);

// Transverse expansion

LayoutData = New Griddata (Griddata.grab_horizontal

GridData.Fill_horizontal;

// HorizontalsPan = 2 is to allow the input box to account for two layers. This looks more beautiful

LayoutData.horizontalspan = 2;

UserText.setLayOutdata (layoutdata);

UserText.SetTooltiptext (WorklistPlugin.getResourceString ("Dialog.

Login.USERTOOLTIP "));

// Label Password

Label Password = New Label (ContentPane, Swt.null);

LayoutData = New GridData (Griddata.horizontal_Align_end);

Password.setLayOutdata (layoutdata);

Password.Settext (WorklistPlugin.getResourceString ("Dialog.Login.Password"));

Password.SetTooltiptext (WorklistPlugin.getResourceString ("DIALOG.

Login.passwordtooltip "));

// text Password

Text PasswordText = New Text (ContentPane, Swt.Border | SWT.LEAD);

LayoutData = New GridData (Griddata.grab_horizontal | griddata.fill_horizontal);

LayoutData.horizontalspan = 2;

PasswordText.setLayOutdata (LayoutData);

PasswordText.sechochar ('*');

PasswordText.SetTooltiptext (WorklistPlugin.getResourceString "

"Dialog.Login.PasswordTooltip")));

}

You can rewrite ConfigureShell to make it correctly display the dialog title bar:

protected void configureshell (shell newshell) {

Super.configureShell (newshell);

Newshell.Settext (WorklistPlugin.getResourceString ("Dialog.Name"));

}

Then, again OkPressed and Cancelpressed, and processes the event when you click the OK or CANCEL button.

In this way, we get the interface as shown.

It can be seen that Eclipse's JFACE package provides us with a large number of available dialogs, such as the MessageDialog class offers OpenError, OpenConfirm, OpenInformation, OpenQuestion, OpenWarning and other dialogs. Flexiblely applying these interfaces and functions, which can be convenient and fast.

This example does not implement MessageLabel response to information. In fact, add an event listener as needed, you can implement it through SetMessage.

Small knot: expand

TitleAreadialog

Need to rewrite

CreateDialogarea

To achieve a custom interface. Different overwritten button events are processed.

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

New Post(0)