1 11 package org.eclipse.jdt.internal.ui.jarpackager; 12 13 import java.io.IOException ; 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 ; 31 32 36 public class OpenJarPackageWizardActionDelegate extends JarPackageActionDelegate { 37 38 private IJarDescriptionReader fReader; 39 40 43 public void run(IAction action) { 44 Shell parent= getShell(); 45 JarPackageData jarPackage= null; 46 String errorDetail= null; 47 try { 48 jarPackage= readJarPackage(getDescriptionFile(getSelection())); 49 } catch (IOException 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 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 75 private JarPackageData readJarPackage(IFile description) throws CoreException, IOException , SAXException { 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 |