Project

General

Profile

Download (3.63 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * 
3
 */
4
package eu.etaxonomy.taxeditor.datasource.wizard;
5

    
6
import org.eclipse.swt.SWT;
7
import org.eclipse.swt.layout.GridData;
8
import org.eclipse.swt.layout.GridLayout;
9
import org.eclipse.swt.widgets.Group;
10
import org.eclipse.swt.widgets.Label;
11
import org.eclipse.swt.widgets.Text;
12

    
13
import eu.etaxonomy.cdm.database.CdmDataSource;
14
import eu.etaxonomy.cdm.database.ICdmDataSource;
15

    
16
/**
17
 * @author n.hoffmann
18
 */
19
public class CdmDataSourcePostgreSQLServerWizardPage extends
20
		CdmDataSourceCredentialsWizardPage {
21

    
22
	private Text text_port;
23
	private Text text_server;
24

    
25
	private String server;
26

    
27
	private int port;
28
	
29
	@Deprecated
30
	protected CdmDataSourcePostgreSQLServerWizardPage(ICdmDataSource dataSource) {
31
		super("PostgreSQL Server", dataSource);
32
		setTitle("PostgreSQL Server");
33
		setDescription("Enter credentials for PostgreSQL Server database");
34

    
35
	}
36
	
37
	/**
38
	 * <p>Constructor for CdmDataSourcePostgreSQLServerWizardPage.</p>
39
	 *
40
	 * @param dataSource a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
41
	 * @param mode a {@link eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard.Mode} enum type.
42
	 */
43
	protected CdmDataSourcePostgreSQLServerWizardPage(ICdmDataSource dataSource, CdmDataSourceWizard.Mode mode) {
44
		super("PostgreSQL Server", dataSource, mode);
45
		setTitle("PostgreSQL Server");
46
		setDescription("Enter credentials for PostgreSQL Server database");
47

    
48
	}
49

    
50
	@Override
51
	public void createDatabaseForm() {
52
		// Create group composite for location data 
53
		locationGroup = new Group(composite, SWT.NONE);
54
		locationGroup.setText("Location");
55
		locationGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
56
		GridLayout locationLayout = new GridLayout();
57
		locationLayout.numColumns = 2;
58
		locationGroup.setLayout(locationLayout);
59

    
60
		// Create host label
61
		Label serverLabel = new Label(locationGroup, SWT.NONE);
62
		serverLabel.setText("Host:");
63

    
64
		// Create host input
65
		text_server = new Text(locationGroup, SWT.BORDER);
66
		text_server.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
67
		
68

    
69
		// Create port label
70
		Label portLabel = new Label(locationGroup, SWT.NONE);
71
		portLabel.setText("Port:");
72

    
73
		// Create port input
74
		text_port = new Text(locationGroup, SWT.BORDER);
75
		text_port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
76
		
77
		
78
	}
79

    
80
	@Override
81
	public void updateLocation() {
82
		server = text_server.getText();
83
		try{
84
			if(! text_port.getText().equals("")){
85
				port = new Integer(text_port.getText());
86
				setErrorMessage(null);
87
			}
88
		}catch(NumberFormatException e){
89
			setErrorMessage("Port number contains invalid characters");
90
		}
91
	}
92

    
93
	@Override
94
	public void updateDataSource() {
95

    
96
		
97
		ICdmDataSource dataSource = getDataSource();
98

    
99
		if(dataSource == null) {
100
			setDataSource(CdmDataSource.NewPostgreSQLInstance(server,
101
					database,
102
					port,
103
					username,
104
					password));
105
		} else {
106
			dataSource.setName(name);
107
			dataSource.setServer(server);
108
			dataSource.setDatabase(database);
109
			dataSource.setPort(port);
110
			dataSource.setUsername(username);
111
			dataSource.setPassword(password);
112
		}
113
	}
114
	
115
	/** {@inheritDoc} */
116
	@Override
117
	public void init() {
118
		super.init();
119
		if(getDataSource() != null){
120
			removeListeners();
121
			text_server.setText(getDataSource().getServer());
122
			text_port.setText(String.valueOf(getDataSource().getPort()));	
123
			// add listeners after setting text to avoid the modify event being called
124
			// for the initial value
125
			addListeners();			
126
		}
127

    
128
	}
129
	
130
	private void addListeners() {
131
		text_server.addModifyListener(this);
132
		text_port.addModifyListener(this);
133
	}
134
	
135
	private void removeListeners() {
136
		text_server.removeModifyListener(this);
137
		text_port.removeModifyListener(this);
138
	}
139

    
140
}
(4-4/7)