1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.datasource.wizard;
|
5
|
|
6
|
import org.eclipse.swt.SWT;
|
7
|
import org.eclipse.swt.layout.GridData;
|
8
|
import org.eclipse.swt.layout.GridLayout;
|
9
|
import org.eclipse.swt.widgets.Group;
|
10
|
import org.eclipse.swt.widgets.Label;
|
11
|
import org.eclipse.swt.widgets.Text;
|
12
|
|
13
|
import eu.etaxonomy.cdm.database.CdmDataSource;
|
14
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
15
|
|
16
|
/**
|
17
|
* @author n.hoffmann
|
18
|
*
|
19
|
*/
|
20
|
public class CdmDataSourcePostgreSQLServerWizardPage extends
|
21
|
CdmDataSourceCredentialsWizardPage {
|
22
|
|
23
|
private Text text_port;
|
24
|
private Text text_server;
|
25
|
|
26
|
private String server;
|
27
|
|
28
|
private int port;
|
29
|
|
30
|
@Deprecated
|
31
|
protected CdmDataSourcePostgreSQLServerWizardPage(ICdmDataSource dataSource) {
|
32
|
super("PostgreSQL Server", dataSource);
|
33
|
setTitle("PostgreSQL Server");
|
34
|
setDescription("Enter credentials for PostgreSQL Server database");
|
35
|
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* <p>Constructor for CdmDataSourcePostgreSQLServerWizardPage.</p>
|
40
|
*
|
41
|
* @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
|
42
|
* @param mode a {@link eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard.Mode} enum type.
|
43
|
*/
|
44
|
protected CdmDataSourcePostgreSQLServerWizardPage(ICdmDataSource dataSource, CdmDataSourceWizard.Mode mode) {
|
45
|
super("PostgreSQL Server", dataSource, mode);
|
46
|
setTitle("PostgreSQL Server");
|
47
|
setDescription("Enter credentials for PostgreSQL Server database");
|
48
|
|
49
|
}
|
50
|
|
51
|
/* (non-Javadoc)
|
52
|
* @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
|
53
|
*/
|
54
|
@Override
|
55
|
public void createDatabaseForm() {
|
56
|
// Create group composite for location data
|
57
|
locationGroup = new Group(composite, SWT.NONE);
|
58
|
locationGroup.setText("Location");
|
59
|
locationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
|
60
|
GridLayout locationLayout = new GridLayout();
|
61
|
locationLayout.numColumns = 2;
|
62
|
locationGroup.setLayout(locationLayout);
|
63
|
|
64
|
// Create host label
|
65
|
Label serverLabel = new Label(locationGroup, SWT.NONE);
|
66
|
serverLabel.setText("Host:");
|
67
|
|
68
|
// Create host input
|
69
|
text_server = new Text(locationGroup, SWT.BORDER);
|
70
|
text_server.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
71
|
|
72
|
|
73
|
// Create port label
|
74
|
Label portLabel = new Label(locationGroup, SWT.NONE);
|
75
|
portLabel.setText("Port:");
|
76
|
|
77
|
// Create port input
|
78
|
text_port = new Text(locationGroup, SWT.BORDER);
|
79
|
text_port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
|
80
|
|
81
|
|
82
|
}
|
83
|
|
84
|
/* (non-Javadoc)
|
85
|
* @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateLocation()
|
86
|
*/
|
87
|
@Override
|
88
|
public void updateLocation() {
|
89
|
server = text_server.getText();
|
90
|
try{
|
91
|
if(! text_port.getText().equals("")){
|
92
|
port = new Integer(text_port.getText());
|
93
|
setErrorMessage(null);
|
94
|
}
|
95
|
}catch(NumberFormatException e){
|
96
|
setErrorMessage("Port number contains invalid characters");
|
97
|
}
|
98
|
}
|
99
|
|
100
|
/* (non-Javadoc)
|
101
|
* @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
|
102
|
*/
|
103
|
@Override
|
104
|
public void updateDataSource() {
|
105
|
|
106
|
|
107
|
ICdmDataSource dataSource = getDataSource();
|
108
|
|
109
|
if(dataSource == null) {
|
110
|
setDataSource(CdmDataSource.NewPostgreSQLInstance(server,
|
111
|
database,
|
112
|
port,
|
113
|
username,
|
114
|
password,
|
115
|
nomenclaturalCode));
|
116
|
} else {
|
117
|
dataSource.setName(name);
|
118
|
dataSource.setServer(server);
|
119
|
dataSource.setDatabase(database);
|
120
|
dataSource.setPort(port);
|
121
|
dataSource.setUsername(username);
|
122
|
dataSource.setPassword(password);
|
123
|
dataSource.setNomenclaturalCode(nomenclaturalCode);
|
124
|
}
|
125
|
}
|
126
|
|
127
|
/* (non-Javadoc)
|
128
|
* @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
|
129
|
*/
|
130
|
/** {@inheritDoc} */
|
131
|
@Override
|
132
|
public void init() {
|
133
|
super.init();
|
134
|
if(getDataSource() != null){
|
135
|
removeListeners();
|
136
|
text_server.setText(getDataSource().getServer());
|
137
|
text_port.setText(String.valueOf(getDataSource().getPort()));
|
138
|
// add listeners after setting text to avoid the modify event being called
|
139
|
// for the initial value
|
140
|
addListeners();
|
141
|
}
|
142
|
|
143
|
}
|
144
|
|
145
|
private void addListeners() {
|
146
|
text_server.addModifyListener(this);
|
147
|
text_port.addModifyListener(this);
|
148
|
}
|
149
|
|
150
|
private void removeListeners() {
|
151
|
text_server.removeModifyListener(this);
|
152
|
text_port.removeModifyListener(this);
|
153
|
}
|
154
|
|
155
|
}
|