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 org
.eclipse
.jface
.wizard
.WizardPage
;
14 import org
.eclipse
.swt
.SWT
;
15 import org
.eclipse
.swt
.events
.KeyEvent
;
16 import org
.eclipse
.swt
.events
.KeyListener
;
17 import org
.eclipse
.swt
.events
.MouseAdapter
;
18 import org
.eclipse
.swt
.events
.MouseEvent
;
19 import org
.eclipse
.swt
.layout
.GridData
;
20 import org
.eclipse
.swt
.layout
.GridLayout
;
21 import org
.eclipse
.swt
.widgets
.Button
;
22 import org
.eclipse
.swt
.widgets
.Composite
;
23 import org
.eclipse
.swt
.widgets
.Group
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.eclipse
.swt
.widgets
.Text
;
27 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
35 public abstract class CdmDataSourceCredentialsWizardPage
extends WizardPage
implements KeyListener
{
37 protected ICdmDataSource dataSource
;
40 protected Text passwordText
;
41 protected Text databaseNameText
;
42 protected Text usernameText
;
44 protected Group authenticationGroup
;
45 protected Group locationGroup
;
47 protected Composite composite
;
49 protected Composite parent
;
54 protected CdmDataSourceCredentialsWizardPage(String pageName
) {
59 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
61 public void createControl(Composite parent
) {
64 // Create top-level composite
66 composite
= new Composite(parent
, SWT
.NONE
);
67 composite
.setLayoutData(new GridData(SWT
.FILL
, SWT
.FILL
, true, true, 2, 1));
68 GridLayout formLayout
= new GridLayout();
69 formLayout
.numColumns
= 2;
70 composite
.setLayout(formLayout
);
72 // create a database specific form
75 // create the authentication input fields
76 createAuthenticationForm();
78 // Create composite for buttons
79 Composite buttonComposite
= new Composite(composite
, SWT
.NONE
);
80 buttonComposite
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, true, false));
81 GridLayout buttonLayout
= new GridLayout();
82 buttonLayout
.numColumns
= 2;
83 buttonComposite
.setLayout(buttonLayout
);
85 // Create test connection button
86 Button testButton
= new Button(buttonComposite
, SWT
.NONE
);
87 testButton
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
88 testButton
.setText("Test connection");
90 // Test connection when button is pressed
91 testButton
.addMouseListener(new MouseAdapter() {
92 public void mouseUp(MouseEvent e
) {
93 testDbConfiguration();
97 setControl(composite
);
101 protected void createAuthenticationForm(){
102 // Create group composite for authentication data
103 authenticationGroup
= new Group(composite
, SWT
.NONE
);
104 authenticationGroup
.setText("Authentication");
105 authenticationGroup
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 2, 1));
106 GridLayout authenticationLayout
= new GridLayout();
107 authenticationLayout
.numColumns
= 2;
108 authenticationGroup
.setLayout(authenticationLayout
);
110 // Create database name label
111 Label databaseNameLabel
= new Label(authenticationGroup
, SWT
.NONE
);
112 databaseNameLabel
.setText("Database Name:");
114 // Create database name input
115 databaseNameText
= new Text(authenticationGroup
, SWT
.BORDER
);
116 databaseNameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
117 databaseNameText
.addKeyListener(this);
119 // Create username label
120 Label usernameLabel
= new Label(authenticationGroup
, SWT
.NONE
);
121 usernameLabel
.setText("User Name:");
123 // Create username input
124 usernameText
= new Text(authenticationGroup
, SWT
.BORDER
);
125 usernameText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
126 usernameText
.addKeyListener(this);
128 // Create password label
129 Label passwordLabel
= new Label(authenticationGroup
, SWT
.NONE
);
130 passwordLabel
.setText("Password:");
132 // Create password input
133 passwordText
= new Text(authenticationGroup
, SWT
.BORDER
);
134 passwordText
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
135 passwordText
.addKeyListener(this);
138 if(dataSource
!= null){
139 // initialize text fields
140 databaseNameText
.setText(getWizard().getDatabase());
141 usernameText
.setText(getWizard().getUsername());
142 passwordText
.setText(getWizard().getPassword());
147 * concrete implementation of the test routine for the specific database
149 public abstract void testDbConfiguration();
152 * Form implementation for the specific database
154 public abstract void createDatabaseForm();
156 public abstract void updateLocation();
159 * updates the current datasource with form values
161 public void updateAuthentication(){
162 getWizard().setDatabase(databaseNameText
.getText());
163 getWizard().setUsername(usernameText
.getText());
164 getWizard().setPassword(passwordText
.getText());
167 public CdmDataSourceWizard
getWizard(){
168 return (CdmDataSourceWizard
) super.getWizard();
172 * @see org.eclipse.swt.events.KeyListener#keyReleased(org.eclipse.swt.events.KeyEvent)
174 public void keyReleased(KeyEvent e
) {
176 updateAuthentication();
179 public void keyPressed(KeyEvent e
){}