had to rename the packages to make them compliant with buckminster
[taxeditor.git] / eu.etaxonomy.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.eclipse.swt.SWT;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Group;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Text;
19
20 import eu.etaxonomy.cdm.database.CdmDataSource;
21 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
22 import eu.etaxonomy.cdm.database.ICdmDataSource;
23
24 /**
25 * <p>CdmDataSourceMySQLWizardPage class.</p>
26 *
27 * @author n.hoffmann
28 * @created 19.05.2009
29 * @version 1.0
30 */
31 public class CdmDataSourceMySQLWizardPage extends CdmDataSourceCredentialsWizardPage {
32
33 private Text text_port;
34 private Text text_server;
35
36 private String server;
37
38 private int port;
39
40 /**
41 * <p>Constructor for CdmDataSourceMySQLWizardPage.</p>
42 *
43 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
44 */
45 protected CdmDataSourceMySQLWizardPage(ICdmDataSource dataSource) {
46 super("MySQL");
47 setTitle("MySQL Server");
48 setDescription("Enter credentials for MySQL database");
49 this.setDataSource(dataSource);
50 }
51
52 /* (non-Javadoc)
53 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
54 */
55 /** {@inheritDoc} */
56 @Override
57 public void createDatabaseForm() {
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 }
85
86 /* (non-Javadoc)
87 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#updateLocation()
88 */
89 /** {@inheritDoc} */
90 @Override
91 public void updateLocation() {
92 server = text_server.getText();
93 try{
94 if(! text_port.getText().equals("")){
95 port = new Integer(text_port.getText());
96 setErrorMessage(null);
97 }
98 }catch(NumberFormatException e){
99 setErrorMessage("Port number contains invalid characters");
100 }
101 }
102
103 /* (non-Javadoc)
104 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
105 */
106 /** {@inheritDoc} */
107 @Override
108 public void updateDataSource() {
109 setDataSource(CdmDataSource.NewMySqlInstance(server,
110 database,
111 port,
112 username,
113 password,
114 nomenclaturalCode));
115 }
116
117 /* (non-Javadoc)
118 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
119 */
120 /** {@inheritDoc} */
121 @Override
122 public void checkPageComplete() {
123 // check if widgets of this component are complete
124 boolean complete = server.trim().length() != 0;
125
126 // set default port
127 if(port == 0){
128 port = DatabaseTypeEnum.MySQL.getDefaultPort();
129 }
130
131 setPageComplete(complete);
132
133 // check if widgets of the extended class are complete
134 super.checkPageComplete();
135 }
136
137 /* (non-Javadoc)
138 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
139 */
140 /** {@inheritDoc} */
141 @Override
142 public void init() {
143 if(getDataSource() != null){
144 modifyTextWithoutTriggeringListeners(text_server, this, getDataSource().getServer());
145 modifyTextWithoutTriggeringListeners(text_port, this, getDataSource().getPort()+"");
146 super.init();
147 }
148 }
149 }