Project

General

Profile

Download (4.42 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.apache.log4j.Logger;
14
import org.eclipse.jface.wizard.Wizard;
15
import org.eclipse.jface.wizard.WizardPage;
16

    
17
import eu.etaxonomy.cdm.database.CdmDataSource;
18
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
19
import eu.etaxonomy.cdm.database.ICdmDataSource;
20
import eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceRepository;
21

    
22
/**
23
 * @author n.hoffmann
24
 * @created 18.05.2009
25
 * @version 1.0
26
 */
27
public class CdmDataSourceWizard extends Wizard {
28
	private static final Logger logger = Logger
29
			.getLogger(CdmDataSourceWizard.class);
30

    
31
	
32
	private WizardPage dataSourcePage;
33

    
34
	private ICdmDataSource dataSource;
35
	
36
	private DatabaseTypeEnum databaseType;
37
	private String dataSourceName;
38
	private String server;
39
	private int port;
40
	private String database;
41
	private String username;
42
	private String password; 
43
	
44
	/**
45
	 * @param b
46
	 */
47
	public CdmDataSourceWizard(ICdmDataSource dataSource) {
48
		super();
49
		setForcePreviousAndNextButtons(true);
50
		
51
		
52
		
53
		if(dataSource != null){
54
			this.dataSource = dataSource;
55
			
56
			setDatabaseType(dataSource.getDatabaseType());
57
			setDataSourceName(dataSource.getName());
58
			setServer(dataSource.getServer());
59
			setPort(dataSource.getPort());
60
			setDatabase(dataSource.getDatabase());
61
			setUsername(dataSource.getUsername());
62
			setPassword(dataSource.getPassword());
63
		}
64
	}
65

    
66

    
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.jface.wizard.Wizard#addPages()
69
	 */
70
	@Override
71
	public void addPages() {
72

    
73
		if(dataSource == null){
74
			dataSourcePage = new CdmDataSourceWizardPage(dataSource);		
75
		}else{
76
			if(dataSource.getDatabaseType() == DatabaseTypeEnum.H2){
77
				dataSourcePage = new CdmDataSourceH2WizardPage(dataSource);
78
			}else if(dataSource.getDatabaseType() == DatabaseTypeEnum.MySQL){
79
				dataSourcePage = new CdmDataSourceMySQLWizardPage(dataSource);
80
			}
81
			
82
		}
83
		
84
		this.addPage(dataSourcePage);
85
	}
86

    
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
89
	 */
90
	@Override
91
	public boolean performFinish() {
92
		
93
		CdmDataSource dataSource = null ;
94
		
95
		if(databaseType == DatabaseTypeEnum.H2){
96
			dataSource = CdmDataSource.NewH2EmbeddedInstance(database, username, password);
97
		}else if(databaseType == DatabaseTypeEnum.MySQL){
98
			dataSource = CdmDataSource.NewMySqlInstance(server, database, port, username, password);
99
		}
100
					
101
		CdmDataSourceRepository.getDefault().save(dataSource);
102
		
103
		return true;
104
	}
105

    
106

    
107
	/**
108
	 * @return the dataSource
109
	 */
110
	public ICdmDataSource getDataSource() {
111
		return dataSource;
112
	}
113

    
114

    
115
	/**
116
	 * @param dataSource the dataSource to set
117
	 */
118
	public void setDataSource(ICdmDataSource dataSource) {
119
		this.dataSource = dataSource;
120
	}
121

    
122

    
123
	/**
124
	 * @return the databaseType
125
	 */
126
	public DatabaseTypeEnum getDatabaseType() {
127
		return databaseType;
128
	}
129

    
130

    
131
	/**
132
	 * @param databaseType the databaseType to set
133
	 */
134
	public void setDatabaseType(DatabaseTypeEnum databaseType) {
135
		this.databaseType = databaseType;
136
	}
137

    
138

    
139
	/**
140
	 * @return the dataSourceName
141
	 */
142
	public String getDataSourceName() {
143
		return dataSourceName;
144
	}
145

    
146

    
147
	/**
148
	 * @param dataSourceName the dataSourceName to set
149
	 */
150
	public void setDataSourceName(String dataSourceName) {
151
		this.dataSourceName = dataSourceName;
152
	}
153

    
154

    
155
	/**
156
	 * @return the server
157
	 */
158
	public String getServer() {
159
		return server;
160
	}
161

    
162

    
163
	/**
164
	 * @param server the server to set
165
	 */
166
	public void setServer(String server) {
167
		this.server = server;
168
	}
169

    
170

    
171
	/**
172
	 * @return the port
173
	 */
174
	public int getPort() {
175
		return port;
176
	}
177

    
178

    
179
	/**
180
	 * @param port the port to set
181
	 */
182
	public void setPort(int port) {
183
		this.port = port;
184
	}
185

    
186

    
187
	/**
188
	 * @return the database
189
	 */
190
	public String getDatabase() {
191
		return database;
192
	}
193

    
194

    
195
	/**
196
	 * @param database the database to set
197
	 */
198
	public void setDatabase(String database) {
199
		this.database = database;
200
	}
201

    
202

    
203
	/**
204
	 * @return the username
205
	 */
206
	public String getUsername() {
207
		return username;
208
	}
209

    
210

    
211
	/**
212
	 * @param username the username to set
213
	 */
214
	public void setUsername(String username) {
215
		this.username = username;
216
	}
217

    
218

    
219
	/**
220
	 * @return the password
221
	 */
222
	public String getPassword() {
223
		return password;
224
	}
225

    
226

    
227
	/**
228
	 * @param password the password to set
229
	 */
230
	public void setPassword(String password) {
231
		this.password = password;
232
	}
233

    
234
}
(4-4/5)