3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.datasource
.wizard
;
13 import org
.eclipse
.jface
.wizard
.Wizard
;
15 import eu
.etaxonomy
.cdm
.database
.DatabaseTypeEnum
;
16 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
17 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
20 * <p>CdmDataSourceWizard class.</p>
26 public class CdmDataSourceWizard
extends Wizard
{
28 private CdmDataSourceCredentialsWizardPage dataSourcePage
;
30 private CdmDataSourceTypeSelectionWizardPage dataSourceSelectionPage
;
32 private ICdmDataSource dataSource
;
34 private String dataSourceName
;
36 private boolean editMode
;
39 * <p>Constructor for CdmDataSourceWizard.</p>
41 public CdmDataSourceWizard() {
44 setForcePreviousAndNextButtons(true);
45 setWindowTitle("Datasource Dialog");
49 * <p>Constructor for CdmDataSourceWizard.</p>
51 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
53 public CdmDataSourceWizard(ICdmDataSource dataSource
) {
55 if(dataSource
!= null){
57 this.dataSource
= dataSource
;
58 dataSourceName
= dataSource
.getName();
60 setForcePreviousAndNextButtons(true);
61 setWindowTitle("Datasource Dialog");
66 * @see org.eclipse.jface.wizard.Wizard#addPages()
70 public void addPages() {
73 if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.H2
){
74 dataSourcePage
= new CdmDataSourceH2WizardPage(dataSource
);
75 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.MySQL
){
76 dataSourcePage
= new CdmDataSourceMySQLWizardPage(dataSource
);
77 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.SqlServer2005
){
78 dataSourcePage
= new CdmDataSourceSQLServerWizardPage(dataSource
);
80 throw new RuntimeException("Editing a datasource of type '" + dataSource
.getDatabaseType() + "' is not supported yet.");
83 this.addPage(dataSourcePage
);
85 dataSourceSelectionPage
= new CdmDataSourceTypeSelectionWizardPage(dataSource
);
86 this.addPage(dataSourceSelectionPage
);
91 * @see org.eclipse.jface.wizard.Wizard#performFinish()
95 public boolean performFinish() {
98 ICdmDataSource dataSource
= dataSourcePage
.getDataSource();
99 CdmDataSourceRepository
.update(dataSourceName
, dataSource
);
103 if(dataSourceSelectionPage
.getCredentialsWizardPage() != null){
104 CdmDataSourceCredentialsWizardPage credentialsWizardPage
= dataSourceSelectionPage
.getCredentialsWizardPage();
105 CdmDataSourceRepository
.save(dataSourceSelectionPage
.getDataSourceName(), credentialsWizardPage
.getDataSource());
108 throw new IllegalStateException("Expected a datasource credentials page to exist");
114 * @see org.eclipse.jface.wizard.Wizard#canFinish()
118 public boolean canFinish() {
120 return dataSourcePage
.isPageComplete();
122 boolean result
= true;
123 result
&= dataSourceSelectionPage
.isPageComplete();
124 if(dataSourceSelectionPage
.getCredentialsWizardPage() != null){
125 result
&= dataSourceSelectionPage
.getCredentialsWizardPage().isPageComplete();