001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.wizards.exports;
011:
012: import org.eclipse.jface.dialogs.Dialog;
013: import org.eclipse.jface.dialogs.IDialogSettings;
014: import org.eclipse.pde.internal.ui.IHelpContextIds;
015: import org.eclipse.pde.internal.ui.PDEPlugin;
016: import org.eclipse.pde.internal.ui.PDEUIMessages;
017: import org.eclipse.pde.internal.ui.util.SWTUtil;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.events.ModifyEvent;
020: import org.eclipse.swt.events.ModifyListener;
021: import org.eclipse.swt.events.SelectionAdapter;
022: import org.eclipse.swt.events.SelectionEvent;
023: import org.eclipse.swt.layout.GridData;
024: import org.eclipse.swt.layout.GridLayout;
025: import org.eclipse.swt.widgets.Button;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Control;
028: import org.eclipse.swt.widgets.FileDialog;
029: import org.eclipse.swt.widgets.Label;
030: import org.eclipse.swt.widgets.Text;
031: import org.eclipse.ui.PlatformUI;
032:
033: public class JARSigningTab {
034:
035: private static final String S_SIGN_JARS = "signJAR"; //$NON-NLS-1$
036: private static final String S_KEYSTORE = "keystore"; //$NON-NLS-1$
037: private static final String S_ALIAS = "alias"; //$NON-NLS-1$
038: private static final String S_PASSWORD = "password"; //$NON-NLS-1$
039:
040: private Button fButton;
041:
042: private Label fKeystoreLabel;
043: private Text fKeystoreText;
044:
045: private Label fAliasLabel;
046: private Text fAliasText;
047:
048: private Label fPasswordLabel;
049: private Text fPasswordText;
050: private BaseExportWizardPage fPage;
051: private Button fBrowseButton;
052:
053: public JARSigningTab(BaseExportWizardPage page) {
054: fPage = page;
055: }
056:
057: public Control createControl(Composite parent) {
058: Composite comp = new Composite(parent, SWT.NONE);
059: comp.setLayout(new GridLayout(3, false));
060: comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
061:
062: fButton = new Button(comp, SWT.CHECK);
063: fButton
064: .setText(PDEUIMessages.AdvancedPluginExportPage_signButton);
065: GridData gd = new GridData();
066: gd.horizontalSpan = 3;
067: fButton.setLayoutData(gd);
068: fButton.addSelectionListener(new SelectionAdapter() {
069: public void widgetSelected(SelectionEvent e) {
070: updateGroup(fButton.getSelection());
071: fPage.pageChanged();
072: }
073: });
074:
075: fKeystoreLabel = createLabel(comp,
076: PDEUIMessages.AdvancedPluginExportPage_keystore);
077: fKeystoreText = createText(comp, 1);
078:
079: fBrowseButton = new Button(comp, SWT.PUSH);
080: fBrowseButton.setText(PDEUIMessages.ExportWizard_browse);
081: fBrowseButton.setLayoutData(new GridData());
082: SWTUtil.setButtonDimensionHint(fBrowseButton);
083: fBrowseButton.addSelectionListener(new SelectionAdapter() {
084: public void widgetSelected(SelectionEvent e) {
085: FileDialog dialog = new FileDialog(fPage.getShell(),
086: SWT.OPEN);
087: String path = fKeystoreText.getText();
088: if (path.trim().length() == 0)
089: path = PDEPlugin.getWorkspace().getRoot()
090: .getLocation().toString();
091: dialog.setFileName(path);
092: String res = dialog.open();
093: if (res != null) {
094: fKeystoreText.setText(res);
095: }
096: }
097: });
098:
099: fAliasLabel = createLabel(comp,
100: PDEUIMessages.AdvancedPluginExportPage_alias);
101: fAliasText = createText(comp, 2);
102:
103: fPasswordLabel = createLabel(comp,
104: PDEUIMessages.AdvancedPluginExportPage_password);
105: fPasswordText = createText(comp, 2);
106: fPasswordText.setEchoChar('*');
107:
108: Dialog.applyDialogFont(comp);
109: PlatformUI.getWorkbench().getHelpSystem().setHelp(comp,
110: IHelpContextIds.ADVANCED_PLUGIN_EXPORT);
111: return comp;
112: }
113:
114: protected void initialize(IDialogSettings settings) {
115: fKeystoreText.setText(getString(settings, S_KEYSTORE));
116: fAliasText.setText(getString(settings, S_ALIAS));
117: fPasswordText.setText(getString(settings, S_PASSWORD));
118: fButton.setSelection(settings.getBoolean(S_SIGN_JARS));
119: updateGroup(fButton.getSelection());
120: }
121:
122: private String getString(IDialogSettings settings, String key) {
123: String value = settings.get(key);
124: return value == null ? "" : value; //$NON-NLS-1$
125: }
126:
127: protected Label createLabel(Composite group, String text) {
128: Label label = new Label(group, SWT.NONE);
129: label.setText(text);
130: GridData gd = new GridData();
131: gd.horizontalIndent = 15;
132: label.setLayoutData(gd);
133: return label;
134: }
135:
136: protected Text createText(Composite group, int span) {
137: Text text = new Text(group, SWT.SINGLE | SWT.BORDER);
138: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
139: gd.horizontalSpan = span;
140: text.setLayoutData(gd);
141: text.addModifyListener(new ModifyListener() {
142: public void modifyText(ModifyEvent e) {
143: fPage.pageChanged();
144: }
145: });
146: return text;
147: }
148:
149: protected String validate() {
150: String error = null;
151: if (fButton.getSelection()) {
152: if (fKeystoreText.getText().trim().length() == 0) {
153: error = PDEUIMessages.AdvancedPluginExportPage_noKeystore;
154: } else if (fAliasText.getText().trim().length() == 0) {
155: error = PDEUIMessages.AdvancedPluginExportPage_noAlias;
156: } else if (fPasswordText.getText().trim().length() == 0) {
157: error = PDEUIMessages.AdvancedPluginExportPage_noPassword;
158: }
159: }
160: return error;
161: }
162:
163: private void updateGroup(boolean enabled) {
164: fKeystoreLabel.setEnabled(enabled);
165: fKeystoreText.setEnabled(enabled);
166: fBrowseButton.setEnabled(enabled);
167: fAliasLabel.setEnabled(enabled);
168: fAliasText.setEnabled(enabled);
169: fPasswordLabel.setEnabled(enabled);
170: fPasswordText.setEnabled(enabled);
171: }
172:
173: protected void saveSettings(IDialogSettings settings) {
174: settings.put(S_SIGN_JARS, fButton.getSelection());
175: settings.put(S_KEYSTORE, fKeystoreText.getText().trim());
176: settings.put(S_ALIAS, fAliasText.getText().trim());
177: settings.put(S_PASSWORD, fPasswordText.getText().trim());
178: }
179:
180: protected String[] getSigningInfo() {
181: if (fButton.getSelection()) {
182: return new String[] { fAliasText.getText().trim(),
183: fKeystoreText.getText().trim(),
184: fPasswordText.getText().trim() };
185: }
186: return null;
187: }
188: }
|