]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2008 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.File; | |
14 | import java.io.IOException; | |
15 | ||
16 | import org.eclipse.swt.widgets.Shell; | |
17 | ||
18 | import org.eclipse.core.runtime.CoreException; | |
19 | import org.eclipse.core.runtime.IPath; | |
20 | ||
21 | import org.eclipse.jface.dialogs.ErrorDialog; | |
22 | import org.eclipse.jface.dialogs.MessageDialog; | |
23 | import org.eclipse.jface.wizard.WizardDialog; | |
24 | ||
25 | import org.eclipse.ui.IEditorLauncher; | |
26 | import org.eclipse.ui.PlatformUI; | |
27 | ||
28 | import org.eclipse.jdt.internal.corext.util.Messages; | |
29 | ||
30 | import org.eclipse.jdt.ui.jarpackager.IJarDescriptionReader; | |
31 | import org.eclipse.jdt.ui.jarpackager.JarPackageData; | |
32 | ||
33 | import org.eclipse.jdt.internal.ui.JavaPlugin; | |
34 | ||
35 | /** | |
36 | * This editor launcher opens the JAR Export Wizard and initializes it with the selected JAR package | |
37 | * description (a *.jardesc file). | |
38 | * | |
39 | * @since 3.5 | |
40 | */ | |
41 | public class OpenJarExportWizardEditorLauncher implements IEditorLauncher { | |
42 | ||
43 | /* | |
44 | * @see org.eclipse.ui.IEditorLauncher#open(org.eclipse.core.runtime.IPath) | |
45 | */ | |
46 | public void open(IPath filePath) { | |
47 | ||
48 | IJarDescriptionReader reader= null; | |
49 | JarPackageData jarPackage= null; | |
50 | try { | |
51 | File file= filePath.toFile(); | |
52 | if (!file.isFile() || !file.getName().endsWith('.' + JarPackagerUtil.DESCRIPTION_EXTENSION)) { | |
53 | openErrorDialog(Messages.format(JarPackagerMessages.OpenJarPackageWizardDelegate_onlyJardesc, JarPackagerUtil.DESCRIPTION_EXTENSION)); | |
54 | return; | |
55 | } | |
56 | ||
57 | jarPackage= new JarPackageData(); | |
58 | reader= jarPackage.generated_4692363288209020111(file); | |
59 | } catch (IOException ex) { | |
60 | openErrorDialog(ex.getLocalizedMessage()); | |
61 | return; | |
62 | } catch (CoreException ex) { | |
63 | openErrorDialog(ex.getLocalizedMessage()); | |
64 | return; | |
65 | } | |
66 | ||
67 | Shell parent= JavaPlugin.getActiveWorkbenchShell(); | |
68 | if (reader != null && !reader.getStatus().isOK()) | |
69 | ErrorDialog.openError(parent, JarPackagerMessages.OpenJarPackageWizardDelegate_jarDescriptionReaderWarnings_title, null, reader.getStatus()); | |
70 | JarPackageWizard wizard= new JarPackageWizard(); | |
71 | wizard.init(PlatformUI.getWorkbench(), jarPackage); | |
72 | WizardDialog dialog= new WizardDialog(parent, wizard); | |
73 | dialog.create(); | |
74 | dialog.open(); | |
75 | } | |
76 | ||
77 | private void openErrorDialog(String errorDetail) { | |
78 | MessageDialog.openError(JavaPlugin.getActiveWorkbenchShell(), JarPackagerMessages.OpenJarPackageWizardDelegate_error_openJarPackager_title, | |
79 | JarPackagerMessages.OpenJarPackageWizardDelegate_error_openJarPackager_message + errorDetail); | |
80 | } | |
81 | } |