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
;
14 import org
.eclipse
.jface
.wizard
.WizardPage
;
16 import eu
.etaxonomy
.cdm
.database
.CdmDataSource
;
17 import eu
.etaxonomy
.cdm
.database
.DatabaseTypeEnum
;
18 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
19 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
26 public class CdmDataSourceWizard
extends Wizard
{
28 private WizardPage dataSourcePage
;
30 private ICdmDataSource dataSource
;
32 private DatabaseTypeEnum databaseType
;
33 private String dataSourceName
;
34 private String server
;
36 private String database
;
37 private String username
;
38 private String password
;
43 public CdmDataSourceWizard(ICdmDataSource dataSource
) {
45 setForcePreviousAndNextButtons(true);
49 if(dataSource
!= null){
50 this.dataSource
= dataSource
;
52 setDatabaseType(dataSource
.getDatabaseType());
53 setDataSourceName(dataSource
.getName());
54 setServer(dataSource
.getServer());
55 setPort(dataSource
.getPort());
56 setDatabase(dataSource
.getDatabase());
57 setUsername(dataSource
.getUsername());
58 setPassword(dataSource
.getPassword());
64 * @see org.eclipse.jface.wizard.Wizard#addPages()
67 public void addPages() {
69 if(dataSource
== null){
70 dataSourcePage
= new CdmDataSourceWizardPage(dataSource
);
72 if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.H2
){
73 dataSourcePage
= new CdmDataSourceH2WizardPage(dataSource
);
74 }else if(dataSource
.getDatabaseType() == DatabaseTypeEnum
.MySQL
){
75 dataSourcePage
= new CdmDataSourceMySQLWizardPage(dataSource
);
80 this.addPage(dataSourcePage
);
84 * @see org.eclipse.jface.wizard.Wizard#performFinish()
87 public boolean performFinish() {
89 CdmDataSource dataSource
= null ;
91 if(databaseType
== DatabaseTypeEnum
.H2
){
92 dataSource
= CdmDataSource
.NewH2EmbeddedInstance(database
, username
, password
);
93 }else if(databaseType
== DatabaseTypeEnum
.MySQL
){
94 dataSource
= CdmDataSource
.NewMySqlInstance(server
, database
, port
, username
, password
);
97 CdmDataSourceRepository
.getDefault().save(dataSource
);
104 * @return the dataSource
106 public ICdmDataSource
getDataSource() {
112 * @param dataSource the dataSource to set
114 public void setDataSource(ICdmDataSource dataSource
) {
115 this.dataSource
= dataSource
;
120 * @return the databaseType
122 public DatabaseTypeEnum
getDatabaseType() {
128 * @param databaseType the databaseType to set
130 public void setDatabaseType(DatabaseTypeEnum databaseType
) {
131 this.databaseType
= databaseType
;
136 * @return the dataSourceName
138 public String
getDataSourceName() {
139 return dataSourceName
;
144 * @param dataSourceName the dataSourceName to set
146 public void setDataSourceName(String dataSourceName
) {
147 this.dataSourceName
= dataSourceName
;
154 public String
getServer() {
160 * @param server the server to set
162 public void setServer(String server
) {
163 this.server
= server
;
170 public int getPort() {
176 * @param port the port to set
178 public void setPort(int port
) {
184 * @return the database
186 public String
getDatabase() {
192 * @param database the database to set
194 public void setDatabase(String database
) {
195 this.database
= database
;
200 * @return the username
202 public String
getUsername() {
208 * @param username the username to set
210 public void setUsername(String username
) {
211 this.username
= username
;
216 * @return the password
218 public String
getPassword() {
224 * @param password the password to set
226 public void setPassword(String password
) {
227 this.password
= password
;