1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.sensorframework.dialogs.dataset; |
5 | |
6 | import org.eclipse.core.resources.IResource; |
7 | import org.eclipse.core.runtime.IPath; |
8 | import org.eclipse.core.runtime.IStatus; |
9 | import org.eclipse.jface.dialogs.MessageDialog; |
10 | import org.eclipse.jface.wizard.IWizardPage; |
11 | import org.eclipse.jface.wizard.Wizard; |
12 | |
13 | import de.uka.ipd.sdq.sensorframework.SensorFrameworkDataset; |
14 | import de.uka.ipd.sdq.sensorframework.dao.file.FileDAOFactory; |
15 | import de.uka.ipd.sdq.sensorframework.dialogs.SensorFrameworkDialogPlugin; |
16 | import de.uka.ipd.sdq.sensorframework.entities.dao.IDAOFactory; |
17 | |
18 | /** |
19 | * The OpenDatasourceWizard allows the user to choose which data source file to |
20 | * run. |
21 | * |
22 | * @author Roman Andrej |
23 | */ |
24 | public class OpenDatasourceWizard extends Wizard { |
25 | |
26 | |
27 | private WizardDatasourceLoadPage db40DatasourceLoadPage, fileDatasourceLoadPage; |
28 | private WizardSelectDatasourcePage selectDatasourceTypePage; |
29 | |
30 | public OpenDatasourceWizard() { |
31 | super(); |
32 | this.setWindowTitle("Load datastore..."); |
33 | } |
34 | |
35 | /* (non-Javadoc) |
36 | * @see org.eclipse.jface.wizard.Wizard#addPages() |
37 | */ |
38 | @Override |
39 | public void addPages() { |
40 | super.addPages(); |
41 | |
42 | selectDatasourceTypePage = new WizardSelectDatasourcePage( |
43 | "Select Type of Datasource to load", false, true, true); |
44 | this.addPage(selectDatasourceTypePage); |
45 | |
46 | db40DatasourceLoadPage = new WizardDatasourceLoadPage("Open the database file", |
47 | IResource.FILE); |
48 | this.addPage(db40DatasourceLoadPage); |
49 | |
50 | fileDatasourceLoadPage = new WizardDatasourceLoadPage( |
51 | "Open the database folder", IResource.FOLDER); |
52 | this.addPage(fileDatasourceLoadPage); |
53 | } |
54 | |
55 | |
56 | /* (non-Javadoc) |
57 | * @see org.eclipse.jface.wizard.Wizard#performFinish() |
58 | */ |
59 | @Override |
60 | public boolean performFinish() { |
61 | IDAOFactory factory = null; |
62 | IPath path = null; |
63 | |
64 | if (selectDatasourceTypePage.getResult().equals( |
65 | WizardSelectDatasourcePage.FILE_DATASRC)) { |
66 | path = fileDatasourceLoadPage.getFileFullPath(); |
67 | |
68 | try { |
69 | factory = new FileDAOFactory(path.toOSString()); |
70 | SensorFrameworkDataset.singleton().addDataSource(factory); |
71 | } catch (Throwable e) { |
72 | MessageDialog.openError(getShell(), "File DAO factory error.", |
73 | e.getMessage()); |
74 | SensorFrameworkDialogPlugin.log(IStatus.ERROR, e.getMessage()); |
75 | return false; |
76 | } |
77 | |
78 | } else { |
79 | return false; |
80 | } |
81 | |
82 | return true; |
83 | } |
84 | |
85 | |
86 | /* (non-Javadoc) |
87 | * @see org.eclipse.jface.wizard.Wizard#canFinish() |
88 | */ |
89 | @Override |
90 | public boolean canFinish() { |
91 | if (selectDatasourceTypePage.getResult().equals( |
92 | WizardSelectDatasourcePage.FILE_DATASRC)) { |
93 | return fileDatasourceLoadPage.isPageComplete(); |
94 | } |
95 | return false; |
96 | } |
97 | |
98 | |
99 | /* (non-Javadoc) |
100 | * @see org.eclipse.jface.wizard.Wizard#getNextPage(org.eclipse.jface.wizard.IWizardPage) |
101 | */ |
102 | @Override |
103 | public IWizardPage getNextPage(IWizardPage page) { |
104 | |
105 | if (page instanceof WizardSelectDatasourcePage) { |
106 | WizardSelectDatasourcePage data_type_page = (WizardSelectDatasourcePage) page; |
107 | if (data_type_page.getResult().equals( |
108 | WizardSelectDatasourcePage.FILE_DATASRC)) { |
109 | return fileDatasourceLoadPage; |
110 | } |
111 | } |
112 | return null; |
113 | } |
114 | } |