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>CdmDataSourceSQLServerWizardPage class.</p>
31 public class CdmDataSourceSQLServerWizardPage
extends CdmDataSourceCredentialsWizardPage
{
33 private Text text_port
;
34 private Text text_server
;
36 private String server
;
41 * <p>Constructor for CdmDataSourceSQLServerWizardPage.</p>
43 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
46 public CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource
) {
47 super("SQL Server", dataSource
);
48 setTitle("SQL Server");
49 setDescription("Enter credentials for SQL Server database");
50 this.setDataSource(dataSource
);
54 * <p>Constructor for CdmDataSourceSQLServerWizardPage.</p>
56 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
57 * param mode a {@link eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard.Mode} enum type.
59 public CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource
, CdmDataSourceWizard
.Mode mode
) {
60 super("SQL Server", dataSource
, mode
);
61 setTitle("SQL Server");
62 setDescription("Enter credentials for SQL Server database");
63 this.setDataSource(dataSource
);
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, 1));
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));
87 text_server
.addModifyListener(this);
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));
97 text_port
.addModifyListener(this);
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() {
126 ICdmDataSource dataSource
= getDataSource();
128 if(dataSource
== null) {
129 setDataSource(CdmDataSource
.NewSqlServer2005Instance(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
);
145 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
149 public void checkPageComplete() {
150 // check if widgets of this component are complete
151 boolean complete
= server
.trim().length() != 0;
155 port
= DatabaseTypeEnum
.SqlServer2005
.getDefaultPort();
158 setPageComplete(complete
);
160 // check if widgets of the extended class are complete
161 super.checkPageComplete();
165 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
171 if(getDataSource() != null){
173 text_server
.setText(getDataSource().getServer());
174 text_port
.setText(String
.valueOf(getDataSource().getPort()));
175 // add listeners after setting text to avoid the modify event being called
176 // for the initial value
182 private void addListeners() {
183 text_server
.addModifyListener(this);
184 text_port
.addModifyListener(this);
187 private void removeListeners() {
188 text_server
.removeModifyListener(this);
189 text_port
.removeModifyListener(this);