KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > security > JarVerificationPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.update.internal.ui.security;
12 import org.eclipse.jface.dialogs.Dialog;
13 import org.eclipse.jface.dialogs.TitleAreaDialog;
14 import org.eclipse.jface.resource.FontRegistry;
15 import org.eclipse.jface.resource.JFaceResources;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.custom.CLabel;
18 import org.eclipse.swt.graphics.Font;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.layout.GridLayout;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Control;
23 import org.eclipse.swt.widgets.Group;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Text;
26 import org.eclipse.ui.*;
27 import org.eclipse.update.core.IVerificationResult;
28 import org.eclipse.update.internal.ui.UpdateUIMessages;
29 import org.eclipse.update.internal.ui.wizards.BannerPage;
30
31 /**
32  *
33  */

34 public class JarVerificationPage extends BannerPage {
35
36     private IVerificationResult _VerificationResult = null;
37     private String JavaDoc _fileName = null;
38     private String JavaDoc _strFeatureName = null;
39     private String JavaDoc _strId = null;
40     private String JavaDoc _strProviderName = null;
41     private TitleAreaDialog _Dialog;
42
43     /*
44      * Constructor for JarVerificationPage.
45      */

46     public JarVerificationPage(IVerificationResult verificationResult) {
47         super(UpdateUIMessages.JarVerificationDialog_Verification);
48         _fileName = verificationResult.getContentReference().getIdentifier();
49         _VerificationResult = verificationResult;
50         _strId = verificationResult.getFeature().getVersionedIdentifier().toString();
51         _strFeatureName = verificationResult.getFeature().getLabel();
52         _strProviderName = verificationResult.getFeature().getProvider();
53     }
54
55     /* (non-Javadoc)
56      * Method declared on Dialog.
57      */

58     protected Control createContents(Composite compositeParent) {
59         PlatformUI.getWorkbench().getHelpSystem().setHelp(compositeParent, "org.eclipse.update.ui.JarVerificationPage"); //$NON-NLS-1$
60
// Composite: Client
61
//------------------
62
Composite compositeClient = new Composite(compositeParent, SWT.NULL);
63         GridLayout layout = new GridLayout();
64         layout.marginHeight = layout.marginWidth = 0;
65         compositeClient.setLayout(layout);
66         compositeClient.setLayoutData(new GridData(GridData.FILL_BOTH));
67
68         // Text Information
69
//------------------
70
createTextArea(compositeClient);
71
72         // Certificate Area
73
//------------------
74
createCertificateArea(compositeClient);
75
76         // File and Feature Information
77
//-----------------------------
78
createInformationArea(compositeClient);
79
80         // Choice Area
81
//------------
82
//createChoiceArea(compositeClient);
83

84         Dialog.applyDialogFont(compositeParent);
85         return compositeClient;
86
87     }
88
89     /*
90      * Creates the Information text
91      */

92     private void createTextArea(Composite compositeClient) {
93
94         // Label: Information
95
//------------------
96
Label labelInformation =
97             new Label(compositeClient, SWT.WRAP);
98         labelInformation.setLayoutData(
99             new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_HORIZONTAL));
100
101         String JavaDoc actionMsg = null;
102         if (_VerificationResult.isFeatureVerification()) {
103             actionMsg = UpdateUIMessages.JarVerificationDialog_MayChooseToInstall;
104         } else {
105             actionMsg = UpdateUIMessages.JarVerificationDialog_MayChooseToContinue;
106         }
107         
108         StringBuffer JavaDoc strb = new StringBuffer JavaDoc();
109         switch (_VerificationResult.getVerificationCode()) {
110
111             case IVerificationResult.TYPE_ENTRY_NOT_SIGNED :
112                 String JavaDoc msg = (_VerificationResult.isFeatureVerification()?
113                     UpdateUIMessages.JarVerificationDialog_AboutToInstall_Feature:
114                         UpdateUIMessages.JarVerificationDialog_AboutToInstall_File)+
115                         "\r\n" + actionMsg; //$NON-NLS-1$
116
setMessage(msg, WARNING);
117                 strb.append(_VerificationResult.isFeatureVerification()?
118                             UpdateUIMessages.JarVerificationDialog_NotDigitallySigned_Feature:
119                                 UpdateUIMessages.JarVerificationDialog_NotDigitallySigned_File);
120                 strb.append("\r\n"); //$NON-NLS-1$
121
strb.append(_VerificationResult.isFeatureVerification()?
122                         UpdateUIMessages.JarVerificationDialog_CannotVerifyProvider_Feature:
123                             UpdateUIMessages.JarVerificationDialog_CannotVerifyProvider_File);
124                 
125 /* strb.append("\r\n"); //$NON-NLS-1$
126                 if (_VerificationResult.isFeatureVerification()) {
127                     strb.append(
128                         UpdateUI.getResourceString("JarVerificationDialog.InstallMayCorrupt"));//$NON-NLS-1$
129                 } else {
130                     strb.append(
131                         UpdateUI.getResourceString("JarVerificationDialog.ContinueMayCorrupt"));//$NON-NLS-1$
132                 }
133                 */

134                 labelInformation.setText(strb.toString());
135                 break;
136
137             case IVerificationResult.TYPE_ENTRY_CORRUPTED :
138                 msg = _VerificationResult.isFeatureVerification()?
139                             UpdateUIMessages.JarVerificationDialog_CorruptedContent_Feature:
140                                 UpdateUIMessages.JarVerificationDialog_CorruptedContent_File;
141                 setMessage(msg, ERROR);
142                 strb.append(
143                     UpdateUIMessages.JarVerificationDialog_ComponentNotInstalled);
144                 labelInformation.setText(strb.toString());
145                 break;
146
147             case IVerificationResult.TYPE_ENTRY_SIGNED_UNRECOGNIZED :
148                 msg = (_VerificationResult.isFeatureVerification()?
149                         UpdateUIMessages.JarVerificationDialog_SignedComponent_Feature:
150                             UpdateUIMessages.JarVerificationDialog_SignedComponent_Feature) +
151                         "\r\n" + actionMsg; //$NON-NLS-1$
152

153                 setMessage(msg, WARNING);
154                 strb.append(_VerificationResult.isFeatureVerification()?
155                     UpdateUIMessages.JarVerificationDialog_UnknownCertificate_Feature:
156                         UpdateUIMessages.JarVerificationDialog_UnknownCertificate_File);
157                 strb.append("\r\n"); //$NON-NLS-1$
158
strb.append(_VerificationResult.isFeatureVerification()?
159                         UpdateUIMessages.JarVerificationDialog_UnableToVerifyProvider_Feature:
160                             UpdateUIMessages.JarVerificationDialog_UnableToVerifyProvider_File);
161 /* strb.append("\r\n"); //$NON-NLS-1$
162                 if (_VerificationResult.isFeatureVerification()) {
163                     strb.append(
164                         UpdateUI.getResourceString("JarVerificationDialog.InstallMayCorrupt")); //$NON-NLS-1$
165                 } else {
166                     strb.append(
167                         UpdateUI.getResourceString("JarVerificationDialog.ContinueMayCorrupt"));//$NON-NLS-1$
168                 }
169                 */

170                 labelInformation.setText(strb.toString());
171                 break;
172
173             case IVerificationResult.TYPE_ENTRY_SIGNED_RECOGNIZED :
174                 msg = (_VerificationResult.isFeatureVerification()?
175                         UpdateUIMessages.JarVerificationDialog_SignedComponent_Feature:
176                             UpdateUIMessages.JarVerificationDialog_SignedComponent_File) +
177                         "\r\n" + actionMsg; //$NON-NLS-1$
178
setMessage(msg, WARNING);
179                 strb.append(_VerificationResult.isFeatureVerification()?
180                     UpdateUIMessages.JarVerificationDialog_KnownCertificate_Feature:
181                         UpdateUIMessages.JarVerificationDialog_KnownCertificate_File);
182                 strb.append("\r\n"); //$NON-NLS-1$
183
strb.append(_VerificationResult.isFeatureVerification()?
184                     UpdateUIMessages.JarVerificationDialog_ProviderKnown_Feature:
185                         UpdateUIMessages.JarVerificationDialog_ProviderKnown_File);
186                 strb.append("\r\n"); //$NON-NLS-1$
187

188                 labelInformation.setText(strb.toString());
189
190 // createCautionArea(compositeClient);
191
break;
192         }
193     }
194     
195
196     /*
197      * Presents File & Feature information
198      */

