--- /dev/null
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.webapp.datasource.wizard;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+import eu.etaxonomy.cdm.database.CdmDataSource;
+import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+
+/**
+ * <p>CdmDataSourceSQLServerWizardPage class.</p>
+ *
+ * @author n.hoffmann
+ * @created 19.05.2009
+ * @version 1.0
+ */
+public class CdmDataSourceSQLServerWizardPage extends CdmDataSourceCredentialsWizardPage {
+
+ private Text text_port;
+ private Text text_server;
+
+ private String server;
+
+ private int port;
+
+ /**
+ * <p>Constructor for CdmDataSourceSQLServerWizardPage.</p>
+ *
+ * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
+ */
+ @Deprecated
+ public CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource) {
+ super("SQL Server", dataSource);
+ setTitle("SQL Server");
+ setDescription("Enter credentials for SQL Server database");
+ this.setDataSource(dataSource);
+ }
+
+ /**
+ * <p>Constructor for CdmDataSourceSQLServerWizardPage.</p>
+ *
+ * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
+ * param mode a {@link eu.etaxonomy.taxeditor.webapp.datasource.common.wizard.CdmDataSourceWizard.Mode} enum type.
+ */
+ public CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource, CdmDataSourceWizard.Mode mode) {
+ super("SQL Server", dataSource, mode);
+ setTitle("SQL Server");
+ setDescription("Enter credentials for SQL Server database");
+ this.setDataSource(dataSource);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void createDatabaseForm() {
+ // Create group composite for location data
+ locationGroup = new Group(composite, SWT.NONE);
+ locationGroup.setText("Location");
+ locationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
+ GridLayout locationLayout = new GridLayout();
+ locationLayout.numColumns = 2;
+ locationGroup.setLayout(locationLayout);
+
+ // Create host label
+ Label serverLabel = new Label(locationGroup, SWT.NONE);
+ serverLabel.setText("Host:");
+
+ // Create host input
+ text_server = new Text(locationGroup, SWT.BORDER);
+ text_server.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ text_server.addModifyListener(this);
+
+ // Create port label
+ Label portLabel = new Label(locationGroup, SWT.NONE);
+ portLabel.setText("Port:");
+
+ // Create port input
+ text_port = new Text(locationGroup, SWT.BORDER);
+ text_port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+
+ text_port.addModifyListener(this);
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#updateLocation()
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void updateLocation() {
+ server = text_server.getText();
+ try{
+ if(! text_port.getText().equals("")){
+ port = new Integer(text_port.getText());
+ setErrorMessage(null);
+ }
+ }catch(NumberFormatException e){
+ setErrorMessage("Port number contains invalid characters");
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.webapp.datasource.common.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void updateDataSource() {
+
+
+
+ ICdmDataSource dataSource = getDataSource();
+
+ if(dataSource == null) {
+ setDataSource(CdmDataSource.NewSqlServer2005Instance(server,
+ database,
+ port,
+ username,
+ password));
+ } else {
+ dataSource.setName(name);
+ dataSource.setServer(server);
+ dataSource.setDatabase(database);
+ dataSource.setPort(port);
+ dataSource.setUsername(username);
+ dataSource.setPassword(password);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.webapp.datasource.common.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void checkPageComplete() {
+ // check if widgets of this component are complete
+ boolean complete = server.trim().length() != 0;
+
+ // set default port
+ if(port == 0){
+ port = DatabaseTypeEnum.SqlServer2005.getDefaultPort();
+ }
+
+ setPageComplete(complete);
+
+ // check if widgets of the extended class are complete
+ super.checkPageComplete();
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.webapp.datasource.common.wizard.CdmDataSourceCredentialsWizardPage#init()
+ */
+ /** {@inheritDoc} */
+ @Override
+ public void init() {
+ super.init();
+ if(getDataSource() != null){
+ removeListeners();
+ text_server.setText(getDataSource().getServer());
+ text_port.setText(String.valueOf(getDataSource().getPort()));
+ // add listeners after setting text to avoid the modify event being called
+ // for the initial value
+ addListeners();
+ }
+
+ }
+
+ private void addListeners() {
+ text_server.addModifyListener(this);
+ text_port.addModifyListener(this);
+ }
+
+ private void removeListeners() {
+ text_server.removeModifyListener(this);
+ text_port.removeModifyListener(this);
+ }
+
+
+}