8ab070c1efdb915ca393abe5e85e40d3452c7e6a
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / datasource / wizard / CdmDataSourceMySQLWizardPage.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.datasource.wizard;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Group;
18 import org.eclipse.swt.widgets.Label;
19 import org.eclipse.swt.widgets.Text;
20
21 import eu.etaxonomy.cdm.database.CdmDataSource;
22 import eu.etaxonomy.cdm.database.ICdmDataSource;
23
24 /**
25 * @author n.hoffmann
26 * @created 19.05.2009
27 * @version 1.0
28 */
29 public class CdmDataSourceMySQLWizardPage extends CdmDataSourceCredentialsWizardPage {
30
31
32 private static final Logger logger = Logger
33 .getLogger(CdmDataSourceMySQLWizardPage.class);
34
35 private Text text_port;
36 private Text text_server;
37
38 private String server;
39
40 private int port;
41
42 /**
43 * @param pageName
44 */
45 protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource) {
46 super("MySQL");
47 setTitle("Enter credentials for MySQL database");
48 this.setDataSource(dataSource);
49 }
50
51 /* (non-Javadoc)
52 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
53 */
54 @Override
55 public void createDatabaseForm() {
56 logger.warn("Creating");
57
58 // Create group composite for location data
59 locationGroup = new Group(composite, SWT.NONE);
60 locationGroup.setText("Location");
61 locationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
62 GridLayout locationLayout = new GridLayout();
63 locationLayout.numColumns = 2;
64 locationGroup.setLayout(locationLayout);
65
66 // Create host label
67 Label serverLabel = new Label(locationGroup, SWT.NONE);
68 serverLabel.setText("Host:");
69
70 // Create host input
71 text_server = new Text(locationGroup, SWT.BORDER);
72 text_server.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
73 text_server.addModifyListener(this);
74
75 // Create port label
76 Label portLabel = new Label(locationGroup, SWT.NONE);
77 portLabel.setText("Port:");
78
79 // Create port input
80 text_port = new Text(locationGroup, SWT.BORDER);
81 text_port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
82 text_port.addModifyListener(this);
83
84 if(getDataSource() != null){
85 text_server.setText(getDataSource().getServer());
86 text_port.setText(getDataSource().getPort()+"");
87 text_databaseName.setText(getDataSource().getDatabase());
88 text_username.setText(getDataSource().getUsername());
89 text_password.setText(getDataSource().getPassword());
90 }
91 }
92
93 /* (non-Javadoc)
94 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#updateLocation()
95 */
96 @Override
97 public void updateLocation() {
98 server = text_server.getText();
99 port = new Integer(text_port.getText());
100
101 }
102
103 /* (non-Javadoc)
104 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
105 */
106 @Override
107 public void updateDataSource() {
108 setDataSource(CdmDataSource.NewMySqlInstance(server,
109 database,
110 port,
111 username,
112 password));
113 }
114
115 /* (non-Javadoc)
116 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
117 */
118 @Override
119 public void init() {
120 if(getDataSource() != null){
121 modifyTextWithoutTriggeringListeners(text_server, this, getDataSource().getServer());
122 modifyTextWithoutTriggeringListeners(text_port, this, getDataSource().getPort()+"");
123 super.init();
124 }
125 }
126 }