Project

General

Profile

Download (5.29 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.datasource.wizard;
11

    
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.layout.GridData;
14
import org.eclipse.swt.layout.GridLayout;
15
import org.eclipse.swt.widgets.Group;
16
import org.eclipse.swt.widgets.Label;
17
import org.eclipse.swt.widgets.Text;
18

    
19
import eu.etaxonomy.cdm.database.CdmDataSource;
20
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
21
import eu.etaxonomy.cdm.database.ICdmDataSource;
22

    
23
/**
24
 * <p>CdmDataSourceSQLServerWizardPage class.</p>
25
 *
26
 * @author n.hoffmann
27
 * @created 19.05.2009
28
 * @version 1.0
29
 */
30
public class CdmDataSourceSQLServerWizardPage extends CdmDataSourceCredentialsWizardPage {
31

    
32
	private Text text_port;
33
	private Text text_server;
34

    
35
	private String server;
36

    
37
	private int port;
38

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

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

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

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

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

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

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

    
123

    
124
		
125
		ICdmDataSource dataSource = getDataSource();
126

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

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

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