ref #9190: rename webapp to local
[taxeditor.git] / eu.etaxonomy.taxeditor.webapp / src / main / java / eu / etaxonomy / taxeditor / local / datasource / wizard / CdmDataSourceCredentialsWizardPage.java
diff --git a/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/local/datasource/wizard/CdmDataSourceCredentialsWizardPage.java b/eu.etaxonomy.taxeditor.webapp/src/main/java/eu/etaxonomy/taxeditor/local/datasource/wizard/CdmDataSourceCredentialsWizardPage.java
deleted file mode 100644 (file)
index b198d45..0000000
+++ /dev/null
@@ -1,406 +0,0 @@
-/**
-* 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.local.datasource.wizard;
-
-import java.sql.SQLException;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.wizard.IWizardPage;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-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.ICdmDataSource;
-import eu.etaxonomy.taxeditor.local.datasource.common.CdmDataSourceRepository;
-
-/**
- * <p>Abstract CdmDataSourceCredentialsWizardPage class.</p>
- *
- * @author n.hoffmann
- * @created 19.05.2009
- * @version 1.0
- */
-public abstract class CdmDataSourceCredentialsWizardPage extends WizardPage implements ModifyListener {
-       private ICdmDataSource dataSource;
-
-       protected Text text_password;
-       protected Text text_databaseName;
-       protected Text text_dataSourceName;
-       protected Text text_username;
-
-       protected Group authenticationGroup;
-       protected Group locationGroup;
-
-       protected Composite composite;
-
-       protected Composite parent;
-
-       protected String name;
-       protected String database;
-       protected String username;
-       protected String password;
-
-       CdmDataSourceWizard.Mode mode;
-
-       /**
-        * <p>Constructor for CdmDataSourceCredentialsWizardPage.</p>
-        *
-        * @param pageName a {@link java.lang.String} object.
-        */
-       protected CdmDataSourceCredentialsWizardPage(String pageName, ICdmDataSource dataSource) {
-               super(pageName);
-               this.setPageComplete(false);
-               setDataSource(dataSource);
-               mode = CdmDataSourceWizard.Mode.CREATE;
-       }
-
-       /**
-        * <p>Constructor for CdmDataSourceCredentialsWizardPage.</p>
-        *
-        * @param pageName a {@link java.lang.String} object.
-        */
-       protected CdmDataSourceCredentialsWizardPage(String pageName, ICdmDataSource dataSource, CdmDataSourceWizard.Mode mode) {
-               super(pageName);
-               this.setPageComplete(false);
-
-               this.mode = mode;
-               if(mode == CdmDataSourceWizard.Mode.CLONE) {
-                       setDataSource(CdmDataSource.NewInstance(dataSource));
-               } else {
-                       setDataSource(dataSource);
-               }
-       }
-
-       /** {@inheritDoc} */
-       @Override
-    public void createControl(Composite parent) {
-               this.parent = parent;
-
-               // Create top-level composite
-               parent.setLayout(new GridLayout());
-               composite = new Composite(parent, SWT.NONE);
-               composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,2,5));
-               GridLayout formLayout = new GridLayout();
-               formLayout.numColumns = 2;
-               composite.setLayout(formLayout);
-
-
-
-               // Create composite for data source name
-               Composite editDatasourceComposite = new Composite(composite, SWT.NONE);
-               GridData datasourceGridData = new GridData(SWT.FILL, SWT.TOP, true, true,2,1);
-               editDatasourceComposite.setLayoutData(datasourceGridData);
-               GridLayout datasourceLayout = new GridLayout();
-               datasourceLayout.numColumns = 2;
-               editDatasourceComposite.setLayout(datasourceLayout);
-
-               // Create label and input for dataSource name
-               Label datasourceNameLabel = new Label(editDatasourceComposite, SWT.NONE);
-               datasourceNameLabel.setText("Datasource Name:");
-               text_dataSourceName = new Text(editDatasourceComposite, SWT.BORDER);
-               text_dataSourceName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
-               if(getDataSource() == null) {
-                       editDatasourceComposite.setVisible(false);
-               }
-
-               // create a database specific form
-               createDatabaseForm();
-
-               // create the authentication input fields
-               createAuthenticationForm();
-
-               // Create composite for buttons
-               Composite buttonComposite = new Composite(composite, SWT.NONE);
-               buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
-               GridLayout buttonLayout = new GridLayout();
-               buttonLayout.numColumns = 1;
-               buttonComposite.setLayout(buttonLayout);
-
-               // Create test connection button
-               Button testButton = new Button(buttonComposite, SWT.NONE);
-               testButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
-               testButton.setText("Test connection");
-
-               // Test connection when button is pressed
-               testButton.addSelectionListener(new SelectionAdapter() {
-                       @Override
-                       public void widgetSelected(SelectionEvent e) {
-                               testDbConfiguration();
-                       }
-               });
-
-               setControl(composite);
-
-               init();
-
-       }
-
-       /**
-        * <p>createAuthenticationForm</p>
-        */
-       protected void createAuthenticationForm(){
-               // Create group composite for authentication data
-               authenticationGroup = new Group(composite, SWT.NONE);
-               authenticationGroup.setText("Authentication");
-               authenticationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 3));
-               GridLayout authenticationLayout = new GridLayout();
-               authenticationLayout.numColumns = 2;
-               authenticationGroup.setLayout(authenticationLayout);
-
-               // Create database name label
-               Label databaseNameLabel = new Label(authenticationGroup, SWT.NONE);
-               databaseNameLabel.setText("Database Name:");
-
-               // Create database name input
-               text_databaseName = new Text(authenticationGroup, SWT.BORDER);
-               text_databaseName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
-               // Create username label
-               Label usernameLabel = new Label(authenticationGroup, SWT.NONE);
-               usernameLabel.setText("User Name:");
-
-               // Create username input
-               text_username = new Text(authenticationGroup, SWT.BORDER);
-               text_username.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
-               // Create password label
-               Label passwordLabel = new Label(authenticationGroup, SWT.NONE);
-               passwordLabel.setText("Password:");
-
-               // Create password input
-               text_password = new Text(authenticationGroup, SWT.BORDER | SWT.PASSWORD);
-               text_password.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-
-       }
-
-       /**
-        * Initialize text fields
-        */
-       public void init() {
-               removeListeners();
-               if(getDataSource() != null){
-                       text_dataSourceName.setText(getDataSource().getName());
-                       text_databaseName.setText(getDataSource().getDatabase());
-                       text_username.setText(getDataSource().getUsername());
-                       text_password.setText(getDataSource().getPassword());
-               }
-               // add listeners after setting text to avoid the modify event being called
-               // for the initial value
-               addListeners();
-
-               // in the case of cloning we use the same datasource info
-               // except for the name
-               if(mode == CdmDataSourceWizard.Mode.CLONE) {
-                       getDataSource().setName("");
-                       text_dataSourceName.setText("");
-               } else {
-                       name = text_dataSourceName.getText();
-               }
-
-       }
-
-       private void addListeners() {
-               text_dataSourceName.addModifyListener(this);
-               text_databaseName.addModifyListener(this);
-               text_username.addModifyListener(this);
-               text_password.addModifyListener(this);
-       }
-
-       private void removeListeners() {
-               text_dataSourceName.removeModifyListener(this);
-               text_databaseName.removeModifyListener(this);
-               text_username.removeModifyListener(this);
-               text_password.removeModifyListener(this);
-       }
-
-       public void testDbConfiguration(){
-               testDbConfiguration(false);
-       }
-
-       /**
-        * Tries to open a connection to the given dataSource. Generates a message on either
-        * failure or success
-        */
-       public void testDbConfiguration(boolean ignoreSuccess){
-               try{
-                       updateAndCheck();
-                       updateDataSource();
-                       getDataSource().testConnection();
-                       if(!ignoreSuccess) {
-                               MessageDialog.openConfirm(parent.getShell(), "Connection Test successful", "Test successful!");
-                       }
-               } catch(SQLException e){
-                       MessageDialog.openWarning(parent.getShell(), "Connection Test unsuccessful", "Reason: " + e.getMessage()
-                                       + System.getProperty("line.separator")    //we may use System.lineSeparator when migrated to Java 1.7
-                                       + System.getProperty("line.separator")
-                                       + "Please double check the connection fields");
-               } catch (ClassNotFoundException e) {
-                       MessageDialog.openWarning(parent.getShell(), "Connection Test unsuccessful", "Reason: " + e.getMessage()
-                                       + System.getProperty("line.separator")    //we may use System.lineSeparator when migrated to Java 1.7
-                                       + System.getProperty("line.separator")
-                                       + "Please double check the connection fields");
-               }
-       }
-
-       /**
-        * Form implementation for the specific database
-        */
-       public abstract void createDatabaseForm();
-
-       /**
-        * <p>updateLocation</p>
-        */
-       public abstract void updateLocation();
-
-       /**
-        * <p>updateDataSource</p>
-        */
-       public abstract void updateDataSource();
-
-       /**
-        * <p>checkPageComplete</p>
-        */
-       public void checkPageComplete(){
-               boolean complete = false;
-               if(mode == CdmDataSourceWizard.Mode.CREATE) {
-                       complete = database.length() != 0;
-               } else {
-                       complete = name.length() != 0 && database.length() != 0;
-               }
-               this.setPageComplete(complete);
-       }
-
-
-
-       /**
-        * updates the current datasource with form values
-        */
-       public void updateAuthentication(){
-               database = text_databaseName.getText();
-               username = text_username.getText();
-               password = text_password.getText();
-       }
-
-       /** {@inheritDoc} */
-       @Override
-       public IWizardPage getNextPage() {
-               return null;
-       }
-
-       /**
-        * <p>Setter for the field <code>dataSource</code>.</p>
-        *
-        * @param dataSource the dataSource to set
-        */
-       public void setDataSource(ICdmDataSource dataSource) {
-               this.dataSource = dataSource;
-       }
-
-       /**
-        * <p>Getter for the field <code>dataSource</code>.</p>
-        *
-        * @return the dataSource
-        */
-       public ICdmDataSource getUpdatedDataSource() {
-               updateDataSource();
-               return dataSource;
-       }
-
-       protected ICdmDataSource getDataSource() {
-               return dataSource;
-       }
-
-       /**
-        * <p>getDataSourceName</p>
-        *
-        * @return a {@link java.lang.String} object.
-        */
-       public String getDataSourceName() {
-               return name;
-       }
-
-       /** {@inheritDoc} */
-       @Override
-    public void modifyText(ModifyEvent e) {
-
-               name = text_dataSourceName.getText();
-               database = text_databaseName.getText();
-
-               switch(mode) {
-               case EDIT:
-                       if(name.length() == 0){
-                               name = "";
-                               setErrorMessage("DataSource name must not be empty.");
-                               this.setPageComplete(false);
-                               return;
-                       } else if ((!dataSource.getName().equals(name)) && (CdmDataSourceRepository.getDataSource(name) != null)) {
-                               name = "";
-                               setErrorMessage("DataSource with the same name already exists");
-                               this.setPageComplete(false);
-                               return;
-                       }
-                       break;
-               case CLONE:
-                       if(name.length() == 0){
-                               name = "";
-                               setErrorMessage("DataSource name must not be empty.");
-                               this.setPageComplete(false);
-                               return;
-                       } else if (CdmDataSourceRepository.getDataSource(name) != null) {
-                               name = "";
-                               setErrorMessage("DataSource with the same name already exists");
-                               this.setPageComplete(false);
-                               return;
-                       }
-                       break;
-               default:
-                       break;
-               }
-
-               if(database.length() == 0){
-                       setErrorMessage("Database name must not be empty.");
-                       this.setPageComplete(false);
-               } else {
-                       updateAndCheck();
-                       setErrorMessage(null);
-               }
-       }
-
-
-       private void updateAndCheck() {
-               updateLocation();
-               updateAuthentication();
-               checkPageComplete();
-       }
-       /**
-        * <p>modifyTextWithoutTriggeringListeners</p>
-        *
-        * @param text a {@link org.eclipse.swt.widgets.Text} object.
-        * @param listener a {@link org.eclipse.swt.events.ModifyListener} object.
-        * @param string a {@link java.lang.String} object.
-        */
-       protected void modifyTextWithoutTriggeringListeners(Text text, ModifyListener listener, String string){
-               text.removeModifyListener(listener);
-               text.setText(string);
-               text.addModifyListener(listener);
-       }
-}