1 package eu
.etaxonomy
.taxeditor
.datasource
;
3 import org
.apache
.log4j
.Logger
;
4 import org
.eclipse
.jface
.dialogs
.Dialog
;
5 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
6 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
7 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
8 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
9 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
10 import org
.eclipse
.jface
.viewers
.LabelProvider
;
11 import org
.eclipse
.jface
.viewers
.ListViewer
;
12 import org
.eclipse
.swt
.SWT
;
13 import org
.eclipse
.swt
.custom
.CCombo
;
14 import org
.eclipse
.swt
.graphics
.Point
;
15 import org
.eclipse
.swt
.layout
.GridData
;
16 import org
.eclipse
.swt
.layout
.GridLayout
;
17 import org
.eclipse
.swt
.widgets
.Button
;
18 import org
.eclipse
.swt
.widgets
.Composite
;
19 import org
.eclipse
.swt
.widgets
.Control
;
20 import org
.eclipse
.swt
.widgets
.Group
;
21 import org
.eclipse
.swt
.widgets
.Label
;
22 import org
.eclipse
.swt
.widgets
.List
;
23 import org
.eclipse
.swt
.widgets
.Shell
;
24 import org
.eclipse
.swt
.widgets
.Text
;
26 import eu
.etaxonomy
.cdm
.database
.CdmDataSource
;
27 import eu
.etaxonomy
.cdm
.database
.DatabaseTypeEnum
;
28 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
29 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
31 public class CdmDataSourceDialog
extends Dialog
{
40 private static final Logger logger
= Logger
41 .getLogger(CdmDataSourceDialog
.class);
42 private CCombo datasourceTypesCombo
;
43 private Composite composite
;
44 private Composite container
;
50 public CdmDataSourceDialog(Shell parentShell
) {
55 * Create contents of the dialog
59 protected Control
createDialogArea(Composite parent
) {
60 container
= (Composite
) super.createDialogArea(parent
);
61 final GridLayout gridLayout
= new GridLayout();
62 gridLayout
.numColumns
= 2;
63 container
.setLayout(gridLayout
);
65 final ListViewer listViewer
= new ListViewer(container
, SWT
.BORDER
);
66 list
= listViewer
.getList();
67 final GridData gd_list
= new GridData(SWT
.LEFT
, SWT
.FILL
, false, true);
68 gd_list
.widthHint
= 162;
69 list
.setLayoutData(gd_list
);
71 listViewer
.setContentProvider(new ArrayContentProvider());
72 listViewer
.setLabelProvider(new LabelProvider() {
74 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
76 public String
getText(Object element
) {
77 if (element
instanceof ICdmDataSource
) {
78 return ((ICdmDataSource
) element
).getName();
80 return super.getText(element
);
83 // list.addListener(SWT. .PaintItem, new Listener() {
85 // public void handleEvent(Event event) {
86 // Object data = event.item.getData();
87 // if (!(data instanceof ICdmDataSource)) {
88 // Font italics = TaxEditorPlugin.getDefault().getFont
89 // (ITaxEditorConstants.MENU_ITEM_ITALICS_FONT);
90 // ((Control) event.item).setFont(italics);
95 java
.util
.List
<ICdmDataSource
> dataSources
=
96 TaxEditorPlugin
.getDefault().getDataSources();
98 listViewer
.setInput(dataSources
);
99 listViewer
.add("<< Add data source >>");
101 listViewer
.addDoubleClickListener(new IDoubleClickListener() {
103 public void doubleClick(DoubleClickEvent event
) {
105 ((IStructuredSelection
) event
.getSelection()).
107 if (selection
instanceof ICdmDataSource
) {
108 createExistingDatasource((ICdmDataSource
) selection
);
110 // newDataSource(CdmDataSource.);
120 private void populateComboBoxItems() {
121 // TODO: replace w cdmApp.getDatabaseService().getDatabaseEnum();
122 for (DatabaseTypeEnum type
: DatabaseTypeEnum
.getAllTypes()) {
123 datasourceTypesCombo
.add(type
.getName());
128 * Create contents of the button bar
132 protected void createButtonsForButtonBar(Composite parent
) {
133 createButton(parent
, IDialogConstants
.OK_ID
, IDialogConstants
.OK_LABEL
,
135 createButton(parent
, IDialogConstants
.CANCEL_ID
,
136 IDialogConstants
.CANCEL_LABEL
, false);
140 * Return the initial size of the dialog
143 protected Point
getInitialSize() {
144 return new Point(500, 375);
147 private void createExistingDatasource(ICdmDataSource dataSource
) {
148 composite
= new Composite(container
, SWT
.NONE
);
149 final GridData gd_composite
= new GridData(SWT
.FILL
, SWT
.TOP
, true, true);
150 composite
.setLayoutData(gd_composite
);
151 final GridLayout gridLayout_1
= new GridLayout();
152 gridLayout_1
.numColumns
= 2;
153 composite
.setLayout(gridLayout_1
);
155 final Label datasourceNameLabel
= new Label(composite
, SWT
.NONE
);
156 datasourceNameLabel
.setText("Datasource Name:");
158 text
= new Text(composite
, SWT
.BORDER
);
159 text
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
161 final Label databaseTypeLabel
= new Label(composite
, SWT
.NONE
);
162 databaseTypeLabel
.setText("Database Type:");
164 datasourceTypesCombo
= new CCombo(composite
, SWT
.BORDER
);
165 final GridData gd_list_1
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false);
166 datasourceTypesCombo
.setLayoutData(gd_list_1
);
167 populateComboBoxItems();
169 // BeanDefinition bean = dataSource.getDatasourceBean();
171 // Redraw dialog container
175 private void createMySqlForm(ICdmDataSource dataSource
) {
176 final Group authenticationGroup
= new Group(composite
, SWT
.NONE
);
177 authenticationGroup
.setText("Authentication");
178 authenticationGroup
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 2, 1));
179 final GridLayout gridLayout_2
= new GridLayout();
180 gridLayout_2
.numColumns
= 2;
181 authenticationGroup
.setLayout(gridLayout_2
);
183 final Label loginNameLabel
= new Label(authenticationGroup
, SWT
.NONE
);
184 loginNameLabel
.setText("Login Name:");
186 text_3
= new Text(authenticationGroup
, SWT
.BORDER
);
187 text_3
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
189 final Label passwordLabel
= new Label(authenticationGroup
, SWT
.NONE
);
190 passwordLabel
.setText("Password:");
192 text_2
= new Text(authenticationGroup
, SWT
.BORDER
);
193 text_2
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
195 final Label savePasswordLabel
= new Label(authenticationGroup
, SWT
.NONE
);
196 savePasswordLabel
.setText("Save password:");
198 final Button button
= new Button(authenticationGroup
, SWT
.CHECK
);
200 final Group locationGroup
= new Group(composite
, SWT
.NONE
);
201 locationGroup
.setText("Location");
202 final GridData gd_locationGroup
= new GridData(SWT
.FILL
, SWT
.CENTER
, false, false, 2, 1);
203 locationGroup
.setLayoutData(gd_locationGroup
);
204 final GridLayout gridLayout_3
= new GridLayout();
205 gridLayout_3
.numColumns
= 2;
206 locationGroup
.setLayout(gridLayout_3
);
208 final Label hostLabel
= new Label(locationGroup
, SWT
.NONE
);
209 hostLabel
.setText("Host:");
211 text_4
= new Text(locationGroup
, SWT
.BORDER
);
212 text_4
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
214 final Label portLabel
= new Label(locationGroup
, SWT
.NONE
);
215 portLabel
.setText("Port <3306>:");
217 text_5
= new Text(locationGroup
, SWT
.BORDER
);
218 text_5
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
220 final Label databaseLabel
= new Label(locationGroup
, SWT
.NONE
);
221 databaseLabel
.setText("Database:");
223 text_6
= new Text(locationGroup
, SWT
.BORDER
);
224 text_6
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
225 new Label(composite
, SWT
.NONE
);
227 final Button saveButton
= new Button(composite
, SWT
.NONE
);
228 final GridData gd_saveButton
= new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false);
229 gd_saveButton
.widthHint
= 76;
230 saveButton
.setLayoutData(gd_saveButton
);
231 saveButton
.setText("Save");