finalizing preferred refactoring
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / datasource / wizard / CdmDataSourceWizard.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.datasource.wizard;
12
13 import org.eclipse.jface.wizard.Wizard;
14 import org.eclipse.jface.wizard.WizardPage;
15
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;
20
21 /**
22 * @author n.hoffmann
23 * @created 18.05.2009
24 * @version 1.0
25 */
26 public class CdmDataSourceWizard extends Wizard {
27
28 private WizardPage dataSourcePage;
29
30 private ICdmDataSource dataSource;
31
32 private DatabaseTypeEnum databaseType;
33 private String dataSourceName;
34 private String server;
35 private int port;
36 private String database;
37 private String username;
38 private String password;
39
40 /**
41 * @param b
42 */
43 public CdmDataSourceWizard(ICdmDataSource dataSource) {
44 super();
45 setForcePreviousAndNextButtons(true);
46
47
48
49 if(dataSource != null){
50 this.dataSource = dataSource;
51
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());
59 }
60 }
61
62
63 /* (non-Javadoc)
64 * @see org.eclipse.jface.wizard.Wizard#addPages()
65 */
66 @Override
67 public void addPages() {
68
69 if(dataSource == null){
70 dataSourcePage = new CdmDataSourceWizardPage(dataSource);
71 }else{
72 if(dataSource.getDatabaseType() == DatabaseTypeEnum.H2){
73 dataSourcePage = new CdmDataSourceH2WizardPage(dataSource);
74 }else if(dataSource.getDatabaseType() == DatabaseTypeEnum.MySQL){
75 dataSourcePage = new CdmDataSourceMySQLWizardPage(dataSource);
76 }
77
78 }
79
80 this.addPage(dataSourcePage);
81 }
82
83 /* (non-Javadoc)
84 * @see org.eclipse.jface.wizard.Wizard#performFinish()
85 */
86 @Override
87 public boolean performFinish() {
88
89 CdmDataSource dataSource = null ;
90
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);
97 }
98
99 CdmDataSourceRepository.getDefault().save(dataSource);
100
101 return true;
102 }
103
104
105 /**
106 * @return the dataSource
107 */
108 public ICdmDataSource getDataSource() {
109 return dataSource;
110 }
111
112
113 /**
114 * @param dataSource the dataSource to set
115 */
116 public void setDataSource(ICdmDataSource dataSource) {
117 this.dataSource = dataSource;
118 }
119
120
121 /**
122 * @return the databaseType
123 */
124 public DatabaseTypeEnum getDatabaseType() {
125 return databaseType;
126 }
127
128
129 /**
130 * @param databaseType the databaseType to set
131 */
132 public void setDatabaseType(DatabaseTypeEnum databaseType) {
133 this.databaseType = databaseType;
134 }
135
136
137 /**
138 * @return the dataSourceName
139 */
140 public String getDataSourceName() {
141 return dataSourceName;
142 }
143
144
145 /**
146 * @param dataSourceName the dataSourceName to set
147 */
148 public void setDataSourceName(String dataSourceName) {
149 this.dataSourceName = dataSourceName;
150 }
151
152
153 /**
154 * @return the server
155 */
156 public String getServer() {
157 return server;
158 }
159
160
161 /**
162 * @param server the server to set
163 */
164 public void setServer(String server) {
165 this.server = server;
166 }
167
168
169 /**
170 * @return the port
171 */
172 public int getPort() {
173 return port;
174 }
175
176
177 /**
178 * @param port the port to set
179 */
180 public void setPort(int port) {
181 this.port = port;
182 }
183
184
185 /**
186 * @return the database
187 */
188 public String getDatabase() {
189 return database;
190 }
191
192
193 /**
194 * @param database the database to set
195 */
196 public void setDatabase(String database) {
197 this.database = database;
198 }
199
200
201 /**
202 * @return the username
203 */
204 public String getUsername() {
205 return username;
206 }
207
208
209 /**
210 * @param username the username to set
211 */
212 public void setUsername(String username) {
213 this.username = username;
214 }
215
216
217 /**
218 * @return the password
219 */
220 public String getPassword() {
221 return password;
222 }
223
224
225 /**
226 * @param password the password to set
227 */
228 public void setPassword(String password) {
229 this.password = password;
230 }
231
232 }