1 12 package org.eclipse.jsch.internal.ui.preference; 13 14 import org.eclipse.jface.dialogs.Dialog; 15 import org.eclipse.jface.dialogs.IDialogConstants; 16 import org.eclipse.jsch.internal.ui.Messages; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.Composite; 21 import org.eclipse.swt.widgets.Control; 22 import org.eclipse.swt.widgets.Label; 23 import org.eclipse.swt.widgets.Shell; 24 import org.eclipse.swt.widgets.Text; 25 26 27 class PassphraseDialog extends Dialog{ 28 protected Text passphraseField; 29 protected String passphrase=null; 30 protected String message=null; 31 32 public PassphraseDialog(Shell parentShell, String message){ 33 super(parentShell); 34 this.message=message; 35 } 36 37 protected void configureShell(Shell newShell){ 38 super.configureShell(newShell); 39 newShell.setText(message); 40 } 41 42 public void create(){ 43 super.create(); 44 passphraseField.setFocus(); 45 } 46 47 protected Control createDialogArea(Composite parent){ 48 initializeDialogUnits(parent); 49 Composite main=new Composite(parent, SWT.NONE); 50 51 GridLayout layout=new GridLayout(); 52 layout.numColumns=3; 53 layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 54 layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 55 layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 56 layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 57 main.setLayout(layout); 58 main.setLayoutData(new GridData(GridData.FILL_BOTH)); 59 60 if(message!=null){ 61 Label messageLabel=new Label(main, SWT.WRAP); 62 messageLabel.setText(message); 63 GridData data=new GridData(GridData.FILL_HORIZONTAL); 64 data.horizontalSpan=3; 65 messageLabel.setLayoutData(data); 66 } 67 68 createPassphraseFields(main); 69 Dialog.applyDialogFont(main); 70 return main; 71 } 72 73 protected void createPassphraseFields(Composite parent){ 74 new Label(parent, SWT.NONE).setText(Messages.CVSSSH2PreferencePage_127); 75 passphraseField=new Text(parent, SWT.BORDER); 76 GridData data=new GridData(GridData.FILL_HORIZONTAL); 77 data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH); 78 passphraseField.setLayoutData(data); 79 passphraseField.setEchoChar('*'); 80 81 new Label(parent, SWT.NONE); 82 } 83 84 public String getPassphrase(){ 85 return passphrase; 86 } 87 88 protected void okPressed(){ 89 String _passphrase=passphraseField.getText(); 90 if(_passphrase==null||_passphrase.length()==0){ 91 return; 92 } 93 passphrase=_passphrase; 94 super.okPressed(); 95 } 96 97 protected void cancelPressed(){ 98 passphrase=null; 99 super.cancelPressed(); 100 } 101 } 102 | Popular Tags |