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.
47 protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource
) {
48 super("MySQL", dataSource
, CdmDataSourceWizard
.Mode
.CREATE
);
49 setTitle("MySQL Server");
50 setDescription("Enter credentials for MySQL database");
55 * <p>Constructor for CdmDataSourceMySQLWizardPage.</p>
57 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
59 protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource
, CdmDataSourceWizard
.Mode mode
) {
60 super("MySQL", dataSource
, mode
);
61 setTitle("MySQL Server");
62 setDescription("Enter credentials for MySQL database");
67 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
71 public void createDatabaseForm() {
72 // Create group composite for location data
73 locationGroup
= new Group(composite
, SWT
.NONE
);
74 locationGroup
.setText("Location");
75 locationGroup
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 2));
76 GridLayout locationLayout
= new GridLayout();
77 locationLayout
.numColumns
= 2;
78 locationGroup
.setLayout(locationLayout
);
81 Label serverLabel
= new Label(locationGroup
, SWT
.NONE
);
82 serverLabel
.setText("Host:");
85 text_server
= new Text(locationGroup
, SWT
.BORDER
);
86 text_server
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
90 Label portLabel
= new Label(locationGroup
, SWT
.NONE
);
91 portLabel
.setText("Port:");
94 text_port
= new Text(locationGroup
, SWT
.BORDER
);
95 text_port
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
101 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#updateLocation()
105 public void updateLocation() {
106 server
= text_server
.getText();
108 if(! text_port
.getText().equals("")){
109 port
= new Integer(text_port
.getText());
110 setErrorMessage(null);
112 }catch(NumberFormatException e
){
113 setErrorMessage("Port number contains invalid characters");
118 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
122 public void updateDataSource() {
123 ICdmDataSource dataSource
= getDataSource();
125 if(dataSource
== null) {
126 setDataSource(CdmDataSource
.NewMySqlInstance(server
,
133 dataSource
.setName(name
);
134 dataSource
.setServer(server
);
135 dataSource
.setDatabase(database
);
136 dataSource
.setPort(port
);
137 dataSource
.setUsername(username
);
138 dataSource
.setPassword(password
);
139 dataSource
.setNomenclaturalCode(nomenclaturalCode
);
144 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
148 public void checkPageComplete() {
149 // check if widgets of this component are complete
150 boolean complete
= server
.trim().length() != 0;
154 port
= DatabaseTypeEnum
.MySQL
.getDefaultPort();
157 setPageComplete(complete
);
159 // check if widgets of the extended class are complete
160 super.checkPageComplete();
164 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
170 if(getDataSource() != null){
172 text_server
.setText(getDataSource().getServer());
173 text_port
.setText(String
.valueOf(getDataSource().getPort()));
174 // add listeners after setting text to avoid the modify event being called
175 // for the initial value
181 private void addListeners() {
182 text_server
.addModifyListener(this);
183 text_port
.addModifyListener(this);
186 private void removeListeners() {
187 text_server
.removeModifyListener(this);
188 text_port
.removeModifyListener(this);