KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > wizards > exports > AdvancedPluginExportPage


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 JavaDoc S_SIGN_JARS = "signJAR"; //$NON-NLS-1$
34
private static final String JavaDoc S_KEYSTORE = "keystore"; //$NON-NLS-1$
35
private static final String JavaDoc S_ALIAS = "alias"; //$NON-NLS-1$
36
private static final String JavaDoc S_PASSWORD = "password"; //$NON-NLS-1$
37

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 JavaDoc pageName) {
47         super(pageName);
48         setTitle(PDEUIMessages.AdvancedPluginExportPage_title); //$NON-NLS-1$
49
setDescription(getDescriptionText()); //$NON-NLS-1$
50
}
51     
52     protected String JavaDoc getDescriptionText() {
53         return PDEUIMessages.AdvancedPluginExportPage_desc; //$NON-NLS-1$
54
}
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); //$NON-NLS-1$
76
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); //$NON-NLS-1$
82
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); //$NON-NLS-1$
91
fKeystoreText = createText(group);
92         fKeystoreText.setText(getString(S_KEYSTORE));
93         
94         fAliasLabel = createLabel(group, PDEUIMessages.AdvancedPluginExportPage_alias); //$NON-NLS-1$
95
fAliasText = createText(group);
96         fAliasText.setText(getString(S_ALIAS));
97         
98         fPasswordLabel = createLabel(group, PDEUIMessages.AdvancedPluginExportPage_password); //$NON-NLS-1$
99
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 JavaDoc getString(String JavaDoc key) {
108         String JavaDoc value = getDialogSettings().get(key);
109         return value == null ? "" : value; //$NON-NLS-1$
110
}
111     
112     protected Button createbutton(Composite group, String JavaDoc 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 JavaDoc 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 JavaDoc error = null;
152         if (fButton.getSelection()) {
153             if (fKeystoreText.getText().trim().length() == 0) {
154                 error = PDEUIMessages.AdvancedPluginExportPage_noKeystore; //$NON-NLS-1$
155
} else if (fAliasText.getText().trim().length() == 0) {
156                 error = PDEUIMessages.AdvancedPluginExportPage_noAlias; //$NON-NLS-1$
157
} else if (fPasswordText.getText().trim().length() == 0) {
158                 error = PDEUIMessages.AdvancedPluginExportPage_noPassword; //$NON-NLS-1$
159
}
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 JavaDoc[] getSigningInfo() {
183         if (fButton.getSelection()) {
184             return new String JavaDoc[] { fAliasText.getText().trim(),
185                     fKeystoreText.getText().trim(),
186                     fPasswordText.getText().trim() };
187         }
188         return null;
189     }
190     
191     public String JavaDoc[] getJNLPInfo() {
192         return null;
193     }
194     
195 }
196
Popular Tags