import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.cdm.database.CdmDataSource;
+import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
import eu.etaxonomy.cdm.database.ICdmDataSource;
/**
public void updateLocation() {
server = text_server.getText();
try{
- port = new Integer(text_port.getText());
+ if(! text_port.getText().equals("")){
+ port = new Integer(text_port.getText());
+ setErrorMessage(null);
+ }
}catch(NumberFormatException e){
- // pass
+ setErrorMessage("Port number contains invalid characters");
}
-
}
/* (non-Javadoc)
password));
}
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
+ */
+ @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.MySQL.getDefaultPort();
+ }
+
+ setPageComplete(complete);
+
+ // check if widgets of the extended class are complete
+ super.checkPageComplete();
+ }
+
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
*/
import org.eclipse.swt.widgets.Text;
import eu.etaxonomy.cdm.database.CdmDataSource;
+import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
import eu.etaxonomy.cdm.database.ICdmDataSource;
/**
public void updateLocation() {
server = text_server.getText();
try{
- port = new Integer(text_port.getText());
+ if(! text_port.getText().equals("")){
+ port = new Integer(text_port.getText());
+ setErrorMessage(null);
+ }
}catch(NumberFormatException e){
-// logger.warn("Error parsing port number", e);
+ setErrorMessage("Port number contains invalid characters");
}
}
username,
password));
}
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
+ */
+ @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.MySQL.getDefaultPort();
+ }
+
+ setPageComplete(complete);
+
+ // check if widgets of the extended class are complete
+ super.checkPageComplete();
+ }
/* (non-Javadoc)
* @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
public class CdmDataSourceWizard extends Wizard {
private CdmDataSourceCredentialsWizardPage dataSourcePage;
- private boolean dataSourcePageComplete = false;
private CdmDataSourceTypeSelectionWizardPage dataSourceSelectionPage;
- private boolean dataSourceSelectionPageComplete = false;
private CdmPersistentDataSource dataSource;
private String dataSourceName;
+ private boolean editMode;
+
/**
* @param b
*/
public CdmDataSourceWizard() {
super();
+ editMode = false;
setForcePreviousAndNextButtons(true);
setWindowTitle("Datasource Dialog");
}
*/
public CdmDataSourceWizard(CdmPersistentDataSource dataSource) {
super();
+ if(dataSource != null){
+ editMode = true;
+ this.dataSource = dataSource;
+ dataSourceName = dataSource.getName();
+ }
setForcePreviousAndNextButtons(true);
setWindowTitle("Datasource Dialog");
- this.dataSource = dataSource;
- dataSourceName = dataSource.getName();
}
@Override
public void addPages() {
- if(dataSource == null){
- dataSourceSelectionPage = new CdmDataSourceTypeSelectionWizardPage(dataSource);
- this.addPage(dataSourceSelectionPage);
- }else{
+ if(editMode){
if(dataSource.getDatabaseType() == DatabaseTypeEnum.H2){
dataSourcePage = new CdmDataSourceH2WizardPage(dataSource);
}else if(dataSource.getDatabaseType() == DatabaseTypeEnum.MySQL){
dataSourcePage = new CdmDataSourceSQLServerWizardPage(dataSource);
}
this.addPage(dataSourcePage);
+ }else{
+ dataSourceSelectionPage = new CdmDataSourceTypeSelectionWizardPage(dataSource);
+ this.addPage(dataSourceSelectionPage);
}
}
@Override
public boolean performFinish() {
- // TODO this is a little bit confusing because we do edit and create in the same wizard.
- // maybe we want to refactor it into separate wizards
- if(dataSourceSelectionPage != null){
- // a new datasource was created
+ if(editMode){
+ ICdmDataSource dataSource = dataSourcePage.getDataSource();
+ CdmDataSourceRepository.getDefault().update(dataSourceName, dataSource);
+
+ return true;
+ }else{
if(dataSourceSelectionPage.getCredentialsWizardPage() != null){
CdmDataSourceCredentialsWizardPage credentialsWizardPage = dataSourceSelectionPage.getCredentialsWizardPage();
CdmDataSourceRepository.getDefault().save(dataSourceSelectionPage.getDataSourceName(), credentialsWizardPage.getDataSource());
+ return true;
}else{
throw new IllegalStateException("Expected a datasource credentials page to exist");
}
- }else if(dataSourcePage != null){
- // existing datasource was edited
- ICdmDataSource dataSource = dataSourcePage.getDataSource();
- CdmDataSourceRepository.getDefault().update(dataSourceName, dataSource);
- }else{
- throw new IllegalStateException("Other pages expected");
}
-
-
-
- return true;
}
/* (non-Javadoc)
*/
@Override
public boolean canFinish() {
- boolean result = super.canFinish();
- result &= dataSourcePageComplete;
- result &= dataSourceSelectionPageComplete;
-
-
- return result;
+ if(editMode){
+ return dataSourcePage.isPageComplete();
+ }else{
+ boolean result = true;
+ result &= dataSourceSelectionPage.isPageComplete();
+ if(dataSourceSelectionPage.getCredentialsWizardPage() != null){
+ result &= dataSourceSelectionPage.getCredentialsWizardPage().isPageComplete();
+ }
+ return result;
+ }
}
}