|
package test.test.gc; import gef.tutorial.stepii.StepiiPlugin; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.TitleAreaDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; //import MyTestPlugin.preferences.PreferenceConstants; //import MyTestPlugin.util.LayoutUtil; /** 登錄對話框 */ public class LoginDialog extends TitleAreaDialog { /** 用戶名 */ private Text userName; /** 密碼 */ private Text password; public LoginDialog(Shell parentShell) { super(parentShell); } /** 設(shè)置登錄對話框的屬性 */ protected void configureShell(Shell newShell) { //super.configureShell(newShell); newShell.setText("用戶登錄"); newShell.setSize(300, 200); newShell.setImage(Display.getDefault().getSystemImage(SWT.ICON_WORKING)); //newShell.setImage(StepiiPlugin.getImageDescriptor("icons/sample.gif").createImage()); //LayoutUtil.centerShell(Display.getCurrent(), newShell); } /** 設(shè)置登錄對話框的內(nèi)容屬性 */ protected Control createContents(Composite parent) { super.createContents(parent); this.setTitle("用戶登錄"); this.setMessage("請輸入用戶名和密碼登錄系統(tǒng)"); //this.setTitleImage(Image.win32_new (Display.getDefault(), SWT.ICON, 65545)); return parent; } /** 設(shè)置登錄對話框內(nèi)容區(qū)的屬性 */ protected Control createDialogArea(Composite parent) { super.createDialogArea(parent); Composite composite = new Composite(parent, SWT.NONE); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); GridLayout layout = new GridLayout(2, false); composite.setLayout(layout); new Label(composite, SWT.NONE).setText("用戶名:"); userName = new Text(composite, SWT.BORDER); userName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); new Label(composite, SWT.NONE).setText("密碼:"); password = new Text(composite, SWT.BORDER); password.setEchoChar(‘*‘); password.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); return parent; } /** 覆蓋父類的方法,當(dāng)單擊按鈕時(shí)調(diào)用 */ protected void buttonPressed(int buttonId) { /** 如果單擊了確定按鈕 */ if (IDialogConstants.OK_ID == buttonId) { /** 用戶名不為空 */ if (userName.getText().equals("")) { this.setErrorMessage("用戶名不為空"); return; } /** 密碼不為空 */ if (password.getText().equals("")) { //this.setTitleImage(Image.win32_new (Display.getDefault(), SWT.ICON, 65545)); this.setErrorMessage("密碼不為空!"); return; } /**驗(yàn)證用戶名密碼*/ boolean bValid = checkValid(); if (!bValid) { this.setErrorMessage("用戶名或密碼錯(cuò)誤!"); return; } okPressed(); } else if (IDialogConstants.CANCEL_ID == buttonId) cancelPressed(); } /** 判斷驗(yàn)證用戶名和密碼 */ private boolean checkValid() { boolean bValid = false; /**將用戶輸入用戶名與首選項(xiàng)中設(shè)置的用戶名和密碼對比,如果正確,則驗(yàn)證成功*/ //IPreferenceStore store = StepiiPlugin.getDefault().getPreferenceStore(); //if (userName.getText().equals(store.getString(PreferenceConstants.P_USER_NAME)) && password.getText().equals(store.getString(PreferenceConstants.P_USER_NAME))) //bValid = true; return bValid; } } |
|
|