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

📄 j2mesigningpropertiespage.java

📁 配置文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
						validatePage();
					}
				}
		);
		
		promptForPasswordRadio.addSelectionListener(
				new SelectionAdapter()
				{
					public void widgetSelected(SelectionEvent e)
					{
						Button b = (Button)e.widget;
						if (b.getSelection())
						{
							validatePage();
						}
					}
				}
		);
		
		savePasswordsInKeyringRadio.addSelectionListener(
				new SelectionAdapter()
				{
					public void widgetSelected(SelectionEvent e)
					{
						Button b = (Button)e.widget;
						if (b.getSelection())
						{
							validatePage();
						}
					}
				}
		);
		
		savePasswordsInProjectRadio.addSelectionListener(
				new SelectionAdapter()
				{
					public void widgetSelected(SelectionEvent e)
					{
						Button b = (Button)e.widget;
						if (b.getSelection())
						{
							validatePage();
						}
					}
				}
		);
		
		keyfileInternalBrowseButton.addSelectionListener(
				new SelectionAdapter()
				{
					public void widgetSelected(SelectionEvent e)
					{
						browseProjectForKeystore();
						validatePage();
					}
				}
		);
		
		keyfileExternalBrowseButton.addSelectionListener(
				new SelectionAdapter()
				{
					public void widgetSelected(SelectionEvent e)
					{
						browseExternalForKeystore();
						validatePage();
					}
				}
		);
		
		aliasText.addModifyListener(
				new ModifyListener()
				{
					public void modifyText(ModifyEvent e)
					{
						validatePage();
					}
				}
		);
		
		keystorePassText.addModifyListener(
				new ModifyListener()
				{
					public void modifyText(ModifyEvent e)
					{
						validatePage();
					}
				}
		);
		
		keyPassText.addModifyListener(
				new ModifyListener()
				{
					public void modifyText(ModifyEvent e)
					{
						validatePage();
					}
				}
		);
		
		testButton.addSelectionListener(
				new SelectionAdapter()
				{
					public void widgetSelected(SelectionEvent e)
					{
						testSettings();
					}
				}
		);
	}
	
	/*
	 * Utility routine to insert a label with the specified text onto the specified parent
	 */
	private Label insertLabel(Composite parent, String text)
	{
		Label lbl = new Label(parent, SWT.LEFT);
		lbl.setText(text);
		return(lbl);
	}
	
	/*
	 * Utility routine to build a GridData item
	 */
	private GridData buildGridData(int nFill, boolean bGrab, int nSpan)
	{
		GridData gd = new GridData();

		gd.horizontalAlignment = nFill;
		gd.grabExcessHorizontalSpace = bGrab;
		gd.horizontalSpan = nSpan;
		
		return(gd);
	}
	
	/*
	 * This routine is responsible for initializing all the controls on
	 * the page to the current values in the Midlet Suite project.
	 */
	private void loadPageData()
	{
		// Get the associated midlet suite project
		IMidletSuiteProject midletProject = getMidletSuiteProject();

		ISignatureProperties props = null;
		try
		{
			props = midletProject.getSignatureProperties();
		}
		catch (CoreException e)
		{
		}

		if (props != null)
		{
			sigProps.copy(props);
		}
		else
		{
			sigProps.clear();
		}
		
		loadSigningData();
	}
	
	/*
	 * This routine loads the controls that are part of the Signing Properties
	 * Group.  It is separated from loadPageData() because we also need to do
	 * this in response to the "Defaults" button being pressed.
	 */
	private void loadSigningData()
	{
		bLoading = true;
		
		signProjectCheckButton.setSelection(sigProps.getSignProject());
		keyfilePath.setText(convertNullToEmpty(sigProps.getKeyStoreDisplayPath()));
		isKeyfileExternal = sigProps.isKeyStorePathExternal();
		aliasText.setText(convertNullToEmpty(sigProps.getKeyAlias()));

		switch(sigProps.getPasswordStorageMethod())
		{
		case ISignatureProperties.PASSMETHOD_IN_PROJECT:
			promptForPasswordRadio.setSelection(false);
			savePasswordsInKeyringRadio.setSelection(false);
			savePasswordsInProjectRadio.setSelection(true);
			keystorePassText.setText(convertNullToEmpty(sigProps.getKeyStorePassword()));
			keyPassText.setText(convertNullToEmpty(sigProps.getKeyPassword()));
			break;
			
		case ISignatureProperties.PASSMETHOD_IN_KEYRING:
			promptForPasswordRadio.setSelection(false);
			savePasswordsInKeyringRadio.setSelection(true);
			savePasswordsInProjectRadio.setSelection(false);
			keystorePassText.setText(convertNullToEmpty(sigProps.getKeyStorePassword()));
			keyPassText.setText(convertNullToEmpty(sigProps.getKeyPassword()));
			break;
			
		case ISignatureProperties.PASSMETHOD_PROMPT:
		default:
			promptForPasswordRadio.setSelection(true);
			savePasswordsInKeyringRadio.setSelection(false);
			savePasswordsInProjectRadio.setSelection(false);
			break;
		}
		
		providerText.setText(convertNullToEmpty(sigProps.getKeyStoreProvider()));
		keystoreTypeText.setText(convertNullToEmpty(sigProps.getKeyStoreType()));
		
		bLoading = false;
		
		validatePage();
	}
	
	/*
	 * Utility routine to convert a null value to an empty string when
	 * loading Text widgets.
	 */
	private String convertNullToEmpty(String s)
	{
		if (s == null)
		{
			return(""); //$NON-NLS-1$
		}
		
		return(s);
	}
	
	/*
	 * Utility routine to convert an empty string to a null value when
	 * unloading Text widgets.
	 */
	public String convertEmptyToNull(String s)
	{
		if (s == null)
		{
			return(null);
		}
		
		if (s.length() == 0)
		{
			return(null);
		}
		
		return(s);
	}
	
	/*
	 * This routine validates the data on the page, updating the buttons
	 * on the form at the same time.
	 */
	private void validatePage()
	{
		bSigningDataValid = updateSigningFields();
		updateApplyButton();
		getContainer().updateButtons();
	}
	
	/*
	 * This routine updates the state of the various Signing Properties fields.
	 * Depending on the various settings, this involves enabling and disabling
	 * some of the fields.  Values are also checked for validity, and the 
	 * error label updated appropriately.
	 * 
	 * Returns true if all the fields are in a self-consistent and valid state,
	 * false otherwise.
	 */
	private boolean updateSigningFields()
	{
		// Don't run the tests while loading.  Event listeners may
		// be triggered while the form isn't self-consistent during
		// the load process.
		if (bLoading)
		{
			return(true);
		}
		
		// The "sign it" checkbox enables or disables everything
		
		boolean bSign = signProjectCheckButton.getSelection();
		
		keyfilePathLabel.setEnabled(bSign);
		keyfilePath.setEnabled(bSign);
		keyfileExternalBrowseButton.setEnabled(bSign);
		aliasLabel.setEnabled(bSign);
		aliasText.setEnabled(bSign);
		promptForPasswordRadio.setEnabled(bSign);
		savePasswordsInProjectRadio.setEnabled(bSign);
		savePasswordsInKeyringRadio.setEnabled(bSign);
		advancedGroup.setEnabled(bSign);
		advancedInstructions.setEnabled(bSign);
		providerLabel.setEnabled(bSign);
		providerText.setEnabled(bSign);
		keystoreTypeLabel.setEnabled(bSign);
		keystoreTypeText.setEnabled(bSign);
		
		if (!bSign)
		{
			keystorePassLabel.setEnabled(false);
			keystorePassText.setEnabled(false);
			keyPassLabel.setEnabled(false);
			keyPassText.setEnabled(false);
			sigProps.clear();
			errorLabel.setText(""); //$NON-NLS-1$
			testButton.setEnabled(false);
			return(true);
		}

		testButton.setEnabled(false);	// assume for now, check later

		boolean bSave = !promptForPasswordRadio.getSelection();
		keystorePassLabel.setEnabled(bSave);
		keystorePassText.setEnabled(bSave);
		keyPassLabel.setEnabled(bSave);
		keyPassText.setEnabled(bSave);
		
		sigProps.setSignProject(true);
		
		// pull out the various text fields, validating them as we go
		
		if (!isKeystorePathValid())
		{
			return(false);
		}
		
		sigProps.setKeyStoreDisplayPath(convertEmptyToNull(keyfilePath.getText()));
		

⌨️ 快捷键说明

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