2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.local
.datasource
.wizard
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.layout
.GridData
;
14 import org
.eclipse
.swt
.layout
.GridLayout
;
15 import org
.eclipse
.swt
.widgets
.Group
;
16 import org
.eclipse
.swt
.widgets
.Label
;
17 import org
.eclipse
.swt
.widgets
.Text
;
19 import eu
.etaxonomy
.cdm
.database
.CdmDataSource
;
20 import eu
.etaxonomy
.cdm
.database
.DatabaseTypeEnum
;
21 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
24 * <p>CdmDataSourceSQLServerWizardPage class.</p>
30 public class CdmDataSourceSQLServerWizardPage
extends CdmDataSourceCredentialsWizardPage
{
32 private Text text_port
;
33 private Text text_server
;
35 private String server
;
40 * <p>Constructor for CdmDataSourceSQLServerWizardPage.</p>
42 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
45 public CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource
) {
46 super("SQL Server", dataSource
);
47 setTitle("SQL Server");
48 setDescription("Enter credentials for SQL Server database");
49 this.setDataSource(dataSource
);
53 * <p>Constructor for CdmDataSourceSQLServerWizardPage.</p>
55 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
56 * param mode a {@link eu.etaxonomy.taxeditor.webapp.datasource.common.wizard.CdmDataSourceWizard.Mode} enum type.
58 public CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource
, CdmDataSourceWizard
.Mode mode
) {
59 super("SQL Server", dataSource
, mode
);
60 setTitle("SQL Server");
61 setDescription("Enter credentials for SQL Server database");
62 this.setDataSource(dataSource
);
66 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
70 public void createDatabaseForm() {
71 // Create group composite for location data
72 locationGroup
= new Group(composite
, SWT
.NONE
);
73 locationGroup
.setText("Location");
74 locationGroup
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
75 GridLayout locationLayout
= new GridLayout();
76 locationLayout
.numColumns
= 2;
77 locationGroup
.setLayout(locationLayout
);
80 Label serverLabel
= new Label(locationGroup
, SWT
.NONE
);
81 serverLabel
.setText("Host:");
84 text_server
= new Text(locationGroup
, SWT
.BORDER
);
85 text_server
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
86 text_server
.addModifyListener(this);
89 Label portLabel
= new Label(locationGroup
, SWT
.NONE
);
90 portLabel
.setText("Port:");
93 text_port
= new Text(locationGroup
, SWT
.BORDER
);
94 text_port
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
96 text_port
.addModifyListener(this);
100 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#updateLocation()
104 public void updateLocation() {
105 server
= text_server
.getText();
107 if(! text_port
.getText().equals("")){
108 port
= new Integer(text_port
.getText());
109 setErrorMessage(null);
111 }catch(NumberFormatException e
){
112 setErrorMessage("Port number contains invalid characters");
117 * @see eu.etaxonomy.taxeditor.webapp.datasource.common.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
121 public void updateDataSource() {
125 ICdmDataSource dataSource
= getDataSource();
127 if(dataSource
== null) {
128 setDataSource(CdmDataSource
.NewSqlServer2005Instance(server
,
134 dataSource
.setName(name
);
135 dataSource
.setServer(server
);
136 dataSource
.setDatabase(database
);
137 dataSource
.setPort(port
);
138 dataSource
.setUsername(username
);
139 dataSource
.setPassword(password
);
144 * @see eu.etaxonomy.taxeditor.webapp.datasource.common.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
.SqlServer2005
.getDefaultPort();
157 setPageComplete(complete
);
159 // check if widgets of the extended class are complete
160 super.checkPageComplete();
164 * @see eu.etaxonomy.taxeditor.webapp.datasource.common.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);