KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
13 import org.eclipse.jface.resource.*;
14 import org.eclipse.swt.*;
15 import org.eclipse.swt.graphics.*;
16 import org.eclipse.swt.layout.*;
17 import org.eclipse.swt.widgets.*;
18 import org.eclipse.update.core.*;
19 import org.eclipse.update.internal.ui.*;
20
21 /**
22  *
23  */

24 public class JarVerificationDialog extends TitleAreaDialog {
25     public final static int INSTALL_ALL = CANCEL + OK + 1;
26     private IVerificationResult _VerificationResult = null;
27     private IDialogPage _DialogPage;
28     private Composite pageContainer;
29     private Image defaultImage = null;
30     private ImageDescriptor defaultImageDescriptor =
31         UpdateUIImages.DESC_UPDATE_WIZ;
32     
33     /**
34      * Constructor for JarVerificationDialog.
35      * @param parentShell
36      */

37     public JarVerificationDialog(Shell parentShell,IDialogPage dialogPage, IVerificationResult verificationResult) {
38         super(parentShell);
39         setShellStyle(SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL | SWT.RESIZE);
40         _VerificationResult = verificationResult;
41         _DialogPage = dialogPage;
42         if (dialogPage instanceof JarVerificationPage){
43             ((JarVerificationPage)_DialogPage).setTitleAreaDialog(this);
44         }
45     }
46
47     /**
48      * Add buttons to the dialog's button bar.
49      */

50     protected void createButtonsForButtonBar(Composite parent) {
51         if (_VerificationResult.getVerificationCode()
52             != IVerificationResult.TYPE_ENTRY_CORRUPTED) {
53
54             if (_VerificationResult.isFeatureVerification()) {
55                 createButton(
56                     parent,
57                     IDialogConstants.OK_ID,
58                     UpdateUIMessages.JarVerificationDialog_Install,
59                     false);
60             } else {
61                 createButton(
62                     parent,
63                     IDialogConstants.OK_ID,
64                     UpdateUIMessages.JarVerificationDialog_Continue,
65                     false);
66             }
67             // Radio button: Install all without prompting
68
//----------------------------------
69
createButton(
70                 parent,
71                 IDialogConstants.YES_TO_ALL_ID,
72                 UpdateUIMessages.JarVerificationDialog_InstallAll,
73                 false);
74             
75             // Radio button: Cancel installation
76
//----------------------------------
77
createButton(
78                 parent,
79                 IDialogConstants.CANCEL_ID,
80                 UpdateUIMessages.JarVerificationDialog_Cancel,
81                 true);
82         } else {
83             createButton(
84                 parent,
85                 IDialogConstants.CANCEL_ID,
86                 UpdateUIMessages.JarVerificationDialog_Cancel,
87                 true);
88         }
89         getButton(IDialogConstants.CANCEL_ID).setFocus();
90     }
91     
92     /* (non-Javadoc)
93      * Method declared on Dialog.
94      */

95     protected Control createDialogArea(Composite parent) {
96         Composite compositeParent = (Composite)super.createDialogArea(parent);
97         setTitleImage(this.getImage());
98         setTitle(UpdateUIMessages.JarVerificationDialog_Title);
99         
100         _DialogPage.createControl(compositeParent);
101         pageContainer=(Composite)_DialogPage.getControl();
102         GridData gd = new GridData(GridData.FILL_BOTH);
103         pageContainer.setLayoutData(gd);
104         pageContainer.setFont(parent.getFont());
105         
106         // Build the separator line
107
Label separator= new Label(compositeParent, SWT.HORIZONTAL | SWT.SEPARATOR);
108         separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
109         
110         return compositeParent;
111     }
112     
113         /**
114      * @see IDialogPage#getImage()
115      */

116     public Image getImage() {
117         if (defaultImage == null)
118             defaultImage = defaultImageDescriptor.createImage();
119
120         return defaultImage;
121     }
122
123     public boolean close() {
124         // dispose of image
125
if (defaultImage != null) {
126             defaultImage.dispose();
127             defaultImage = null;
128         }
129         return super.close();
130     }
131     /* (non-Javadoc)
132      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
133      */

134     protected void buttonPressed(int buttonId) {
135         if (IDialogConstants.YES_TO_ALL_ID == buttonId)
136             installAllPressed();
137         else
138             super.buttonPressed(buttonId);
139     }
140     
141     private void installAllPressed() {
142         setReturnCode(JarVerificationDialog.INSTALL_ALL);
143         close();
144     }
145 }
146
Popular Tags