199     private void createInformationArea(Composite compositeClient) {
200
201         // Composite: Information labels
202
//------------------------------
203
Composite compositeInformation = new Composite(compositeClient, SWT.NULL);
204         GridLayout layout = new GridLayout();
205         layout.numColumns = 2;
206         layout.marginWidth = layout.marginHeight = 0;
207         compositeInformation.setLayout(layout);
208         compositeInformation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
209
210         // get bold face
211
FontRegistry fregistry = JFaceResources.getFontRegistry();
212         Font boldFont = fregistry.getBold(JFaceResources.DIALOG_FONT);
213         
214         // Feature name
215
//---------------
216
Label keyLabel = null;
217         CLabel valueLabel = null;
218         if (_strFeatureName != null && _strFeatureName.length() > 0) {
219             keyLabel = new Label(compositeInformation, SWT.NULL);
220             keyLabel.setText(
221                 UpdateUIMessages.JarVerificationDialog_FeatureName);
222
223             valueLabel = new CLabel(compositeInformation, SWT.NULL);
224             valueLabel.setFont(boldFont);
225             valueLabel.setText(_strFeatureName);
226             valueLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
227         }
228         // Feature identifier
229
//---------------------
230
if (_strId != null && _strId.length() > 0) {
231             keyLabel = new Label(compositeInformation, SWT.NULL);
232             keyLabel.setText(
233                 UpdateUIMessages.JarVerificationDialog_FeatureIdentifier);
234
235             valueLabel = new CLabel(compositeInformation, SWT.NULL);
236             valueLabel.setFont(boldFont);
237             valueLabel.setText(_strId);
238             valueLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
239         }
240         // Provider name
241
//--------------
242
if (_strProviderName != null && _strProviderName.length() > 0) {
243             keyLabel = new Label(compositeInformation, SWT.NULL);
244             keyLabel.setText(
245                 UpdateUIMessages.JarVerificationDialog_Provider);
246
247             valueLabel = new CLabel(compositeInformation, SWT.NULL);
248             valueLabel.setFont(boldFont);
249             valueLabel.setText(_strProviderName);
250             valueLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
251         }
252         // Label: File name
253
//-----------------
254
keyLabel = new Label(compositeInformation, SWT.NULL);
255         keyLabel.setText(
256             UpdateUIMessages.JarVerificationDialog_FileName);
257
258         valueLabel = new CLabel(compositeInformation, SWT.NULL);
259         valueLabel.setFont(boldFont);
260         valueLabel.setText(_fileName);
261         valueLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
262     }
263
264     /*
265      * Show certificate information
266      */

