3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.datasource
.wizard
;
13 import java
.util
.ArrayList
;
15 import org
.eclipse
.jface
.wizard
.IWizardPage
;
16 import org
.eclipse
.jface
.wizard
.Wizard
;
17 import org
.eclipse
.jface
.wizard
.WizardPage
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.events
.KeyEvent
;
20 import org
.eclipse
.swt
.events
.KeyListener
;
21 import org
.eclipse
.swt
.events
.SelectionAdapter
;
22 import org
.eclipse
.swt
.events
.SelectionEvent
;
23 import org
.eclipse
.swt
.layout
.GridData
;
24 import org
.eclipse
.swt
.layout
.GridLayout
;
25 import org
.eclipse
.swt
.widgets
.Combo
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Label
;
28 import org
.eclipse
.swt
.widgets
.Text
;
30 import eu
.etaxonomy
.cdm
.database
.DatabaseTypeEnum
;
31 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
38 public class CdmDataSourceWizardPage
extends WizardPage
implements KeyListener
{
41 private ArrayList
<DatabaseTypeEnum
> databaseTypes
;
43 private Text datasourceNameText
;
44 private Combo databaseTypeCombo
;
46 private Composite composite
;
47 private Composite editDatasourceComposite
;
50 private ICdmDataSource dataSource
;
52 private WizardPage nextPage
;
54 protected CdmDataSourceWizardPage(ICdmDataSource dataSource
) {
55 super("DataSourceWizardPage");
57 this.dataSource
= dataSource
;
59 String pageName
= dataSource
== null ?
"Create New Datasource" : "Edit Existing Datasource";
65 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
67 public void createControl(Composite parent
) {
69 // Create top-level composite
70 composite
= new Composite(parent
, SWT
.NONE
);
71 GridLayout gridLayout
= new GridLayout();
72 gridLayout
.numColumns
= 1;
73 composite
.setLayout(gridLayout
);
75 // Create editDatasourceComposite to display a dataSource's name and type
76 editDatasourceComposite
= new Composite(composite
, SWT
.NONE
);
77 GridData datasourceGridData
= new GridData(SWT
.FILL
, SWT
.TOP
, true, true);
78 editDatasourceComposite
.setLayoutData(datasourceGridData
);
79 GridLayout datasourceLayout
= new GridLayout();
80 datasourceLayout
.numColumns
= 2;
81 editDatasourceComposite
.setLayout(datasourceLayout
);
83 // Create label and input for dataSource name
84 Label datasourceNameLabel
= new Label(editDatasourceComposite
, SWT
.NONE
);
85 datasourceNameLabel
.setText("Datasource Name:");
86 datasourceNameText
= new Text(editDatasourceComposite
, SWT
.BORDER
);
87 datasourceNameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
88 datasourceNameText
.addKeyListener(this);
90 // Create label and dropdown for database type
91 Label databaseTypeLabel
= new Label(editDatasourceComposite
, SWT
.NONE
);
92 databaseTypeLabel
.setText("Database Type:");
93 databaseTypeCombo
= new Combo(editDatasourceComposite
, SWT
.BORDER
);
94 GridData comboLayout
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false);
95 databaseTypeCombo
.setLayoutData(comboLayout
);
96 populateComboBoxItems();
98 // Create listener to display database type-specific config options
99 databaseTypeCombo
.addSelectionListener(new SelectionAdapter() {
100 public void widgetSelected(SelectionEvent e
) {
102 // Get database type at the selected index
103 DatabaseTypeEnum type
= databaseTypes
.get(databaseTypeCombo
.getSelectionIndex());
105 ((CdmDataSourceWizard
) getWizard()).setDatabaseType(type
);
108 addDatabasePage(type
);
112 // make the composite the wizard pages control
113 setControl(composite
);
116 private void populateComboBoxItems() {
119 if (databaseTypes
== null) {
120 databaseTypes
= new ArrayList
<DatabaseTypeEnum
>();
123 // Add types to the type drop-down and to the types collection
124 for (DatabaseTypeEnum type
: DatabaseTypeEnum
.getAllTypes()) {
125 // FIXME right now we filter supported types
126 if(type
.equals(DatabaseTypeEnum
.MySQL
)
127 || type
.equals(DatabaseTypeEnum
.H2
)
128 || type
.equals(DatabaseTypeEnum
.SqlServer2005
)){
129 databaseTypeCombo
.add(type
.getName());
130 databaseTypes
.add(type
);
138 private void addDatabasePage(DatabaseTypeEnum type
) {
139 // add credentials wizard page according to selection
140 Wizard wizard
= (Wizard
) getWizard();
141 WizardPage wizardPage
= null;
142 if(type
== DatabaseTypeEnum
.H2
){
143 wizardPage
= new CdmDataSourceH2WizardPage(dataSource
);
144 }else if(type
== DatabaseTypeEnum
.MySQL
){
145 wizardPage
= new CdmDataSourceMySQLWizardPage(dataSource
);
146 }else if(type
== DatabaseTypeEnum
.SqlServer2005
){
147 wizardPage
= new CdmDataSourceSQLServerWizardPage(dataSource
);
150 if(wizard
.getPage(wizardPage
.getName()) != null){
151 nextPage
= (WizardPage
) wizard
.getPage(wizardPage
.getName());
153 wizard
.addPage(wizardPage
);
154 nextPage
= wizardPage
;
157 // nextPage = (WizardPage) wizard.getPage(wizardPage.getName());
159 // wizard.addPage(wizardPage);
160 getContainer().updateButtons();
165 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
167 public void keyPressed(KeyEvent e
) {}
170 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
172 public void keyReleased(KeyEvent e
) {
173 ((CdmDataSourceWizard
) getWizard()).setDataSourceName(datasourceNameText
.getText());
177 * @see org.eclipse.jface.wizard.WizardPage#getNextPage()
180 public IWizardPage
getNextPage() {