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;
44 // default mode is to create a new datasource
45 Mode mode
= Mode
.CREATE
;
48 * <p>Constructor for CdmDataSourceWizard.</p>
50 public CdmDataSourceWizard() {
52 this.mode
= Mode
.CREATE
;
53 setForcePreviousAndNextButtons(true);
54 setWindowTitle("Datasource Dialog");
60 * <p>Constructor for CdmDataSourceWizard.</p>
62 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
64 public CdmDataSourceWizard(ICdmDataSource dataSource
, Mode mode
) {
66 if(dataSource
!= null){
68 this.dataSource
= dataSource
;
69 dataSourceName
= dataSource
.getName();
71 //setForcePreviousAndNextButtons(true);
72 setWindowTitle("Datasource Dialog");
77 * @see org.eclipse.jface.wizard.Wizard#addPages()
81 public void addPages() {
85 if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.H2
){
86 dataSourcePage
= new CdmDataSourceH2WizardPage(dataSource
);
87 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.MySQL
){
88 dataSourcePage
= new CdmDataSourceMySQLWizardPage(dataSource
, mode
);
89 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.SqlServer2005
){
90 dataSourcePage
= new CdmDataSourceSQLServerWizardPage(dataSource
);
91 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.PostgreSQL
){
92 dataSourcePage
= new CdmDataSourcePostgreSQLServerWizardPage(dataSource
);
94 throw new RuntimeException("Editing a datasource of type '" + dataSource
.getDatabaseType() + "' is not supported yet.");
97 this.addPage(dataSourcePage
);
99 dataSourceSelectionPage
= new CdmDataSourceTypeSelectionWizardPage(dataSource
);
100 this.addPage(dataSourceSelectionPage
);
108 * @see org.eclipse.jface.wizard.Wizard#performFinish()
112 public boolean performFinish() {
113 ICdmDataSource dataSource
;
116 dataSource
= dataSourcePage
.getUpdatedDataSource();
117 if(dataSourceName
.equals(dataSource
.getName())) {
118 CdmDataSourceRepository
.update(dataSourceName
, dataSource
);
120 CdmDataSourceRepository
.replace(dataSourceName
, dataSource
);
124 dataSource
= dataSourcePage
.getUpdatedDataSource();
125 CdmDataSourceRepository
.save(dataSourcePage
.getDataSourceName(), dataSource
);
128 if(dataSourceSelectionPage
.getCredentialsWizardPage() != null){
129 CdmDataSourceCredentialsWizardPage credentialsWizardPage
= dataSourceSelectionPage
.getCredentialsWizardPage();
130 CdmDataSourceRepository
.save(dataSourceSelectionPage
.getDataSourceName(), credentialsWizardPage
.getUpdatedDataSource());
133 throw new IllegalStateException("Expected a datasource credentials page to exist");
142 * @see org.eclipse.jface.wizard.Wizard#canFinish()
146 public boolean canFinish() {
150 return dataSourcePage
.isPageComplete();
152 boolean result
= true;
153 result
&= dataSourceSelectionPage
.isPageComplete();
154 if(dataSourceSelectionPage
.getCredentialsWizardPage() != null){
155 result
&= dataSourceSelectionPage
.getCredentialsWizardPage().isPageComplete();