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

📄 j2mesigningpropertiespage.java

📁 eclipseme的最新版本的source,欢迎j2me程序员使用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * Copyright (c) 2003-2005 Craig Setera
 * All Rights Reserved.
 * Licensed under the Eclipse Public License - v 1.0
 * For more information see http://www.eclipse.org/legal/epl-v10.html
 * 
 * Signature support added 2004 by Kevin Hunter
 */
package eclipseme.ui.internal.properties;

import java.io.File;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
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.FileDialog;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchPropertyPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.dialogs.ISelectionStatusValidator;
import org.eclipse.ui.dialogs.PropertyPage;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;

import eclipseme.core.IEclipseMECoreConstants;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.signing.SignatureUtils;
import eclipseme.core.model.IJadSignature;
import eclipseme.core.model.IMidletSuiteProject;
import eclipseme.core.model.ISignatureProperties;
import eclipseme.core.model.MidletSuiteFactory;
import eclipseme.core.nature.J2MENature;
import eclipseme.core.signing.SignatureProperties;
import eclipseme.ui.EclipseMEUIErrors;
import eclipseme.ui.EclipseMEUIStrings;
import eclipseme.ui.IEclipseMEUIConstants;

/**
 * Property page implementation for J2ME properties associated
 * with signing the project.
 * <p />
 * Copyright (c) 2003-2005 Craig Setera<br>
 * All Rights Reserved.<br>
 * Licensed under the Eclipse Public License - v 1.0<p/>
 * <br>
 * $Revision: 1.4 $
 * <br>
 * $Date: 2006/11/12 01:10:48 $
 * <br>
 * @author Craig Setera
 * @author Kevin Hunter
 * @see PropertyPage
 */
