KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > jarpackager > OpenJarPackageWizardActionDelegate


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.ui.jarpackager;
12
13 import java.io.IOException JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.core.runtime.CoreException;
17
18 import org.eclipse.core.resources.IFile;
19
20 import org.eclipse.swt.widgets.Shell;
21
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.dialogs.ErrorDialog;
24 import org.eclipse.jface.dialogs.MessageDialog;
25 import org.eclipse.jface.wizard.WizardDialog;
26
27 import org.eclipse.jdt.ui.jarpackager.IJarDescriptionReader;
28 import org.eclipse.jdt.ui.jarpackager.JarPackageData;
29
30 import org.xml.sax.SAXException JavaDoc;
31
32 /**
33  * This action delegate opens the JAR Package Wizard and initializes
34  * it with the selected JAR package description.
35  */

36 public class OpenJarPackageWizardActionDelegate extends JarPackageActionDelegate {
37
38     private IJarDescriptionReader fReader;
39
40     /*
41      * @see IActionDelegate
42      */

43     public void run(IAction action) {
44         Shell parent= getShell();
45         JarPackageData jarPackage= null;
46         String JavaDoc errorDetail= null;
47         try {
48             jarPackage= readJarPackage(getDescriptionFile(getSelection()));
49         } catch (IOException JavaDoc ex) {
50             errorDetail= ex.getLocalizedMessage();
51             MessageDialog.openError(parent, JarPackagerMessages.OpenJarPackageWizardDelegate_error_openJarPackager_title, JarPackagerMessages.OpenJarPackageWizardDelegate_error_openJarPackager_message + errorDetail);
52             return;
53         } catch (CoreException ex) {
54             errorDetail= ex.getLocalizedMessage();
55             MessageDialog.openError(parent, JarPackagerMessages.OpenJarPackageWizardDelegate_error_openJarPackager_title, JarPackagerMessages.OpenJarPackageWizardDelegate_error_openJarPackager_message + errorDetail);
56             return;
57         } catch (SAXException JavaDoc ex) {
58             errorDetail= JarPackagerMessages.OpenJarPackageWizardDelegate_badXmlFormat + ex.getLocalizedMessage();
59             MessageDialog.openError(parent, JarPackagerMessages.OpenJarPackageWizardDelegate_error_openJarPackager_title, JarPackagerMessages.OpenJarPackageWizardDelegate_error_openJarPackager_message + errorDetail);
60             return;
61         }
62
63         if (fReader != null && !fReader.getStatus().isOK())
64             ErrorDialog.openError(parent, JarPackagerMessages.OpenJarPackageWizardDelegate_jarDescriptionReaderWarnings_title, null, fReader.getStatus());
65         JarPackageWizard wizard= new JarPackageWizard();
66         wizard.init(getWorkbench(), jarPackage);
67         WizardDialog dialog= new WizardDialog(parent, wizard);
68         dialog.create();
69         dialog.open();
70     }
71     
72     /**
73      * Reads the JAR package spec from file.
74      */

75     private JarPackageData readJarPackage(IFile description) throws CoreException, IOException JavaDoc, SAXException JavaDoc {
76         Assert.isLegal(description.isAccessible());
77         Assert.isNotNull(description.getFileExtension());
78         Assert.isLegal(description.getFileExtension().equals(JarPackagerUtil.DESCRIPTION_EXTENSION));
79         JarPackageData jarPackage= new JarPackageData();
80         try {
81             fReader= jarPackage.createJarDescriptionReader(description.getContents());
82             fReader.read(jarPackage);
83         } finally {
84             if (fReader != null)
85                 fReader.close();
86         }
87         return jarPackage;
88     }
89 }
90
Popular Tags