Project

General

Profile

Download (4.3 KB) Statistics
| Branch: | Tag: | Revision:
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.store.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.store.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
		}
96
					
97
		CdmDataSourceRepository.getDefault().save(dataSource);
98
		
99
		return true;
100
	}
101

    
102

    
103
	/**
104
	 * @return the dataSource
105
	 */
106
	public ICdmDataSource getDataSource() {
107
		return dataSource;
108
	}
109

    
110

    
111
	/**
112
	 * @param dataSource the dataSource to set
113
	 */
114
	public void setDataSource(ICdmDataSource dataSource) {
115
		this.dataSource = dataSource;
116
	}
117

    
118

    
119
	/**
120
	 * @return the databaseType
121
	 */
122
	public DatabaseTypeEnum getDatabaseType() {
123
		return databaseType;
124
	}
125

    
126

    
127
	/**
128
	 * @param databaseType the databaseType to set
129
	 */
130
	public void setDatabaseType(DatabaseTypeEnum databaseType) {
131
		this.databaseType = databaseType;
132
	}
133

    
134

    
135
	/**
136
	 * @return the dataSourceName
137
	 */
138
	public String getDataSourceName() {
139
		return dataSourceName;
140
	}
141

    
142

    
143
	/**
144
	 * @param dataSourceName the dataSourceName to set
145
	 */
146
	public void setDataSourceName(String dataSourceName) {
147
		this.dataSourceName = dataSourceName;
148
	}
149

    
150

    
151
	/**
152
	 * @return the server
153
	 */
154
	public String getServer() {
155
		return server;
156
	}
157

    
158

    
159
	/**
160
	 * @param server the server to set
161
	 */
162
	public void setServer(String server) {
163
		this.server = server;
164
	}
165

    
166

    
167
	/**
168
	 * @return the port
169
	 */
170
	public int getPort() {
171
		return port;
172
	}
173

    
174

    
175
	/**
176
	 * @param port the port to set
177
	 */
178
	public void setPort(int port) {
179
		this.port = port;
180
	}
181

    
182

    
183
	/**
184
	 * @return the database
185
	 */
186
	public String getDatabase() {
187
		return database;
188
	}
189

    
190

    
191
	/**
192
	 * @param database the database to set
193
	 */
194
	public void setDatabase(String database) {
195
		this.database = database;
196
	}
197

    
198

    
199
	/**
200
	 * @return the username
201
	 */
202
	public String getUsername() {
203
		return username;
204
	}
205

    
206

    
207
	/**
208
	 * @param username the username to set
209
	 */
210
	public void setUsername(String username) {
211
		this.username = username;
212
	}
213

    
214

    
215
	/**
216
	 * @return the password
217
	 */
218
	public String getPassword() {
219
		return password;
220
	}
221

    
222

    
223
	/**
224
	 * @param password the password to set
225
	 */
226
	public void setPassword(String password) {
227
		this.password = password;
228
	}
229

    
230
}
(4-4/5)