267     private void createCertificateArea(Composite compositeClient) {
268
269         if (_VerificationResult.getVerificationCode()
270             == IVerificationResult.TYPE_ENTRY_SIGNED_UNRECOGNIZED
271             || _VerificationResult.getVerificationCode()
272                 == IVerificationResult.TYPE_ENTRY_SIGNED_RECOGNIZED) {
273             // Group box
274
//----------
275
Group group = new Group(compositeClient, SWT.SHADOW_ETCHED_IN);
276             GridLayout layout = new GridLayout();
277             layout.numColumns = 2;
278             layout.marginWidth = layout.marginHeight = 0;
279             group.setLayout(layout);
280             group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
281             group.setText(UpdateUIMessages.JarVerificationDialog_CertificateInfo);
282
283             // Signer
284
//-------------------
285
Label keyLabel = null;
286             Text valueText = null;
287             //data = new GridData(GridData.FILL_HORIZONTAL);
288
//data.horizontalIndent = 0;
289
//textInformation.setLayoutData(data);
290
if (_VerificationResult.getSignerInfo() != null) {
291                 keyLabel = new Label(group, SWT.NULL);
292                 keyLabel.setText(UpdateUIMessages.JarVerificationDialog_SubjectCA);
293                 keyLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
294
295                 valueText = new Text(group, SWT.MULTI|SWT.BORDER|SWT.WRAP|SWT.V_SCROLL);
296                 valueText.setText(_VerificationResult.getSignerInfo());
297                 valueText.setEditable(false);
298                 valueText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
299             }
300             
301             // Authenticator
302
//---------------------
303
if (_VerificationResult.getVerifierInfo() != null) {
304                 keyLabel = new Label(group, SWT.NULL);
305                 keyLabel.setText(UpdateUIMessages.JarVerificationDialog_RootCA);
306                 keyLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
307
308                 valueText = new Text(group, SWT.MULTI|SWT.BORDER|SWT.WRAP|SWT.V_SCROLL);
309                 valueText.setText(_VerificationResult.getVerifierInfo());
310                 valueText.setEditable(false);
311                 valueText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
312             }
313         }
314     }
315
316     /*
317      * Sets the Dialog
318      */

319     public void setTitleAreaDialog(TitleAreaDialog dialog) {
320         _Dialog = dialog;
321     }
322
323     /*
324      *
325      */

326     public void setMessage(String JavaDoc newMessage, int newType) {
327         super.setMessage(newMessage, newType);
328         if (_Dialog != null) {
329             _Dialog.setMessage(newMessage, newType);
330         }
331     }
332
333 }
334
Popular Tags