Project

General

Profile

Download (4.35 KB) Statistics
| Branch: | Tag: | Revision:
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>CdmDataSourceSQLServerWizardPage class.</p>
26
 *
27
 * @author n.hoffmann
28
 * @created 19.05.2009
29
 * @version 1.0
30
 */
31
public class CdmDataSourceSQLServerWizardPage 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 CdmDataSourceSQLServerWizardPage.</p>
42
	 *
43
	 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
44
	 */
45
	public CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource) {
46
		super("SQL Server");
47
		setTitle("SQL Server");
48
		setDescription("Enter credentials for SQL Server 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
		
83
		text_port.addModifyListener(this);
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.NewSqlServer2005Instance(server,
110
//															database,
111
//															port,
112
//															username,
113
//															password,
114
//															nomenclaturalCode));
115
		setDataSource(CdmDataSource.NewSqlServer2005Instance(server,
116
				database,
117
				port,
118
				username,
119
				password));
120
	}
121
	
122
	/* (non-Javadoc)
123
	 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
124
	 */
125
	/** {@inheritDoc} */
126
	@Override
127
	public void checkPageComplete() {
128
		// check if widgets of this component are complete
129
		boolean complete = server.trim().length() != 0;
130
		
131
		// set default port
132
		if(port == 0){
133
			port = DatabaseTypeEnum.SqlServer2005.getDefaultPort();
134
		}
135
		
136
		setPageComplete(complete);
137
		
138
		// check if widgets of the extended class are complete
139
		super.checkPageComplete();
140
	}
141

    
142
	/* (non-Javadoc)
143
	 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
144
	 */
145
	/** {@inheritDoc} */
146
	@Override
147
	public void init() {
148
		if(getDataSource() != null){
149
			modifyTextWithoutTriggeringListeners(text_server, this, getDataSource().getServer());
150
			modifyTextWithoutTriggeringListeners(text_port, this, getDataSource().getPort()+"");			
151
			super.init();
152
		}
153
	}
154
	
155
	
156
}
(5-5/7)