891c0eaf69d5c9eebfa5dcc4b6a49e25373145d4
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.wiki / src / net / sourceforge / phpeclipse / wiki / export / pdf / WikiPDFExportWizard.java
1 /*
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
4  * 
5  * Contributors: Team in a Box Ltd http://www.teaminabox.co.uk/
6  */
7
8 package net.sourceforge.phpeclipse.wiki.export.pdf;
9
10 import java.io.File;
11 import java.lang.reflect.InvocationTargetException;
12
13 import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.QualifiedName;
18 import org.eclipse.jface.dialogs.MessageDialog;
19 import org.eclipse.jface.operation.IRunnableWithProgress;
20 import org.eclipse.jface.viewers.IStructuredSelection;
21 import org.eclipse.jface.wizard.Wizard;
22 import org.eclipse.ui.INewWizard;
23 import org.eclipse.ui.IWorkbench;
24
25 public final class WikiPDFExportWizard extends Wizard implements INewWizard {
26   static final QualifiedName DIRECTORY_QUALIFIED_NAME = new QualifiedName(WikiEditorPlugin.PLUGIN_ID, "exportDirectory");
27
28   private WikiPDFExportWizardPage page;
29
30   private IStructuredSelection selection;
31
32   public WikiPDFExportWizard() {
33     super();
34     setNeedsProgressMonitor(true);
35   }
36
37   public void addPages() {
38     page = new WikiPDFExportWizardPage(selection);
39     addPage(page);
40   }
41
42   public boolean performFinish() {
43     return page.finish();
44   }
45
46   private boolean runOperationForContainer(IRunnableWithProgress op) {
47     try {
48       getContainer().run(true, true, op);
49     } catch (InterruptedException e) {
50       return false;
51     } catch (InvocationTargetException e) {
52       WikiEditorPlugin.getDefault().log("", e);
53       MessageDialog.openError(getShell(), "Error", e.getTargetException().getMessage());
54       return false;
55     }
56
57     return true;
58   }
59
60   private void persistExportProperties() {
61     IProject project = page.getFolder().getProject();
62     try {
63       project.setPersistentProperty(WikiPDFExportWizard.DIRECTORY_QUALIFIED_NAME, new File(page.getExportDirectoryPath())
64           .getAbsolutePath());
65     } catch (CoreException cex) {
66       noteException(cex);
67     }
68   }
69
70   private void noteException(CoreException cex) {
71     WikiEditorPlugin.getDefault().log("Export Error", cex);
72     throw new RuntimeException("An error occurred. Please see the log for details.");
73   }
74
75   public void init(IWorkbench workbench, IStructuredSelection selection) {
76     this.selection = selection;
77   }
78 }