// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* 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.
*/
*/
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 Group nomenclaturalCodeGroup;
protected String database;
protected String username;
protected String password;
-
+
protected NomenclaturalCode nomenclaturalCode;
-
+
CdmDataSourceWizard.Mode mode;
-
+
/**
* <p>Constructor for CdmDataSourceCredentialsWizardPage.</p>
*
protected CdmDataSourceCredentialsWizardPage(String pageName, ICdmDataSource dataSource) {
super(pageName);
this.setPageComplete(false);
- setDataSource(dataSource);
+ setDataSource(dataSource);
mode = CdmDataSourceWizard.Mode.CREATE;
}
-
+
/**
* <p>Constructor for CdmDataSourceCredentialsWizardPage.</p>
*
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));
+ setDataSource(CdmDataSource.NewInstance(dataSource));
} else {
- setDataSource(dataSource);
+ setDataSource(dataSource);
}
}
-
+
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
/** {@inheritDoc} */
- public void createControl(Composite parent) {
+ @Override
+ public void createControl(Composite parent) {
this.parent = parent;
-
- // Create top-level composite
+
+ // 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));
if(getDataSource() == null) {
editDatasourceComposite.setVisible(false);
}
-
+
// create a database specific form
createDatabaseForm();
-
+
// create the authentication input fields
createAuthenticationForm();
-
+
// create nomenclatural code combo
createNomenclaturalCodeForm();
-
+
// 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() {
/* (non-Javadoc)
testDbConfiguration();
}
});
-
+
setControl(composite);
-
- init();
-
+
+ init();
+
}
/**
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() {
+ public void init() {
removeListeners();
- if(getDataSource() != null){
+ if(getDataSource() != null){
text_dataSourceName.setText(getDataSource().getName());
text_databaseName.setText(getDataSource().getDatabase());
text_username.setText(getDataSource().getUsername());
// 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("");
+ getDataSource().setName("");
+ text_dataSourceName.setText("");
} else {
name = text_dataSourceName.getText();
}
-
+
}
-
+
private void addListeners() {
- text_dataSourceName.addModifyListener(this);
+ 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);
private void createNomenclaturalCodeForm() {
nomenclaturalCodeGroup = new Group(composite , SWT.NONE);
nomenclaturalCodeGroup.setLayout(new GridLayout());
-
+
nomenclaturalCode = dataSource != null ? dataSource.getNomenclaturalCode() : PreferencesUtil.getPreferredNomenclaturalCode();
-
+
for (final NomenclaturalCode code : NomenclaturalCodeHelper.getSupportedCodes()) {
Button button = new Button(nomenclaturalCodeGroup, SWT.RADIO);
button.setText(NomenclaturalCodeHelper.getDescription(code));
button.setSelection(nomenclaturalCode.equals(code));
}
button.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
nomenclaturalCode = (NomenclaturalCode) e.widget.getData();
modifyText(null);
}
});
- }
+ }
}
-
+
public void testDbConfiguration(){
testDbConfiguration(false);
}
-
+
/**
* Tries to open a connection to the given dataSource. Generates a message on either
* failure or success
MessageDialog.openConfirm(parent.getShell(), "Connection Test successful", "Test successful!");
}
} catch(SQLException e){
- MessageDialog.openWarning(parent.getShell(), "Connection Test unsuccessful", "Reason: " + e.getMessage()
+ 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");
- throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
- MessageDialog.openWarning(parent.getShell(), "Connection Test unsuccessful", "Reason: " + e.getMessage()
+ 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");
- throw new RuntimeException(e);
- }
+ }
}
-
+
/**
* Form implementation for the specific database
*/
- public abstract void createDatabaseForm();
-
+ public abstract void createDatabaseForm();
+
/**
* <p>updateLocation</p>
*/
public abstract void updateLocation();
-
+
/**
* <p>updateDataSource</p>
*/
public abstract void updateDataSource();
-
+
/**
* <p>checkPageComplete</p>
*/
boolean complete = false;
if(mode == CdmDataSourceWizard.Mode.CREATE) {
complete = database.length() != 0;
- } else {
+ } else {
complete = name.length() != 0 && database.length() != 0;
- }
+ }
this.setPageComplete(complete);
}
-
-
+
+
/**
* updates the current datasource with form values
*/
- public void updateAuthentication(){
+ public void updateAuthentication(){
database = text_databaseName.getText();
username = text_username.getText();
password = text_password.getText();
*
* @param dataSource the dataSource to set
*/
- public void setDataSource(ICdmDataSource dataSource) {
+ public void setDataSource(ICdmDataSource dataSource) {
this.dataSource = dataSource;
}
updateDataSource();
return dataSource;
}
-
- protected ICdmDataSource getDataSource() {
+
+ protected ICdmDataSource getDataSource() {
return dataSource;
}
-
+
/**
* <p>getDataSourceName</p>
*
public String getDataSourceName() {
return name;
}
-
+
/* (non-Javadoc)
* @see org.eclipse.swto.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
/** {@inheritDoc} */
- public void modifyText(ModifyEvent e) {
-
+ @Override
+ public void modifyText(ModifyEvent e) {
+
name = text_dataSourceName.getText();
database = text_databaseName.getText();
switch(mode) {
case EDIT:
- if(name.length() == 0){
+ if(name.length() == 0){
name = "";
setErrorMessage("DataSource name must not be empty.");
this.setPageComplete(false);
}
break;
case CLONE:
- if(name.length() == 0){
+ if(name.length() == 0){
name = "";
setErrorMessage("DataSource name must not be empty.");
this.setPageComplete(false);
default:
break;
}
-
- if(database.length() == 0){
+
+ if(database.length() == 0){
setErrorMessage("Database name must not be empty.");
this.setPageComplete(false);
- } else {
+ } else {
updateAndCheck();
- setErrorMessage(null);
- }
- }
+ setErrorMessage(null);
+ }
+ }
+
-
private void updateAndCheck() {
updateLocation();
updateAuthentication();