]> gerrit.simantics Code Review - simantics/platform.git/blob
2ead523bd7bb983361030fd6311941984fc1b2cc
[simantics/platform.git] /
1 package org.simantics.document.linking.wizard;
2
3 import org.eclipse.jface.resource.JFaceResources;
4 import org.eclipse.jface.resource.LocalResourceManager;
5 import org.eclipse.jface.viewers.IStructuredSelection;
6 import org.eclipse.jface.wizard.IWizardPage;
7 import org.eclipse.jface.wizard.Wizard;
8 import org.eclipse.ui.IExportWizard;
9 import org.eclipse.ui.IWorkbench;
10 import org.simantics.db.Resource;
11 import org.simantics.utils.ui.AdaptionUtils;
12
13 /**
14  * Wizard for exporting reports.
15  * 
16  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
17  *
18  */
19 public class ReportWizard extends Wizard implements IExportWizard{
20         
21         Resource selectedResource;
22         ReportSelectionPage reportSelectionPage;
23         ReportCustomizationPage reportCustomizationPage;
24         ReportGeneratePage reportGeneratePage;
25         
26         LocalResourceManager manager = new LocalResourceManager(JFaceResources.getResources());
27         
28         public ReportWizard() {
29                 setNeedsProgressMonitor(true);
30         }
31         
32         @Override
33         public void addPages() {
34                 reportSelectionPage = new ReportSelectionPage("Select report parameters");
35                 reportCustomizationPage = new ReportCustomizationPage("Customize report");
36                 reportGeneratePage = new ReportGeneratePage("Run Report");
37                 addPage(reportSelectionPage);
38                 addPage(reportCustomizationPage);
39                 addPage(reportGeneratePage);
40                 if (selectedResource != null)
41                         reportSelectionPage.setInput(selectedResource);
42         }
43         
44         @Override
45         public IWizardPage getNextPage(IWizardPage page) {
46                 if (page == reportSelectionPage) {
47                         reportCustomizationPage.setReportWriter(reportSelectionPage.getSelectedWriter());
48                         reportCustomizationPage.setModel(reportSelectionPage.getSelectedModel());
49                         reportGeneratePage.setFilename(reportSelectionPage.getFilename());
50                         reportGeneratePage.setModel(reportSelectionPage.getSelectedModel());
51                         reportGeneratePage.setReportWriter(reportSelectionPage.getSelectedWriter());
52                 } 
53                 return super.getNextPage(page);
54         }
55
56         @Override
57         public boolean performFinish() {
58                 return reportGeneratePage.isGenerated();
59         }
60         
61         @Override
62         public boolean canFinish() {
63                 if (!reportGeneratePage.isGenerated())
64                         return false;
65                 return super.canFinish();
66         }
67
68         @Override
69         public void init(IWorkbench workbench, IStructuredSelection selection) {
70                 selectedResource = AdaptionUtils.adaptToSingle(selection, Resource.class);
71                 if (reportSelectionPage != null)
72                         reportSelectionPage.setInput(selectedResource);
73         }
74         
75         @Override
76         public void dispose() {
77                 manager.dispose();
78                 super.dispose();
79         }
80
81 }