/**
* 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.
*/
* @version 1.0
*/
public class CdmDataSourceTypeSelectionWizardPage extends WizardPage implements ModifyListener{
-
+
public static final DatabaseTypeEnum[] supportedDatabaseTypes = new DatabaseTypeEnum[]{
- DatabaseTypeEnum.MySQL,
- DatabaseTypeEnum.H2,
- DatabaseTypeEnum.PostgreSQL
+ DatabaseTypeEnum.MySQL,
+ DatabaseTypeEnum.H2,
+ DatabaseTypeEnum.PostgreSQL
/*DatabaseTypeEnum.SqlServer2005*/
};
-
-
+
+
private ArrayList<DatabaseTypeEnum> databaseTypes;
-
+
private Text datasourceNameText;
private String dataSourceName;
private Combo databaseTypeCombo;
-
+
private Composite composite;
private Composite editDatasourceComposite;
private boolean dataBaseTypeSelected = false;
private boolean dataSourceNameSet = false;
-
+
private ICdmDataSource dataSource;
private WizardPage nextPage;
private CdmDataSourceCredentialsWizardPage credentialsWizardPage;
-
+
/**
* <p>Constructor for CdmDataSourceTypeSelectionWizardPage.</p>
*
*/
public CdmDataSourceTypeSelectionWizardPage(ICdmDataSource dataSource) {
super("DataSourceWizardPage");
-
+
this.dataSource = dataSource;
-
+
String pageName = dataSource == null ? "Create New Datasource" : "Edit Existing Datasource";
-
+
setTitle(pageName);
}
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
/** {@inheritDoc} */
- public void createControl(Composite parent) {
+ @Override
+ public void createControl(Composite parent) {
setPageComplete(false);
-
- // Create top-level composite
+
+ // Create top-level composite
composite = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
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:");
datasourceNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
datasourceNameText.addModifyListener(this);
- // Create label and dropdown for database type
+ // Create label and dropdown for database type
Label databaseTypeLabel = new Label(editDatasourceComposite, SWT.NONE);
databaseTypeLabel.setText("Database Type:");
databaseTypeCombo = new Combo(editDatasourceComposite, SWT.BORDER | SWT.READ_ONLY);
GridData comboLayout = new GridData(SWT.FILL, SWT.CENTER, false, false);
databaseTypeCombo.setLayoutData(comboLayout);
- populateComboBoxItems();
-
+ populateComboBoxItems();
+
// Create listener to display database type-specific config options
databaseTypeCombo.addSelectionListener(new SelectionAdapter() {
- public void widgetSelected(SelectionEvent e) {
-
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+
// Get database type at the selected index
DatabaseTypeEnum type = databaseTypes.get(databaseTypeCombo.getSelectionIndex());
-
+
addDatabasePage(type);
setDataBaseTypeSelected(true);
checkPageComplete();
}
});
-
+
// make the composite the wizard pages control
setControl(composite);
}
-
+
private void populateComboBoxItems() {
-
+
// Init DB types
if (databaseTypes == null) {
databaseTypes = new ArrayList<DatabaseTypeEnum>();
}
-
+
// Add types to the type drop-down and to the types collection
for (DatabaseTypeEnum type : supportedDatabaseTypes) {
databaseTypeCombo.add(type.getName());
databaseTypes.add(type);
}
}
-
+
/**
* @param type
*/
// add credentials wizard page according to selection
Wizard wizard = (Wizard) getWizard();
credentialsWizardPage = null;
-
-
+
+
if(type == DatabaseTypeEnum.H2){
credentialsWizardPage = new CdmDataSourceH2WizardPage(dataSource,CdmDataSourceWizard.Mode.CREATE);
}
else if(type == DatabaseTypeEnum.PostgreSQL){
credentialsWizardPage = new CdmDataSourcePostgreSQLServerWizardPage(dataSource, CdmDataSourceWizard.Mode.CREATE);
}
-
+
// else if(type == DatabaseTypeEnum.SqlServer2005){
// credentialsWizardPage = new CdmDataSourceSQLServerWizardPage(dataSource);
// }
-
- if(wizard.getPage(credentialsWizardPage.getName()) != null){
+
+ if(credentialsWizardPage != null && wizard.getPage(credentialsWizardPage.getName()) != null){
nextPage = (WizardPage) wizard.getPage(credentialsWizardPage.getName());
}else{
wizard.addPage(credentialsWizardPage);
* @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
*/
/** {@inheritDoc} */
- public void modifyText(ModifyEvent e) {
+ @Override
+ public void modifyText(ModifyEvent e) {
String name = datasourceNameText.getText();
-
+
if(name.length() == 0){
setDataSourceNameSet(false);
setErrorMessage("DataSource name must not be empty.");
public void checkPageComplete() {
boolean complete = isDataBaseTypeSelected();
complete &= isDataSourceNameSet();
-
+
setPageComplete(complete);
}
-
+
/**
* <p>Getter for the field <code>dataSourceName</code>.</p>
*
public NomenclaturalCode getNomenclaturalCode() {
return nomenclaturalCode;
}
-
-
+
+
}