2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.local
.datasource
.wizard
;
11 import org
.eclipse
.jface
.wizard
.Wizard
;
13 import eu
.etaxonomy
.cdm
.database
.DatabaseTypeEnum
;
14 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
15 import eu
.etaxonomy
.taxeditor
.local
.datasource
.common
.CdmDataSourceRepository
;
18 * <p>CdmDataSourceWizard class.</p>
23 public class CdmDataSourceWizard
extends Wizard
{
25 private CdmDataSourceCredentialsWizardPage dataSourcePage
;
27 private CdmDataSourceTypeSelectionWizardPage dataSourceSelectionPage
;
29 private ICdmDataSource dataSource
;
31 private String dataSourceName
;
33 //private boolean editMode;
41 // default mode is to create a new datasource
42 Mode mode
= Mode
.CREATE
;
45 * <p>Constructor for CdmDataSourceWizard.</p>
47 public CdmDataSourceWizard() {
49 this.mode
= Mode
.CREATE
;
50 setForcePreviousAndNextButtons(true);
51 setWindowTitle("Datasource Dialog");
55 * <p>Constructor for CdmDataSourceWizard.</p>
57 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
59 public CdmDataSourceWizard(ICdmDataSource dataSource
, Mode mode
) {
61 if(dataSource
!= null){
63 this.dataSource
= dataSource
;
64 dataSourceName
= dataSource
.getName();
66 //setForcePreviousAndNextButtons(true);
67 setWindowTitle("Datasource Dialog");
71 public void addPages() {
75 if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.H2
){
76 dataSourcePage
= new CdmDataSourceH2WizardPage(dataSource
, mode
);
77 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.MySQL
){
78 dataSourcePage
= new CdmDataSourceMySQLWizardPage(dataSource
, mode
);
79 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.SqlServer2005
){
80 dataSourcePage
= new CdmDataSourceSQLServerWizardPage(dataSource
,mode
);
81 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.PostgreSQL
){
82 dataSourcePage
= new CdmDataSourcePostgreSQLServerWizardPage(dataSource
, mode
);
84 throw new RuntimeException("Editing a datasource of type '" + dataSource
.getDatabaseType() + "' is not supported yet.");
87 this.addPage(dataSourcePage
);
89 dataSourceSelectionPage
= new CdmDataSourceTypeSelectionWizardPage(dataSource
);
90 this.addPage(dataSourceSelectionPage
);
97 public boolean performFinish() {
98 ICdmDataSource dataSource
;
101 dataSource
= dataSourcePage
.getUpdatedDataSource();
102 if(dataSourceName
.equals(dataSource
.getName())) {
103 CdmDataSourceRepository
.update(dataSourceName
, dataSource
);
105 CdmDataSourceRepository
.replace(dataSourceName
, dataSource
);
109 dataSource
= dataSourcePage
.getUpdatedDataSource();
110 CdmDataSourceRepository
.save(dataSourcePage
.getDataSourceName(), dataSource
);
113 if(dataSourceSelectionPage
.getCredentialsWizardPage() != null){
114 CdmDataSourceCredentialsWizardPage credentialsWizardPage
= dataSourceSelectionPage
.getCredentialsWizardPage();
115 CdmDataSourceRepository
.save(dataSourceSelectionPage
.getDataSourceName(), credentialsWizardPage
.getUpdatedDataSource());
118 throw new IllegalStateException("Expected a datasource credentials page to exist");
127 public boolean canFinish() {
131 return dataSourcePage
.isPageComplete();
133 boolean result
= true;
134 result
&= dataSourceSelectionPage
.isPageComplete();
135 if(dataSourceSelectionPage
.getCredentialsWizardPage() != null){
136 result
&= dataSourceSelectionPage
.getCredentialsWizardPage().isPageComplete();