Project

General

Profile

Download (5.22 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.datasource.wizard;
12

    
13
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.layout.GridData;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Group;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.swt.widgets.Text;
19

    
20
import eu.etaxonomy.cdm.database.CdmDataSource;
21
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
22
import eu.etaxonomy.cdm.database.ICdmDataSource;
23

    
24
/**
25
 * <p>CdmDataSourceMySQLWizardPage class.</p>
26
 *
27
 * @author n.hoffmann
28
 * @created 19.05.2009
29
 * @version 1.0
30
 */
31
public class CdmDataSourceMySQLWizardPage extends CdmDataSourceCredentialsWizardPage {
32
	
33
	private Text text_port;
34
	private Text text_server;
35

    
36
	private String server;
37

    
38
	private int port;
39

    
40
	
41

    
42
	/**
43
	 * <p>Constructor for CdmDataSourceMySQLWizardPage.</p>
44
	 *
45
	 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
46
	 */
47
	@Deprecated
48
	protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource) {
49
		super("MySQL", dataSource, CdmDataSourceWizard.Mode.CREATE);
50
		setTitle("MySQL Server");
51
		setDescription("Enter credentials for MySQL database");
52

    
53
	}
54
	
55
	/**
56
	 * <p>Constructor for CdmDataSourceMySQLWizardPage.</p>
57
	 *
58
	 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
59
	 * @param mode a {@link eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard.Mode} enum type.
60
	 */
61
	protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource, CdmDataSourceWizard.Mode mode) {
62
		super("MySQL", dataSource, mode);
63
		setTitle("MySQL Server");
64
		setDescription("Enter credentials for MySQL database");
65

    
66
	}
67
	
68
	/* (non-Javadoc)
69
	 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
70
	 */
71
	/** {@inheritDoc} */
72
	@Override
73
	public void createDatabaseForm() {
74
		// Create group composite for location data 
75
		locationGroup = new Group(composite, SWT.NONE);
76
		locationGroup.setText("Location");
77
		locationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 2));
78
		GridLayout locationLayout = new GridLayout();
79
		locationLayout.numColumns = 2;
80
		locationGroup.setLayout(locationLayout);
81

    
82
		// Create host label
83
		Label serverLabel = new Label(locationGroup, SWT.NONE);
84
		serverLabel.setText("Host:");
85

    
86
		// Create host input
87
		text_server = new Text(locationGroup, SWT.BORDER);
88
		text_server.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
89
		
90

    
91
		// Create port label
92
		Label portLabel = new Label(locationGroup, SWT.NONE);
93
		portLabel.setText("Port:");
94

    
95
		// Create port input
96
		text_port = new Text(locationGroup, SWT.BORDER);
97
		text_port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
98
		
99
		
100
	}
101

    
102
	/* (non-Javadoc)
103
	 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#updateLocation()
104
	 */
105
	/** {@inheritDoc} */
106
	@Override
107
	public void updateLocation() {
108
		server = text_server.getText();
109
		try{
110
			if(! text_port.getText().equals("")){
111
				port = new Integer(text_port.getText());
112
				setErrorMessage(null);
113
			}
114
		}catch(NumberFormatException e){
115
			setErrorMessage("Port number contains invalid characters");
116
		}
117
	}
118

    
119
	/* (non-Javadoc)
120
	 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
121
	 */
122
	/** {@inheritDoc} */
123
	@Override
124
	public void updateDataSource() {	
125
		ICdmDataSource dataSource = getDataSource();
126

    
127
		if(dataSource == null) {
128
			setDataSource(CdmDataSource.NewMySqlInstance(server,
129
					database,
130
					port,
131
					username,
132
					password,
133
					nomenclaturalCode));
134
		} else {
135
			dataSource.setName(name);
136
			dataSource.setServer(server);
137
			dataSource.setDatabase(database);
138
			dataSource.setPort(port);
139
			dataSource.setUsername(username);
140
			dataSource.setPassword(password);
141
			dataSource.setNomenclaturalCode(nomenclaturalCode);
142
		}
143
	}
144
	
145
	/* (non-Javadoc)
146
	 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
147
	 */
148
	/** {@inheritDoc} */
149
	@Override
150
	public void checkPageComplete() {
151
		// check if widgets of this component are complete
152
		boolean complete = server.trim().length() != 0;
153
		
154
		// set default port
155
		if(port == 0){
156
			port = DatabaseTypeEnum.MySQL.getDefaultPort();
157
		}
158
		
159
		setPageComplete(complete);
160
		
161
		// check if widgets of the extended class are complete
162
		super.checkPageComplete();
163
	}
164
	
165
	/* (non-Javadoc)
166
	 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
167
	 */
168
	/** {@inheritDoc} */
169
	@Override
170
	public void init() {
171
		super.init();
172
		if(getDataSource() != null){
173
			removeListeners();
174
			text_server.setText(getDataSource().getServer());
175
			text_port.setText(String.valueOf(getDataSource().getPort()));		
176
			// add listeners after setting text to avoid the modify event being called
177
			// for the initial value
178
			addListeners();
179
		}
180

    
181
	}
182
	
183
	private void addListeners() {
184
		text_server.addModifyListener(this);
185
		text_port.addModifyListener(this);
186
	}
187
	
188
	private void removeListeners() {
189
		text_server.removeModifyListener(this);
190
		text_port.removeModifyListener(this);
191
	}
192
}
(3-3/7)