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
.store
.datasource
.wizard
;
13 import java
.util
.ArrayList
;
15 import org
.eclipse
.jface
.wizard
.Wizard
;
16 import org
.eclipse
.jface
.wizard
.WizardPage
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.events
.KeyEvent
;
19 import org
.eclipse
.swt
.events
.KeyListener
;
20 import org
.eclipse
.swt
.events
.SelectionAdapter
;
21 import org
.eclipse
.swt
.events
.SelectionEvent
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Combo
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Label
;
27 import org
.eclipse
.swt
.widgets
.Text
;
29 import eu
.etaxonomy
.cdm
.database
.DatabaseTypeEnum
;
30 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
37 public class CdmDataSourceWizardPage
extends WizardPage
implements KeyListener
{
40 private ArrayList
<DatabaseTypeEnum
> databaseTypes
;
42 private Text datasourceNameText
;
43 private Combo databaseTypeCombo
;
45 private Composite composite
;
46 private Composite editDatasourceComposite
;
49 private ICdmDataSource dataSource
;
51 protected CdmDataSourceWizardPage(ICdmDataSource dataSource
) {
52 super("DataSourceWizardPage");
54 this.dataSource
= dataSource
;
56 String pageName
= dataSource
== null ?
"Create New Datasource" : "Edit Existing Datasource";
62 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
64 public void createControl(Composite parent
) {
66 // Create top-level composite
67 composite
= new Composite(parent
, SWT
.NONE
);
68 GridLayout gridLayout
= new GridLayout();
69 gridLayout
.numColumns
= 1;
70 composite
.setLayout(gridLayout
);
72 // Create editDatasourceComposite to display a dataSource's name and type
73 editDatasourceComposite
= new Composite(composite
, SWT
.NONE
);
74 GridData datasourceGridData
= new GridData(SWT
.FILL
, SWT
.TOP
, true, true);
75 editDatasourceComposite
.setLayoutData(datasourceGridData
);
76 GridLayout datasourceLayout
= new GridLayout();
77 datasourceLayout
.numColumns
= 2;
78 editDatasourceComposite
.setLayout(datasourceLayout
);
80 // Create label and input for dataSource name
81 Label datasourceNameLabel
= new Label(editDatasourceComposite
, SWT
.NONE
);
82 datasourceNameLabel
.setText("Datasource Name:");
83 datasourceNameText
= new Text(editDatasourceComposite
, SWT
.BORDER
);
84 datasourceNameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
85 datasourceNameText
.addKeyListener(this);
87 // Create label and dropdown for database type
88 Label databaseTypeLabel
= new Label(editDatasourceComposite
, SWT
.NONE
);
89 databaseTypeLabel
.setText("Database Type:");
90 databaseTypeCombo
= new Combo(editDatasourceComposite
, SWT
.BORDER
);
91 GridData comboLayout
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false);
92 databaseTypeCombo
.setLayoutData(comboLayout
);
93 populateComboBoxItems();
95 // Create listener to display database type-specific config options
96 databaseTypeCombo
.addSelectionListener(new SelectionAdapter() {
97 public void widgetSelected(SelectionEvent e
) {
99 // Get database type at the selected index
100 DatabaseTypeEnum type
= databaseTypes
.get(databaseTypeCombo
.getSelectionIndex());
102 ((CdmDataSourceWizard
) getWizard()).setDatabaseType(type
);
105 addDatabasePage(type
);
109 // make the composite the wizard pages control
110 setControl(composite
);
113 private void populateComboBoxItems() {
116 if (databaseTypes
== null) {
117 databaseTypes
= new ArrayList
<DatabaseTypeEnum
>();
120 // Add types to the type drop-down and to the types collection
121 for (DatabaseTypeEnum type
: DatabaseTypeEnum
.getAllTypes()) {
122 // FIXME right now we filter supported types
123 if(type
.equals(DatabaseTypeEnum
.MySQL
)
124 || type
.equals(DatabaseTypeEnum
.H2
)){
125 databaseTypeCombo
.add(type
.getName());
126 databaseTypes
.add(type
);
134 private void addDatabasePage(DatabaseTypeEnum type
) {
135 // add credentials wizard page according to selection
136 Wizard wizard
= (Wizard
) getWizard();
137 WizardPage wizardPage
= null;
138 if(type
== DatabaseTypeEnum
.H2
){
139 wizardPage
= new CdmDataSourceH2WizardPage(dataSource
);
140 }else if(type
== DatabaseTypeEnum
.MySQL
){
141 wizardPage
= new CdmDataSourceMySQLWizardPage(dataSource
);
144 wizard
.addPage(wizardPage
);
145 getContainer().updateButtons();
150 * @see org.eclipse.swt.events.KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
152 public void keyPressed(KeyEvent e
) {}
155 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
157 public void keyReleased(KeyEvent e
) {
158 ((CdmDataSourceWizard
) getWizard()).setDataSourceName(datasourceNameText
.getText());