Project

General

Profile

Download (5.3 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
	@Deprecated
46
	public CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource) {
47
		super("SQL Server", dataSource);
48
		setTitle("SQL Server");
49
		setDescription("Enter credentials for SQL Server database");
50
		this.setDataSource(dataSource);
51
	}
52
	
53
	/**
54
	 * <p>Constructor for CdmDataSourceSQLServerWizardPage.</p>
55
	 *
56
	 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
57
	 * param mode a {@link eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard.Mode} enum type.
58
	 */
59
	public CdmDataSourceSQLServerWizardPage(ICdmDataSource dataSource, CdmDataSourceWizard.Mode mode) {
60
		super("SQL Server", dataSource, mode);
61
		setTitle("SQL Server");
62
		setDescription("Enter credentials for SQL Server database");
63
		this.setDataSource(dataSource);
64
	}
65
	
66
	/* (non-Javadoc)
67
	 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#createDatabaseForm()
68
	 */
69
	/** {@inheritDoc} */
70
	@Override
71
	public void createDatabaseForm() {		
72
		// Create group composite for location data 
73
		locationGroup = new Group(composite, SWT.NONE);
74
		locationGroup.setText("Location");
75
		locationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
76
		GridLayout locationLayout = new GridLayout();
77
		locationLayout.numColumns = 2;
78
		locationGroup.setLayout(locationLayout);
79

    
80
		// Create host label
81
		Label serverLabel = new Label(locationGroup, SWT.NONE);
82
		serverLabel.setText("Host:");
83

    
84
		// Create host input
85
		text_server = new Text(locationGroup, SWT.BORDER);
86
		text_server.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
87
		text_server.addModifyListener(this);
88

    
89
		// Create port label
90
		Label portLabel = new Label(locationGroup, SWT.NONE);
91
		portLabel.setText("Port:");
92

    
93
		// Create port input
94
		text_port = new Text(locationGroup, SWT.BORDER);
95
		text_port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
96
		
97
		text_port.addModifyListener(this);
98
	}
99

    
100
	/* (non-Javadoc)
101
	 * @see eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceCredentialsWizardPage#updateLocation()
102
	 */
103
	/** {@inheritDoc} */
104
	@Override
105
	public void updateLocation() {
106
		server = text_server.getText();
107
		try{
108
			if(! text_port.getText().equals("")){
109
				port = new Integer(text_port.getText());
110
				setErrorMessage(null);
111
			}
112
		}catch(NumberFormatException e){
113
			setErrorMessage("Port number contains invalid characters");
114
		}
115
	}
116

    
117
	/* (non-Javadoc)
118
	 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#updateDataSource()
119
	 */
120
	/** {@inheritDoc} */
121
	@Override
122
	public void updateDataSource() {
123

    
124

    
125
		
126
		ICdmDataSource dataSource = getDataSource();
127

    
128
		if(dataSource == null) {
129
			setDataSource(CdmDataSource.NewSqlServer2005Instance(server,
130
					database,
131
					port,
132
					username,
133
					password));
134
		} else {
135
			dataSource.setName(name);
136
			dataSource.setServer(server);
137
			dataSource.setDatabase(database);
138
			dataSource.setPort(port);
139
			dataSource.setUsername(username);
140
			dataSource.setPassword(password);
141
		}
142
	}
143
	
144
	/* (non-Javadoc)
145
	 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#checkPageComplete()
146
	 */
147
	/** {@inheritDoc} */
148
	@Override
149
	public void checkPageComplete() {
150
		// check if widgets of this component are complete
151
		boolean complete = server.trim().length() != 0;
152
		
153
		// set default port
154
		if(port == 0){
155
			port = DatabaseTypeEnum.SqlServer2005.getDefaultPort();
156
		}
157
		
158
		setPageComplete(complete);
159
		
160
		// check if widgets of the extended class are complete
161
		super.checkPageComplete();
162
	}
163

    
164
	/* (non-Javadoc)
165
	 * @see eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceCredentialsWizardPage#init()
166
	 */
167
	/** {@inheritDoc} */
168
	@Override
169
	public void init() {
170
		super.init();
171
		if(getDataSource() != null){
172
			removeListeners();
173
			text_server.setText(getDataSource().getServer());
174
			text_port.setText(String.valueOf(getDataSource().getPort()));			
175
			// add listeners after setting text to avoid the modify event being called
176
			// for the initial value
177
			addListeners();
178
		}
179

    
180
	}
181
	
182
	private void addListeners() {
183
		text_server.addModifyListener(this);
184
		text_port.addModifyListener(this);
185
	}
186
	
187
	private void removeListeners() {
188
		text_server.removeModifyListener(this);
189
		text_port.removeModifyListener(this);
190
	}
191
	
192
	
193
}
(5-5/7)