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
|
*/
|
30
|
public class CdmDataSourceMySQLWizardPage extends CdmDataSourceCredentialsWizardPage {
|
31
|
|
32
|
private Text text_port;
|
33
|
private Text text_server;
|
34
|
|
35
|
private String server;
|
36
|
|
37
|
private int port;
|
38
|
|
39
|
|
40
|
|
41
|
/**
|
42
|
* <p>Constructor for CdmDataSourceMySQLWizardPage.</p>
|
43
|
*
|
44
|
* @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
|
45
|
*/
|
46
|
@Deprecated
|
47
|
protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource) {
|
48
|
super("MySQL", dataSource, CdmDataSourceWizard.Mode.CREATE);
|
49
|
setTitle("MySQL Server");
|
50
|
setDescription("Enter credentials for MySQL database");
|
51
|
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* <p>Constructor for CdmDataSourceMySQLWizardPage.</p>
|
56
|
*
|
57
|
* @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
|
58
|
* @param mode a {@link eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard.Mode} enum type.
|
59
|
*/
|
60
|
protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource, CdmDataSourceWizard.Mode mode) {
|
61
|
super("MySQL", dataSource, mode);
|
62
|
setTitle("MySQL Server");
|
63
|
setDescription("Enter credentials for MySQL database");
|
64
|
|
65
|
}
|
66
|
|
67
|
/** {@inheritDoc} */
|
68
|
@Override
|
69
|
public void createDatabaseForm() {
|
70
|
// Create group composite for location data
|
71
|
locationGroup = new Group(composite, SWT.NONE);
|
72
|
locationGroup.setText("Location");
|
73
|
locationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 2));
|
74
|
GridLayout locationLayout = new GridLayout();
|
75
|
locationLayout.numColumns = 2;
|
76
|
locationGroup.setLayout(locationLayout);
|
77
|
|
78
|
// Create host label
|
79
|
Label serverLabel = new Label(locationGroup, SWT.NONE);
|
80
|
serverLabel.setText("Host:");
|
81
|
|
82
|
// Create host input
|
83
|
text_server = new Text(locationGroup, SWT.BORDER);
|
84
|
text_server.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
85
|
|
86
|
|
87
|
// Create port label
|
88
|
Label portLabel = new Label(locationGroup, SWT.NONE);
|
89
|
portLabel.setText("Port:");
|
90
|
|
91
|
// Create port input
|
92
|
text_port = new Text(locationGroup, SWT.BORDER);
|
93
|
text_port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
94
|
|
95
|
|
96
|
}
|
97
|
|
98
|
/** {@inheritDoc} */
|
99
|
@Override
|
100
|
public void updateLocation() {
|
101
|
server = text_server.getText();
|
102
|
try{
|
103
|
if(! text_port.getText().equals("")){
|
104
|
port = new Integer(text_port.getText());
|
105
|
setErrorMessage(null);
|
106
|
}
|
107
|
}catch(NumberFormatException e){
|
108
|
setErrorMessage("Port number contains invalid characters");
|
109
|
}
|
110
|
}
|
111
|
|
112
|
/** {@inheritDoc} */
|
113
|
@Override
|
114
|
public void updateDataSource() {
|
115
|
ICdmDataSource dataSource = getDataSource();
|
116
|
|
117
|
if(dataSource == null) {
|
118
|
setDataSource(CdmDataSource.NewMySqlInstance(server,
|
119
|
database,
|
120
|
port,
|
121
|
username,
|
122
|
password));
|
123
|
} else {
|
124
|
dataSource.setName(name);
|
125
|
dataSource.setServer(server);
|
126
|
dataSource.setDatabase(database);
|
127
|
dataSource.setPort(port);
|
128
|
dataSource.setUsername(username);
|
129
|
dataSource.setPassword(password);
|
130
|
}
|
131
|
}
|
132
|
|
133
|
/** {@inheritDoc} */
|
134
|
@Override
|
135
|
public void checkPageComplete() {
|
136
|
// check if widgets of this component are complete
|
137
|
boolean complete = server.trim().length() != 0;
|
138
|
|
139
|
// set default port
|
140
|
if(port == 0){
|
141
|
port = DatabaseTypeEnum.MySQL.getDefaultPort();
|
142
|
}
|
143
|
|
144
|
setPageComplete(complete);
|
145
|
|
146
|
// check if widgets of the extended class are complete
|
147
|
super.checkPageComplete();
|
148
|
}
|
149
|
|
150
|
/** {@inheritDoc} */
|
151
|
@Override
|
152
|
public void init() {
|
153
|
super.init();
|
154
|
if(getDataSource() != null){
|
155
|
removeListeners();
|
156
|
text_server.setText(getDataSource().getServer());
|
157
|
text_port.setText(String.valueOf(getDataSource().getPort()));
|
158
|
// add listeners after setting text to avoid the modify event being called
|
159
|
// for the initial value
|
160
|
addListeners();
|
161
|
}
|
162
|
|
163
|
}
|
164
|
|
165
|
private void addListeners() {
|
166
|
text_server.addModifyListener(this);
|
167
|
text_port.addModifyListener(this);
|
168
|
}
|
169
|
|
170
|
private void removeListeners() {
|
171
|
text_server.removeModifyListener(this);
|
172
|
text_port.removeModifyListener(this);
|
173
|
}
|
174
|
}
|