Added "Save All" button which saves all open taxon editors, commits the current trans...
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / datasource / CdmDataSourceDialog.java
1 package eu.etaxonomy.taxeditor.datasource;
2
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;
25
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;
30
31 public class CdmDataSourceDialog extends Dialog {
32 private List list;
33 private List list_1;
34 private Text text_6;
35 private Text text_5;
36 private Text text_4;
37 private Text text_2;
38 private Text text_3;
39 private Text text;
40 private static final Logger logger = Logger
41 .getLogger(CdmDataSourceDialog.class);
42 private CCombo datasourceTypesCombo;
43 private Composite composite;
44 private Composite container;
45
46 /**
47 * Create the dialog
48 * @param parentShell
49 */
50 public CdmDataSourceDialog(Shell parentShell) {
51 super(parentShell);
52 }
53
54 /**
55 * Create contents of the dialog
56 * @param parent
57 */
58 @Override
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);
64
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);
70
71 listViewer.setContentProvider(new ArrayContentProvider());
72 listViewer.setLabelProvider(new LabelProvider() {
73 /* (non-Javadoc)
74 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
75 */
76 public String getText(Object element) {
77 if (element instanceof ICdmDataSource) {
78 return ((ICdmDataSource) element).getName();
79 }
80 return super.getText(element);
81 }
82 });
83 // list.addListener(SWT. .PaintItem, new Listener() {
84 // @Override
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);
91 // }
92 // }
93 // });
94
95 java.util.List<ICdmDataSource> dataSources =
96 TaxEditorPlugin.getDefault().getDataSources();
97
98 listViewer.setInput(dataSources);
99 listViewer.add("<< Add data source >>");
100
101 listViewer.addDoubleClickListener(new IDoubleClickListener() {
102 @Override
103 public void doubleClick(DoubleClickEvent event) {
104 Object selection =
105 ((IStructuredSelection) event.getSelection()).
106 getFirstElement();
107 if (selection instanceof ICdmDataSource) {
108 createExistingDatasource((ICdmDataSource) selection);
109 } else {
110 // newDataSource(CdmDataSource.);
111 }
112 }
113 });
114
115
116 //
117 return container;
118 }
119
120 private void populateComboBoxItems() {
121 // TODO: replace w cdmApp.getDatabaseService().getDatabaseEnum();
122 for (DatabaseTypeEnum type : DatabaseTypeEnum.getAllTypes()) {
123 datasourceTypesCombo.add(type.getName());
124 }
125 }
126
127 /**
128 * Create contents of the button bar
129 * @param parent
130 */
131 @Override
132 protected void createButtonsForButtonBar(Composite parent) {
133 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL,
134 true);
135 createButton(parent, IDialogConstants.CANCEL_ID,
136 IDialogConstants.CANCEL_LABEL, false);
137 }
138
139 /**
140 * Return the initial size of the dialog
141 */
142 @Override
143 protected Point getInitialSize() {
144 return new Point(500, 375);
145 }
146
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);
154
155 final Label datasourceNameLabel = new Label(composite, SWT.NONE);
156 datasourceNameLabel.setText("Datasource Name:");
157
158 text = new Text(composite, SWT.BORDER);
159 text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
160
161 final Label databaseTypeLabel = new Label(composite, SWT.NONE);
162 databaseTypeLabel.setText("Database Type:");
163
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();
168
169 // BeanDefinition bean = dataSource.getDatasourceBean();
170
171 // Redraw dialog container
172 container.layout();
173 }
174
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);
182
183 final Label loginNameLabel = new Label(authenticationGroup, SWT.NONE);
184 loginNameLabel.setText("Login Name:");
185
186 text_3 = new Text(authenticationGroup, SWT.BORDER);
187 text_3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
188
189 final Label passwordLabel = new Label(authenticationGroup, SWT.NONE);
190 passwordLabel.setText("Password:");
191
192 text_2 = new Text(authenticationGroup, SWT.BORDER);
193 text_2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
194
195 final Label savePasswordLabel = new Label(authenticationGroup, SWT.NONE);
196 savePasswordLabel.setText("Save password:");
197
198 final Button button = new Button(authenticationGroup, SWT.CHECK);
199
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);
207
208 final Label hostLabel = new Label(locationGroup, SWT.NONE);
209 hostLabel.setText("Host:");
210
211 text_4 = new Text(locationGroup, SWT.BORDER);
212 text_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
213
214 final Label portLabel = new Label(locationGroup, SWT.NONE);
215 portLabel.setText("Port <3306>:");
216
217 text_5 = new Text(locationGroup, SWT.BORDER);
218 text_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
219
220 final Label databaseLabel = new Label(locationGroup, SWT.NONE);
221 databaseLabel.setText("Database:");
222
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);
226
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");
232 }
233 }