2 * Copyright (c) 2002 Team in a Box Ltd. All rights reserved. This file is made available under the terms and conditions of the
3 * Common Public License v 1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/cpl-v1.0.html
5 * Contributors: Team in a Box Ltd http://www.teaminabox.co.uk/
8 package net.sourceforge.phpeclipse.wiki.export;
11 import java.lang.reflect.InvocationTargetException;
13 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
14 import net.sourceforge.phpeclipse.wiki.preferences.Util;
16 import org.eclipse.core.resources.IContainer;
17 import org.eclipse.core.resources.IProject;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.IStatus;
21 import org.eclipse.core.runtime.QualifiedName;
22 import org.eclipse.core.runtime.Status;
23 import org.eclipse.jface.dialogs.MessageDialog;
24 import org.eclipse.jface.operation.IRunnableWithProgress;
25 import org.eclipse.jface.viewers.ISelection;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27 import org.eclipse.jface.wizard.Wizard;
28 import org.eclipse.ui.INewWizard;
29 import org.eclipse.ui.IWorkbench;
31 public final class WikiExportWizard extends Wizard implements INewWizard {
32 static final QualifiedName DIRECTORY_QUALIFIED_NAME = new QualifiedName(WikiEditorPlugin.PLUGIN_ID, "exportDirectory");
34 private WikiExportWizardPage page;
36 private ISelection selection;
38 public WikiExportWizard() {
40 setNeedsProgressMonitor(true);
43 public void addPages() {
44 page = new WikiExportWizardPage(selection);
48 public boolean performFinish() {
49 persistExportProperties();
51 final IContainer folder = page.getFolder();
52 final String exportDirectory = page.getExportDirectoryPath();
54 return runOperationForContainer(new IRunnableWithProgress() {
55 public void run(IProgressMonitor monitor) throws InvocationTargetException {
57 startExport(monitor, folder, exportDirectory);
58 } catch (Exception e) {
59 throw new InvocationTargetException(e);
67 private boolean runOperationForContainer(IRunnableWithProgress op) {
69 getContainer().run(true, true, op);
70 } catch (InterruptedException e) {
72 } catch (InvocationTargetException e) {
73 WikiEditorPlugin.getDefault().log("", e);
74 MessageDialog.openError(getShell(), "Error", e.getTargetException().getMessage());
81 private void startExport(IProgressMonitor monitor, IContainer folder, String exportDirectory) throws CoreException {
83 final String srcBasePath = Util.getWikiTextsPath(folder);
84 new WikiExporter().export(folder, exportDirectory, srcBasePath, monitor);
85 } catch (Exception ioex) {
86 throw new CoreException(new Status(IStatus.ERROR, "Failed to write Wiki Documents", IStatus.OK, ioex.getMessage(), ioex));
90 private void persistExportProperties() {
91 IProject project = page.getFolder().getProject();
93 project.setPersistentProperty(WikiExportWizard.DIRECTORY_QUALIFIED_NAME, new File(page.getExportDirectoryPath())
95 } catch (CoreException cex) {
100 private void noteException(CoreException cex) {
101 WikiEditorPlugin.getDefault().log("Export Error", cex);
102 throw new RuntimeException("An error occurred. Please see the log for details.");
105 public void init(IWorkbench workbench, IStructuredSelection selection) {
106 this.selection = selection;