finalizing preferred refactoring
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / datasource / wizard / CdmDataSourceSQLServerWizardPage.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.jface.dialogs.MessageDialog;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Group;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.swt.widgets.Text;
21
22 import eu.etaxonomy.cdm.database.CdmDataSource;
23 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
24 import eu.etaxonomy.cdm.database.ICdmDataSource;
25
26 /**
27 * @author n.hoffmann
28 * @created 19.05.2009
29 * @version 1.0
30 */
31 public class CdmDataSourceSQLServerWizardPage extends CdmDataSourceCredentialsWizardPage {
32
33
34 private static final Logger logger = Logger
35 .getLogger(CdmDataSourceSQLServerWizardPage.class);
36
37 private Text portText;
38 private Text serverText;
39
40 /**
41 * @param pageName
42 */
43 protected CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource) {
44 super("SQL Server");
45 setTitle("Enter credentials for SQL Server database");
46 this.dataSource = dataSource;
47 }
48
49 /* (non-Javadoc)
50 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
51 */
52 @Override
53 public void createDatabaseForm() {
54 logger.warn("Creating");
55
56 // Create group composite for location data
57 locationGroup = new Group(composite, SWT.NONE);
58 locationGroup.setText("Location");
59 locationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
60 GridLayout locationLayout = new GridLayout();
61 locationLayout.numColumns = 2;
62 locationGroup.setLayout(locationLayout);
63
64 // Create host label
65 Label serverLabel = new Label(locationGroup, SWT.NONE);
66 serverLabel.setText("Host:");
67
68 // Create host input
69 serverText = new Text(locationGroup, SWT.BORDER);
70 serverText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
71 serverText.addKeyListener(this);
72
73 // Create port label
74 Label portLabel = new Label(locationGroup, SWT.NONE);
75 portLabel.setText("Port:");
76
77 // Create port input
78 portText = new Text(locationGroup, SWT.BORDER);
79 portText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
80
81 portText.addKeyListener(this);
82 }
83
84 /* (non-Javadoc)
85 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#testDbConfiguration()
86 */
87 @Override
88 public void testDbConfiguration() {
89 ICdmDataSource dataSource = CdmDataSource.NewSqlServer2005Instance(
90 getWizard().getServer(),
91 getWizard().getDatabase(),
92 getWizard().getPort(),
93 getWizard().getUsername(),
94 getWizard().getPassword()
95 );
96 try{
97 dataSource.testConnection();
98 MessageDialog.openConfirm(parent.getShell(), "Test successful", "Test successful!");
99 } catch(Exception e){
100 MessageDialog.openWarning(parent.getShell(), "Test unsuccessful", "Test unsuccessful! \n\nSee error.log for details.");
101 throw new RuntimeException(e);
102 }
103 }
104
105 /* (non-Javadoc)
106 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#updateLocation()
107 */
108 @Override
109 public void updateLocation() {
110 getWizard().setServer(serverText.getText());
111 int port = new Integer(portText.getText());
112 getWizard().setPort(port);
113 }
114 }