refactored wizard dialog and pages to allow for easy in place editing and cloning...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / datasource / wizard / CdmDataSourcePostgreSQLServerWizardPage.java
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 protected CdmDataSourcePostgreSQLServerWizardPage(ICdmDataSource dataSource) {
31 super("PostgreSQL Server", dataSource);
32 setTitle("PostgreSQL Server");
33 setDescription("Enter credentials for PostgreSQL Server database");
34
35 }
36
37 /* (non-Javadoc)
38 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
39 */
40 @Override
41 public void createDatabaseForm() {
42 // Create group composite for location data
43 locationGroup = new Group(composite, SWT.NONE);
44 locationGroup.setText("Location");
45 locationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
46 GridLayout locationLayout = new GridLayout();
47 locationLayout.numColumns = 2;
48 locationGroup.setLayout(locationLayout);
49
50 // Create host label
51 Label serverLabel = new Label(locationGroup, SWT.NONE);
52 serverLabel.setText("Host:");
53
54 // Create host input
55 text_server = new Text(locationGroup, SWT.BORDER);
56 text_server.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
57
58
59 // Create port label
60 Label portLabel = new Label(locationGroup, SWT.NONE);
61 portLabel.setText("Port:");
62
63 // Create port input
64 text_port = new Text(locationGroup, SWT.BORDER);
65 text_port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
66
67
68 }
69
70 /* (non-Javadoc)
71 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateLocation()
72 */
73 @Override
74 public void updateLocation() {
75 server = text_server.getText();
76 try{
77 if(! text_port.getText().equals("")){
78 port = new Integer(text_port.getText());
79 setErrorMessage(null);
80 }
81 }catch(NumberFormatException e){
82 setErrorMessage("Port number contains invalid characters");
83 }
84 }
85
86 /* (non-Javadoc)
87 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
88 */
89 @Override
90 public void updateDataSource() {
91
92
93 ICdmDataSource dataSource = getDataSource();
94
95 if(dataSource == null) {
96 setDataSource(CdmDataSource.NewPostgreSQLInstance(server,
97 database,
98 port,
99 username,
100 password,
101 nomenclaturalCode));
102 } else {
103 dataSource.setName(name);
104 dataSource.setServer(server);
105 dataSource.setDatabase(database);
106 dataSource.setPort(port);
107 dataSource.setUsername(username);
108 dataSource.setPassword(password);
109 dataSource.setNomenclaturalCode(nomenclaturalCode);
110 }
111 }
112
113 /* (non-Javadoc)
114 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
115 */
116 /** {@inheritDoc} */
117 @Override
118 public void init() {
119 super.init();
120 if(getDataSource() != null){
121 removeListeners();
122 text_server.setText(getDataSource().getServer());
123 text_port.setText(String.valueOf(getDataSource().getPort()));
124 // add listeners after setting text to avoid the modify event being called
125 // for the initial value
126 addListeners();
127 }
128
129 }
130
131 private void addListeners() {
132 text_server.addModifyListener(this);
133 text_port.addModifyListener(this);
134 }
135
136 private void removeListeners() {
137 text_server.removeModifyListener(this);
138 text_port.removeModifyListener(this);
139 }
140
141 }