1 11 package org.eclipse.pde.internal.ui.wizards.exports; 12 13 import org.eclipse.jface.dialogs.Dialog; 14 import org.eclipse.jface.dialogs.IDialogSettings; 15 import org.eclipse.pde.internal.ui.IHelpContextIds; 16 import org.eclipse.pde.internal.ui.PDEUIMessages; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.events.ModifyEvent; 19 import org.eclipse.swt.events.ModifyListener; 20 import org.eclipse.swt.events.SelectionAdapter; 21 import org.eclipse.swt.events.SelectionEvent; 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.layout.GridLayout; 24 import org.eclipse.swt.widgets.Button; 25 import org.eclipse.swt.widgets.Composite; 26 import org.eclipse.swt.widgets.Group; 27 import org.eclipse.swt.widgets.Label; 28 import org.eclipse.swt.widgets.Text; 29 import org.eclipse.ui.PlatformUI; 30 31 public class AdvancedPluginExportPage extends ExportWizardPage { 32 33 private static final String S_SIGN_JARS = "signJAR"; private static final String S_KEYSTORE = "keystore"; private static final String S_ALIAS = "alias"; private static final String S_PASSWORD = "password"; 38 private Button fButton; 39 private Label fKeystoreLabel; 40 private Text fKeystoreText; 41 private Label fAliasLabel; 42 private Text fAliasText; 43 private Label fPasswordLabel; 44 private Text fPasswordText; 45 46 public AdvancedPluginExportPage(String pageName) { 47 super(pageName); 48 setTitle(PDEUIMessages.AdvancedPluginExportPage_title); setDescription(getDescriptionText()); } 51 52 protected String getDescriptionText() { 53 return PDEUIMessages.AdvancedPluginExportPage_desc; } 55 56 public void createControl(Composite parent) { 57 Composite container = new Composite(parent, SWT.NONE); 58 GridLayout layout = new GridLayout(); 59 layout.marginHeight = 15; 60 layout.verticalSpacing = 15; 61 container.setLayout(layout); 62 63 createSigningSection(container); 64 createJNLPSection(container); 65 66 Dialog.applyDialogFont(container); 67 validatePage(); 68 setControl(container); 69 70 PlatformUI.getWorkbench().getHelpSystem().setHelp(container, IHelpContextIds.ADVANCED_PLUGIN_EXPORT); 71 } 72 73 private void createSigningSection(Composite parent) { 74 Group group = new Group(parent, SWT.NONE); 75 group.setText(PDEUIMessages.AdvancedPluginExportPage_signJar); group.setLayout(new GridLayout(2, false)); 77 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 78 79 IDialogSettings settings = getDialogSettings(); 80 81 fButton = createbutton(group, PDEUIMessages.AdvancedPluginExportPage_signButton); fButton.addSelectionListener(new SelectionAdapter() { 83 public void widgetSelected(SelectionEvent e) { 84 boolean selected = fButton.getSelection(); 85 updateGroup(selected); 86 validatePage(); 87 } 88 }); 89 90 fKeystoreLabel = createLabel(group, PDEUIMessages.AdvancedPluginExportPage_keystore); fKeystoreText = createText(group); 92 fKeystoreText.setText(getString(S_KEYSTORE)); 93 94 fAliasLabel = createLabel(group, PDEUIMessages.AdvancedPluginExportPage_alias); fAliasText = createText(group); 96 fAliasText.setText(getString(S_ALIAS)); 97 98 fPasswordLabel = createLabel(group, PDEUIMessages.AdvancedPluginExportPage_password); fPasswordText = createText(group); 100 fPasswordText.setEchoChar('*'); 101 fPasswordText.setText(getString(S_PASSWORD)); 102 103 fButton.setSelection(settings.getBoolean(S_SIGN_JARS)); 104 updateGroup(fButton.getSelection()); 105 } 106 107 protected String getString(String key) { 108 String value = getDialogSettings().get(key); 109 return value == null ? "" : value; } 111 112 protected Button createbutton(Composite group, String text) { 113 Button button = new Button(group, SWT.CHECK); 114 button.setText(text); 115 GridData gd = new GridData(); 116 gd.horizontalSpan = 2; 117 button.setLayoutData(gd); 118 return button; 119 } 120 121 protected Label createLabel(Composite group, String text) { 122 Label label = new Label(group, SWT.NONE); 123 label.setText(text); 124 GridData gd = new GridData(); 125 gd.horizontalIndent = 30; 126 label.setLayoutData(gd); 127 return label; 128 } 129 130 protected Text createText(Composite group) { 131 Text text = new Text(group, SWT.SINGLE|SWT.BORDER); 132 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 133 text.addModifyListener(new ModifyListener() { 134 public void modifyText(ModifyEvent e) { 135 validatePage(); 136 } 137 }); 138 return text; 139 } 140 141 protected void createJNLPSection(Composite parent) { 142 } 143 144 protected void validatePage() { 145 if (!isCurrentPage()) 146 return; 147 forceValidatePage(); 148 } 149 150 protected void forceValidatePage() { 151 String error = null; 152 if (fButton.getSelection()) { 153 if (fKeystoreText.getText().trim().length() == 0) { 154 error = PDEUIMessages.AdvancedPluginExportPage_noKeystore; } else if (fAliasText.getText().trim().length() == 0) { 156 error = PDEUIMessages.AdvancedPluginExportPage_noAlias; } else if (fPasswordText.getText().trim().length() == 0) { 158 error = PDEUIMessages.AdvancedPluginExportPage_noPassword; } 160 } 161 setErrorMessage(error); 162 setPageComplete(error == null); 163 } 164 165 private void updateGroup(boolean enabled) { 166 fKeystoreLabel.setEnabled(enabled); 167 fKeystoreText.setEnabled(enabled); 168 fAliasLabel.setEnabled(enabled); 169 fAliasText.setEnabled(enabled); 170 fPasswordLabel.setEnabled(enabled); 171 fPasswordText.setEnabled(enabled); 172 } 173 174 public void saveSettings() { 175 IDialogSettings settings = getDialogSettings(); 176 settings.put(S_SIGN_JARS, fButton.getSelection()); 177 settings.put(S_KEYSTORE, fKeystoreText.getText().trim()); 178 settings.put(S_ALIAS, fAliasText.getText().trim()); 179 settings.put(S_PASSWORD, fPasswordText.getText().trim()); 180 } 181 182 public String [] getSigningInfo() { 183 if (fButton.getSelection()) { 184 return new String [] { fAliasText.getText().trim(), 185 fKeystoreText.getText().trim(), 186 fPasswordText.getText().trim() }; 187 } 188 return null; 189 } 190 191 public String [] getJNLPInfo() { 192 return null; 193 } 194 195 } 196 | Popular Tags |