3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.datasource
.wizard
;
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
;
20 import eu
.etaxonomy
.cdm
.database
.CdmDataSource
;
21 import eu
.etaxonomy
.cdm
.database
.DatabaseTypeEnum
;
22 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
25 * <p>CdmDataSourceMySQLWizardPage class.</p>
31 public class CdmDataSourceMySQLWizardPage
extends CdmDataSourceCredentialsWizardPage
{
33 private Text text_port
;
34 private Text text_server
;
36 private String server
;
43 * <p>Constructor for CdmDataSourceMySQLWizardPage.</p>
45 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
48 protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource
) {
49 super("MySQL", dataSource
, CdmDataSourceWizard
.Mode
.CREATE
);
50 setTitle("MySQL Server");
51 setDescription("Enter credentials for MySQL database");
56 * <p>Constructor for CdmDataSourceMySQLWizardPage.</p>
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.
61 protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource
, CdmDataSourceWizard
.Mode mode
) {
62 super("MySQL", dataSource
, mode
);
63 setTitle("MySQL Server");
64 setDescription("Enter credentials for MySQL database");
69 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
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
);
83 Label serverLabel
= new Label(locationGroup
, SWT
.NONE
);
84 serverLabel
.setText("Host:");
87 text_server
= new Text(locationGroup
, SWT
.BORDER
);
88 text_server
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
92 Label portLabel
= new Label(locationGroup
, SWT
.NONE
);
93 portLabel
.setText("Port:");
96 text_port
= new Text(locationGroup
, SWT
.BORDER
);
97 text_port
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
103 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#updateLocation()
107 public void updateLocation() {
108 server
= text_server
.getText();
110 if(! text_port
.getText().equals("")){
111 port
= new Integer(text_port
.getText());
112 setErrorMessage(null);
114 }catch(NumberFormatException e
){
115 setErrorMessage("Port number contains invalid characters");
120 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
124 public void updateDataSource() {
125 ICdmDataSource dataSource
= getDataSource();
127 if(dataSource
== null) {
128 setDataSource(CdmDataSource
.NewMySqlInstance(server
,
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
);
146 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
150 public void checkPageComplete() {
151 // check if widgets of this component are complete
152 boolean complete
= server
.trim().length() != 0;
156 port
= DatabaseTypeEnum
.MySQL
.getDefaultPort();
159 setPageComplete(complete
);
161 // check if widgets of the extended class are complete
162 super.checkPageComplete();
166 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
172 if(getDataSource() != null){
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
183 private void addListeners() {
184 text_server
.addModifyListener(this);
185 text_port
.addModifyListener(this);
188 private void removeListeners() {
189 text_server
.removeModifyListener(this);
190 text_port
.removeModifyListener(this);