(no commit message)
[taxeditor.git] / taxeditor-printpublisher / src / main / java / eu / etaxonomy / printpublisher / wizard / AbstractPublishWizard.java
1 /**
2 *
3 */
4 package eu.etaxonomy.printpublisher.wizard;
5
6 import java.lang.reflect.InvocationTargetException;
7
8 import org.apache.log4j.Logger;
9 import org.eclipse.core.runtime.IProgressMonitor;
10 import org.eclipse.jface.operation.IRunnableWithProgress;
11 import org.eclipse.jface.viewers.IStructuredSelection;
12 import org.eclipse.jface.wizard.Wizard;
13 import org.eclipse.ui.IExportWizard;
14 import org.eclipse.ui.IWorkbench;
15
16 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
17 import eu.etaxonomy.printpublisher.IHarvestObserver;
18 import eu.etaxonomy.printpublisher.PublishConfigurator;
19 import eu.etaxonomy.printpublisher.Publisher;
20 import eu.etaxonomy.printpublisher.out.IPublishOutputModule;
21 import eu.etaxonomy.taxeditor.store.CdmStore;
22
23 /**
24 *
25 * @author n.hoffmann
26 * @created Apr 1, 2010
27 * @version 1.0
28 */
29 public class AbstractPublishWizard extends Wizard implements IExportWizard{
30 private static final Logger logger = Logger
31 .getLogger(AbstractPublishWizard.class);
32
33 public static final String PAGE_SERVICE = "PAGE_SERVICE";
34 public static final String PAGE_TAXA = "PAGE_TAXA";
35 public static final String PAGE_OPTIONS = "PAGE_OPTIONS";
36 public static final String PAGE_FOLDER = "PAGE_FOLDER";
37 public static final String PAGE_OVERVIEW = "PAGE_OVERVIEW";
38 public static final String PAGE_FEATURETREE = "PAGE_FEATURETREE";
39
40 protected SelectServiceWizardPage pageService;
41 protected SelectTaxaWizardPage pageTaxa;
42 protected OptionsWizardPage pageOptions;
43 protected SelectFeatureTreeWizardPage pageFeatureTree;
44 protected SelectFolderWizardPage pageFolder;
45 protected OverviewWizardPage pageOverview;
46
47 private PublishConfigurator configurator;
48
49 private IPublishOutputModule outputModule;
50
51 public AbstractPublishWizard(){
52 setNeedsProgressMonitor(true);
53 }
54
55 /* (non-Javadoc)
56 * @see org.eclipse.jface.wizard.Wizard#performFinish()
57 */
58 @Override
59 public boolean performFinish() {
60
61 IRunnableWithProgress runnable = new IRunnableWithProgress() {
62
63 public void run(final IProgressMonitor monitor)
64 throws InvocationTargetException, InterruptedException {
65 monitor.beginTask("Exporting Printable Output", getConfigurator().calculateNumberOfNodes() + 1);
66 try{
67 IHarvestObserver observer = new IHarvestObserver() {
68
69 public void update(String taskName) {
70 monitor.setTaskName(taskName);
71 monitor.worked(1);
72
73 }
74 };
75 getConfigurator().addObserver(observer);
76
77 Publisher.publish(configurator);
78 }finally{
79 monitor.done();
80 }
81
82 }
83 };
84
85 ConversationHolder conversation = null;
86
87 try {
88 if(getConfigurator().isLocal()){
89 conversation= CdmStore.createConversation();
90 }
91 getContainer().run(false, true, runnable);
92
93 } catch (InvocationTargetException e) {
94 // TODO Auto-generated catch block
95 e.printStackTrace();
96 } catch (InterruptedException e) {
97 // TODO Auto-generated catch block
98 e.printStackTrace();
99 }finally{
100 if(conversation != null) conversation.close();
101 }
102
103 return true;
104 }
105
106 @Override
107 public void addPages() {
108 super.addPages();
109
110 pageService = new SelectServiceWizardPage(PAGE_SERVICE);
111 addPage(pageService);
112
113 pageTaxa = new SelectTaxaWizardPage(PAGE_TAXA);
114 addPage(pageTaxa);
115
116 pageOptions = new OptionsWizardPage(PAGE_OPTIONS);
117 addPage(pageOptions);
118
119 pageFeatureTree = new SelectFeatureTreeWizardPage(PAGE_FEATURETREE);
120 addPage(pageFeatureTree);
121
122 pageFolder = new SelectFolderWizardPage(PAGE_FOLDER);
123 addPage(pageFolder);
124
125 pageOverview = new OverviewWizardPage(PAGE_OVERVIEW);
126 addPage(pageOverview);
127 }
128
129 /* (non-Javadoc)
130 * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
131 */
132 public void init(IWorkbench workbench, IStructuredSelection selection) {
133 logger.warn("Instantiating wizard: " + this.getClass().getSimpleName());
134 }
135
136
137
138 @Override
139 public boolean canFinish() {
140 return pageService.isPageComplete() &&
141 pageTaxa.isPageComplete() &&
142 pageFeatureTree.isPageComplete() &&
143 pageFolder.isPageComplete();
144 }
145
146 protected PublishConfigurator getConfigurator() {
147 return configurator;
148 }
149
150 protected void setConfigurator(PublishConfigurator configurator){
151 this.configurator = configurator;
152 }
153
154 protected void setOutputModule(IPublishOutputModule outputModule){
155 this.outputModule = outputModule;
156 }
157
158 public IPublishOutputModule getOutputModule(){
159 return outputModule;
160 }
161 }