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>
30 public class CdmDataSourceMySQLWizardPage
extends CdmDataSourceCredentialsWizardPage
{
32 private Text text_port
;
33 private Text text_server
;
35 private String server
;
42 * <p>Constructor for CdmDataSourceMySQLWizardPage.</p>
44 * @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.
58 * @param mode a {@link eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard.Mode} enum type.
60 protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource
, CdmDataSourceWizard
.Mode mode
) {
61 super("MySQL", dataSource
, mode
);
62 setTitle("MySQL Server");
63 setDescription("Enter credentials for MySQL database");
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
);
79 Label serverLabel
= new Label(locationGroup
, SWT
.NONE
);
80 serverLabel
.setText("Host:");
83 text_server
= new Text(locationGroup
, SWT
.BORDER
);
84 text_server
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
88 Label portLabel
= new Label(locationGroup
, SWT
.NONE
);
89 portLabel
.setText("Port:");
92 text_port
= new Text(locationGroup
, SWT
.BORDER
);
93 text_port
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
100 public void updateLocation() {
101 server
= text_server
.getText();
103 if(! text_port
.getText().equals("")){
104 port
= new Integer(text_port
.getText());
105 setErrorMessage(null);
107 }catch(NumberFormatException e
){
108 setErrorMessage("Port number contains invalid characters");
114 public void updateDataSource() {
115 ICdmDataSource dataSource
= getDataSource();
117 if(dataSource
== null) {
118 setDataSource(CdmDataSource
.NewMySqlInstance(server
,
124 dataSource
.setName(name
);
125 dataSource
.setServer(server
);
126 dataSource
.setDatabase(database
);
127 dataSource
.setPort(port
);
128 dataSource
.setUsername(username
);
129 dataSource
.setPassword(password
);
135 public void checkPageComplete() {
136 // check if widgets of this component are complete
137 boolean complete
= server
.trim().length() != 0;
141 port
= DatabaseTypeEnum
.MySQL
.getDefaultPort();
144 setPageComplete(complete
);
146 // check if widgets of the extended class are complete
147 super.checkPageComplete();
154 if(getDataSource() != null){
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
165 private void addListeners() {
166 text_server
.addModifyListener(this);
167 text_port
.addModifyListener(this);
170 private void removeListeners() {
171 text_server
.removeModifyListener(this);
172 text_port
.removeModifyListener(this);