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.
10 package eu
.etaxonomy
.taxeditor
.local
.datasource
.wizard
;
12 import org
.eclipse
.jface
.wizard
.Wizard
;
14 import eu
.etaxonomy
.cdm
.database
.DatabaseTypeEnum
;
15 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
16 import eu
.etaxonomy
.taxeditor
.local
.datasource
.common
.CdmDataSourceRepository
;
19 * <p>CdmDataSourceWizard class.</p>
25 public class CdmDataSourceWizard
extends Wizard
{
27 private CdmDataSourceCredentialsWizardPage dataSourcePage
;
29 private CdmDataSourceTypeSelectionWizardPage dataSourceSelectionPage
;
31 private ICdmDataSource dataSource
;
33 private String dataSourceName
;
35 //private boolean editMode;
43 // default mode is to create a new datasource
44 Mode mode
= Mode
.CREATE
;
47 * <p>Constructor for CdmDataSourceWizard.</p>
49 public CdmDataSourceWizard() {
51 this.mode
= Mode
.CREATE
;
52 setForcePreviousAndNextButtons(true);
53 setWindowTitle("Datasource Dialog");
59 * <p>Constructor for CdmDataSourceWizard.</p>
61 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
63 public CdmDataSourceWizard(ICdmDataSource dataSource
, Mode mode
) {
65 if(dataSource
!= null){
67 this.dataSource
= dataSource
;
68 dataSourceName
= dataSource
.getName();
70 //setForcePreviousAndNextButtons(true);
71 setWindowTitle("Datasource Dialog");
76 * @see org.eclipse.jface.wizard.Wizard#addPages()
80 public void addPages() {
84 if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.H2
){
85 dataSourcePage
= new CdmDataSourceH2WizardPage(dataSource
, mode
);
86 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.MySQL
){
87 dataSourcePage
= new CdmDataSourceMySQLWizardPage(dataSource
, mode
);
88 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.SqlServer2005
){
89 dataSourcePage
= new CdmDataSourceSQLServerWizardPage(dataSource
,mode
);
90 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.PostgreSQL
){
91 dataSourcePage
= new CdmDataSourcePostgreSQLServerWizardPage(dataSource
, mode
);
93 throw new RuntimeException("Editing a datasource of type '" + dataSource
.getDatabaseType() + "' is not supported yet.");
96 this.addPage(dataSourcePage
);
98 dataSourceSelectionPage
= new CdmDataSourceTypeSelectionWizardPage(dataSource
);
99 this.addPage(dataSourceSelectionPage
);
107 * @see org.eclipse.jface.wizard.Wizard#performFinish()
111 public boolean performFinish() {
112 ICdmDataSource dataSource
;
115 dataSource
= dataSourcePage
.getUpdatedDataSource();
116 if(dataSourceName
.equals(dataSource
.getName())) {
117 CdmDataSourceRepository
.update(dataSourceName
, dataSource
);
119 CdmDataSourceRepository
.replace(dataSourceName
, dataSource
);
123 dataSource
= dataSourcePage
.getUpdatedDataSource();
124 CdmDataSourceRepository
.save(dataSourcePage
.getDataSourceName(), dataSource
);
127 if(dataSourceSelectionPage
.getCredentialsWizardPage() != null){
128 CdmDataSourceCredentialsWizardPage credentialsWizardPage
= dataSourceSelectionPage
.getCredentialsWizardPage();
129 CdmDataSourceRepository
.save(dataSourceSelectionPage
.getDataSourceName(), credentialsWizardPage
.getUpdatedDataSource());
132 throw new IllegalStateException("Expected a datasource credentials page to exist");
141 * @see org.eclipse.jface.wizard.Wizard#canFinish()
145 public boolean canFinish() {
149 return dataSourcePage
.isPageComplete();
151 boolean result
= true;
152 result
&= dataSourceSelectionPage
.isPageComplete();
153 if(dataSourceSelectionPage
.getCredentialsWizardPage() != null){
154 result
&= dataSourceSelectionPage
.getCredentialsWizardPage().isPageComplete();