⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 signingpasswordsdialog.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
字号:
/*
 ********************************************************************
 *
 *	Filename    :   SigningPasswordsDialog.java
 *	Package     :   eclipseme.ui.internal.dialog
 *	System      :   eclipseme.ui
 *	Author      :   Kevin Hunter
 *	Description :   Dialog for obtaining keystore and key passwords
 *					from the user.
 *	                
 * Copyright (c) 2004 Kevin Hunter
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 *
 *
 *	CVS
 *	$$Source: /cvsroot/eclipseme/eclipseme.ui/src/eclipseme/ui/internal/dialog/SigningPasswordsDialog.java,v $$
 *	$$Author: setera $$
 *	$$Date: 2006/02/11 21:27:36 $$
 *	$$Revision: 1.5 $$
 *
 ********************************************************************
 */

package eclipseme.ui.internal.dialog;

import java.text.MessageFormat;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class SigningPasswordsDialog extends TitleAreaDialog
{
	private Text	keystorePasswordText;
	private Text	keyPasswordText;
	private String	keystorePassword;
	private String	keyPassword;
	private String	dialogMessage;
	private Button	okButton;
	
	/**
	 * @param parentShell
	 */
	public SigningPasswordsDialog(Shell parentShell, IProject project)
	{
		super(parentShell);
		
		try
		{
			IProjectDescription description = project.getDescription();
			String projectName = description.getName();
			String[] args = new String[] { projectName };
			dialogMessage = MessageFormat.format(DIALOG_MESSAGE1, args);
		}
		catch(CoreException e)
		{
			dialogMessage = DIALOG_MESSAGE2;
		}
	}
	
	public void setKeystorePassword(String value)
	{
		keystorePassword = value;
	}
	
	public String getKeystorePassword()
	{
		return(keystorePassword);
	}
	
	public void setKeyPassword(String value)
	{
		keyPassword = value;
	}
	
	public String getKeyPassword()
	{
		return(keyPassword);
	}
	
	/**
	 * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createContents(Composite parent)
	{
		Control control = super.createContents(parent);
		setTitle(DIALOG_TITLE);
		setMessage(dialogMessage, IMessageProvider.INFORMATION);
		return control;
	}
	
	/**
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createDialogArea(Composite parent)
	{
		Composite dialogArea = new Composite( (Composite)super.createDialogArea(parent), SWT.NONE);
		dialogArea.setLayoutData(new GridData(GridData.FILL_BOTH));
		
		GridLayout layout = new GridLayout(2, false);
		dialogArea.setLayout(layout);
		
		Label label = new Label(dialogArea, SWT.NONE);
		label.setText(KEYSTORE_PWD_LABEL);
		
		keystorePasswordText = new Text(dialogArea, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
		keystorePasswordText.setLayoutData(buildGridData(SWT.FILL, true, 1));
		if (keystorePassword != null)
		{
			keystorePasswordText.setText(keystorePassword);
		}
		
		label = new Label(dialogArea, SWT.NONE);
		label.setText(KEY_PWD_LABEL);
		
		keyPasswordText = new Text(dialogArea, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
		keyPasswordText.setLayoutData(buildGridData(SWT.FILL, true, 1));
		if (keyPassword != null)
		{
			keyPasswordText.setText(keyPassword);
		}
		
		keystorePasswordText.addModifyListener(
				new ModifyListener()
				{
					public void modifyText(ModifyEvent e)
					{
						updateButtons();
					}
				}
		);
		
		keyPasswordText.addModifyListener(
				new ModifyListener()
				{
					public void modifyText(ModifyEvent e)
					{
						updateButtons();
					}
				}
		);
		
		updateButtons();
		
		return(dialogArea);
	}
	
	protected void createButtonsForButtonBar(Composite parent)
	{
		okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
		createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
		updateButtons();
	}
	
	private void updateButtons()
	{
		if (okButton == null || keystorePasswordText == null || keyPasswordText == null)
		{
			return;
		}
		
		String value = keystorePasswordText.getText();
		if (value == null)
		{
			okButton.setEnabled(false);
			return;
		}
		if (value.length() == 0)
		{
			okButton.setEnabled(false);
			return;
		}
		value = keyPasswordText.getText();
		if (value == null)
		{
			okButton.setEnabled(false);
			return;
		}
		if (value.length() == 0)
		{
			okButton.setEnabled(false);
			return;
		}
		okButton.setEnabled(true);
	}
	
	protected void okPressed()
	{
		keystorePassword = keystorePasswordText.getText();
		keyPassword = keyPasswordText.getText();
		
		super.okPressed();
	}
	
	private GridData buildGridData(int nFill, boolean bGrab, int nSpan)
	{
		GridData gd = new GridData();

		gd.horizontalAlignment = nFill;
		gd.grabExcessHorizontalSpace = bGrab;
		gd.horizontalSpan = nSpan;
		
		return(gd);
	}
	
	private static final String DIALOG_TITLE = "Enter passwords";
	private static final String DIALOG_MESSAGE1 = "Enter passwords for project \"{0}\"";
	private static final String DIALOG_MESSAGE2 = "Enter passwords for project";
	private static final String KEYSTORE_PWD_LABEL = "Keystore password:";
	private static final String KEY_PWD_LABEL = "Key password:";
}

/*
 ********************************************************************
 *	CVS History:
 *	$$Log: SigningPasswordsDialog.java,v $
 *	$Revision 1.5  2006/02/11 21:27:36  setera
 *	$Massive rework of emulator/device handling
 *	$
 *	$Revision 1.4  2005/07/08 21:47:12  setera
 *	$Initial 1.1.0 changes:
 *	$- Convert to manifest files for plugin.xml
 *	$- Require JDT 3.1.0 for our feature
 *	$- Fix up build files to include new manifest files
 *	$- Fix up some of the deprecations
 *	$
 *	$Revision 1.3  2004/11/27 21:31:13  kdhunter
 *	$Added borders to text boxes
 *	$
 *	$Revision 1.2  2004/11/27 18:26:53  kdhunter
 *	$Added project name to dialog
 *	$Converted to TitleAreaDialog to look more professional
 *	$
 *	$Revision 1.1  2004/11/26 22:57:55  kdhunter
 *	$Dialog for asking user for passwords
 *	$$
 *
 ********************************************************************
 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -