]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/ui/org/eclipse/jdt/internal/ui/jarpackager/OpenJarExportWizardEditorLauncher.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / internal / ui / jarpackager / OpenJarExportWizardEditorLauncher.java
CommitLineData
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 *******************************************************************************/
11package org.eclipse.jdt.internal.ui.jarpackager;
12
13import java.io.File;
14import java.io.IOException;
15
16import org.eclipse.swt.widgets.Shell;
17
18import org.eclipse.core.runtime.CoreException;
19import org.eclipse.core.runtime.IPath;
20
21import org.eclipse.jface.dialogs.ErrorDialog;
22import org.eclipse.jface.dialogs.MessageDialog;
23import org.eclipse.jface.wizard.WizardDialog;
24
25import org.eclipse.ui.IEditorLauncher;
26import org.eclipse.ui.PlatformUI;
27
28import org.eclipse.jdt.internal.corext.util.Messages;
29
30import org.eclipse.jdt.ui.jarpackager.IJarDescriptionReader;
31import org.eclipse.jdt.ui.jarpackager.JarPackageData;
32
33import 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 */
41public 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}