public class J2MESigningPropertiesPage 
	extends PropertyPage 
	implements IWorkbenchPropertyPage 
{
	private CLabel	errorLabel;					// label into which error messages are placed
	
	private Button	signProjectCheckButton;		// "Sign project?" checkbox

	private Label	keyfilePathLabel;
	private Label	keyfilePath;				// path to keyfile label
	private Button	keyfileExternalBrowseButton;// "External" browse button for keyfile text box
	private Button	keyfileInternalBrowseButton;// "Internal" browse button for keyfile text box
	private boolean	isKeyfileExternal;

	private Label	aliasLabel;
	private Text	aliasText;					// key alias text box

	private Button	promptForPasswordRadio;		// "prompt" radio button 
	private Button	savePasswordsInKeyringRadio;// "save" radio button
	private Button	savePasswordsInProjectRadio;// "save" radio button

	private Label	keystorePassLabel;
	private Text	keystorePassText;			// keystore password text box

	private Label	keyPassLabel;
	private Text	keyPassText;				// key password text box

	private Group	advancedGroup;				// "advanced" group
	private Label	advancedInstructions;
	private Label	providerLabel;
	private Text	providerText;				// crypto provider text box
	private Label	keystoreTypeLabel;
	private Text	keystoreTypeText;			// keystore type text box
	
	private Button	testButton;					// "test settings" button
	
	private SignatureProperties	sigProps;		// signature properties object
	
	private boolean bLoading = false;			// true while loading to defer validation
	private boolean bSigningDataValid = false;	// true if signing data is currently valid

	/**
	 * Default constructor.
	 */
	public J2MESigningPropertiesPage()
	{
	}
	
	/**
	 * Returns <code>true</code> if the page data is currently valid.
	 * @see org.eclipse.jface.preference.IPreferencePage#isValid()
	 */
	public boolean isValid()
	{
		return bSigningDataValid;
	}
	
	/**
	 * @see org.eclipse.jface.preference.IPreferencePage#performOk()
	 */
	public boolean performOk()
	{
		IProject project = getProject();

		boolean isJ2meProject = false;
		try
		{
			isJ2meProject = J2MENature.hasJ2MENature(project);
		} 
		catch (CoreException e)
		{
		}
		
		if (!isJ2meProject)
		{
			return(true);
		}
		
		boolean succeeded = false;
		
		try
		{
			IMidletSuiteProject midletProject = getMidletSuiteProject();
			midletProject.setSignatureProperties(sigProps);
			midletProject.saveMetaData();
			
			succeeded = true;
		}
		catch (Exception ex)
		{
			EclipseMEUIErrors.displayError(	getShell(),
											"EclipseMEUiError.Exception",			//$NON-NLS-1$
											"EclipseMEUiError.SetPlatformFailed",	//$NON-NLS-1$
											ex);
		}
		
		return succeeded;
	}
	
	/**
	 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
	 */
	protected void performDefaults()
	{
		super.performDefaults();
		
		sigProps.clear();	// restore signing settings to defaults
		
		loadSigningData();	// reload the page data
	}

	/**
	 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
	 */
	protected Control createContents(Composite parent)
	{
		PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, "eclipseme.ui.help_J2MEProjectPropertiesPage");
		
		IProject project = getProject();
		
		if (!isJ2MEProject(project))
		{
			Label lbl = new Label(parent, SWT.NONE);
			lbl.setText(EclipseMEUIStrings.getString("J2MEProjectPropertiesPage.NotMidletSuiteProject")); //$NON-NLS-1$
			return(lbl);
		}

		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(1, true));
		
		errorLabel = new CLabel(composite, SWT.LEFT);
		errorLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		FontData[] fd = errorLabel.getFont().getFontData();
		Font f = new Font(parent.getDisplay(), fd[0].getName(), fd[0].getHeight(), SWT.BOLD);
		errorLabel.setFont(f);
		
		Group signingGroup = new Group(composite, SWT.NONE);
		signingGroup.setText(SIGNING_GROUP_TEXT);
		signingGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
		
		populateSigningGroup(signingGroup);

		sigProps = new SignatureProperties();
		
		loadPageData();
		
		return composite;
	}
	
	/**
	 * Return a boolean indicating whether the controls should be read only
	 * for the specified project.
	 * 
	 * @param project
	 * @return
	 */
	private boolean isReadOnly(IProject project) {
		boolean readOnly = false;

		try {
			readOnly = project.hasNature(IEclipseMECoreConstants.J2ME_PREPROCESSED_NATURE_ID);
		} catch (CoreException e) {
			EclipseMECorePlugin.log(IStatus.WARNING, e);
		}
		
		return readOnly; 
	}

	/*
	 * This routine builds all the controls in the "Signing Properties" Group
	 */
	private void populateSigningGroup(Group signingGroup)
	{
		signingGroup.setLayout(new GridLayout(4, false));

		signProjectCheckButton = new Button(signingGroup, SWT.CHECK);
		signProjectCheckButton.setText(SIGN_PROJECT_CHECK_BUTTON_TEXT);
		signProjectCheckButton.setLayoutData(buildGridData(SWT.BEGINNING, false, 4));
		signProjectCheckButton.setEnabled(!isReadOnly(getProject()));
		
		keyfilePathLabel = insertLabel(signingGroup, KEYSTORE_LABEL_TEXT);
		
		keyfilePath = new Label(signingGroup, SWT.LEFT | SWT.BORDER);
		keyfilePath.setLayoutData(buildGridData(SWT.FILL, true, 1));
		
		keyfileInternalBrowseButton = new Button(signingGroup, SWT.PUSH);
		keyfileInternalBrowseButton.setText(INTERNAL_BROWSE_BUTTON_TEXT);
		keyfileInternalBrowseButton.setLayoutData(buildGridData(SWT.END, false, 1));
		
		keyfileExternalBrowseButton = new Button(signingGroup, SWT.PUSH);
		keyfileExternalBrowseButton.setText(EXTERNAL_BROWSE_BUTTON_TEXT);
		keyfileExternalBrowseButton.setLayoutData(buildGridData(SWT.END, false, 1));
		
		aliasLabel = insertLabel(signingGroup, ALIAS_LABEL_TEXT);
		
		aliasText = new Text(signingGroup, SWT.SINGLE | SWT.BORDER);
		aliasText.setLayoutData(buildGridData(SWT.FILL, false, 3));
		
		new Label(signingGroup, SWT.SEPARATOR | SWT.HORIZONTAL).setLayoutData(buildGridData(SWT.FILL, false, 4));
		
		promptForPasswordRadio = new Button(signingGroup, SWT.RADIO);
		promptForPasswordRadio.setText(PROMPT_FOR_PWD_LABEL_TEXT);
		promptForPasswordRadio.setLayoutData(buildGridData(SWT.BEGINNING, false, 4));
		
		savePasswordsInKeyringRadio = new Button(signingGroup, SWT.RADIO);
		savePasswordsInKeyringRadio.setText(STORE_PWD_KEYRING_LABEL_TEXT);
		savePasswordsInKeyringRadio.setLayoutData(buildGridData(SWT.BEGINNING, false, 4));

		savePasswordsInProjectRadio = new Button(signingGroup, SWT.RADIO);
		savePasswordsInProjectRadio.setText(STORE_PWD_PROJECT_LABEL_TEXT);
		savePasswordsInProjectRadio.setLayoutData(buildGridData(SWT.BEGINNING, false, 4));

		keystorePassLabel = insertLabel(signingGroup, KEYSTORE_PWD_LABEL_TEXT);
		
		keystorePassText = new Text(signingGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
		keystorePassText.setLayoutData(buildGridData(SWT.FILL, false, 3));
		
		keyPassLabel = insertLabel(signingGroup, KEY_PWD_LABEL_TEXT);
		
		keyPassText = new Text(signingGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD);
		keyPassText.setLayoutData(buildGridData(SWT.FILL, false, 3));
		
		advancedGroup = new Group(signingGroup, SWT.NONE);
		advancedGroup.setLayout(new GridLayout(2, false));
		advancedGroup.setText(ADVANCED_GROUP_TEXT);
		advancedGroup.setLayoutData(buildGridData(SWT.FILL, false, 4));
		
		advancedInstructions = new Label(advancedGroup, SWT.LEFT);
		advancedInstructions.setText(ADVANCED_TEXT);
		advancedInstructions.setLayoutData(buildGridData(SWT.BEGINNING, false, 3));
		
		providerLabel = insertLabel(advancedGroup, PROVIDER_LABEL_TEXT);
		providerText = new Text(advancedGroup, SWT.SINGLE | SWT.BORDER);
		providerText.setLayoutData(buildGridData(SWT.FILL, true, 2));

		keystoreTypeLabel = insertLabel(advancedGroup, KEYSTORE_TYPE_LABEL_TEXT);
		keystoreTypeText = new Text(advancedGroup, SWT.SINGLE | SWT.BORDER);
		keystoreTypeText.setLayoutData(buildGridData(SWT.FILL, true, 2));
		
		testButton = new Button(signingGroup, SWT.PUSH);
		testButton.setText(TEST_BUTTON_TEXT);
		testButton.setLayoutData(buildGridData(SWT.BEGINNING, false, 1));
		
		signProjectCheckButton.addSelectionListener(
				new SelectionAdapter()
				{
					public void widgetSelected(SelectionEvent e)
					{

⌨️ 快捷键说明

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