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
);
95 }else if(databaseType
== DatabaseTypeEnum
.SqlServer2005
){
96 dataSource
= CdmDataSource
.NewSqlServer2005Instance(server
, database
, port
, username
, password
);
99 CdmDataSourceRepository
.getDefault().save(dataSource
);
106 * @return the dataSource
108 public ICdmDataSource
getDataSource() {
114 * @param dataSource the dataSource to set
116 public void setDataSource(ICdmDataSource dataSource
) {
117 this.dataSource
= dataSource
;
122 * @return the databaseType
124 public DatabaseTypeEnum
getDatabaseType() {
130 * @param databaseType the databaseType to set
132 public void setDatabaseType(DatabaseTypeEnum databaseType
) {
133 this.databaseType
= databaseType
;
138 * @return the dataSourceName
140 public String
getDataSourceName() {
141 return dataSourceName
;
146 * @param dataSourceName the dataSourceName to set
148 public void setDataSourceName(String dataSourceName
) {
149 this.dataSourceName
= dataSourceName
;
156 public String
getServer() {
162 * @param server the server to set
164 public void setServer(String server
) {
165 this.server
= server
;
172 public int getPort() {
178 * @param port the port to set
180 public void setPort(int port
) {
186 * @return the database
188 public String
getDatabase() {
194 * @param database the database to set
196 public void setDatabase(String database
) {
197 this.database
= database
;
202 * @return the username
204 public String
getUsername() {
210 * @param username the username to set
212 public void setUsername(String username
) {
213 this.username
= username
;
218 * @return the password
220 public String
getPassword() {
226 * @param password the password to set
228 public void setPassword(String password
) {
229 this.password
= password
;