1 package com.quantum.wizards;
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
6 import com.quantum.Messages;
7 import com.quantum.model.JDBCDriver;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.ModifyEvent;
11 import org.eclipse.swt.events.ModifyListener;
12 import org.eclipse.swt.events.SelectionAdapter;
13 import org.eclipse.swt.events.SelectionEvent;
14 import org.eclipse.swt.graphics.Point;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Button;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.swt.widgets.Text;
23 class BookmarkConnectionWizardPage extends PropertyChangeWizardPage {
25 /* use this to paint a more helpful UI for the JDBC URL */
26 private JDBCDriver driver;
27 private String userid;
28 private String password;
29 private String connectionURL;
30 private boolean prompt;
32 private Label jdbcLabel;
34 private URLSetupControl urlSetupControl;
35 private Composite container;
37 private PropertyChangeListener listener = new PropertyChangeListener() {
38 public void propertyChange(PropertyChangeEvent event) {
39 if ("connectionURL".equals(event.getPropertyName())) {
40 BookmarkConnectionWizardPage.this.setConnectionURL((String) event.getNewValue());
41 BookmarkConnectionWizardPage.this.updateButtonState();
47 * Constructor for BookmarkPage.
50 public BookmarkConnectionWizardPage(String pageName) {
52 setTitle(Messages.getString(getClass(), "title"));
53 setDescription(Messages.getString(getClass(), "description"));
55 public void createControl(Composite parent) {
56 setPageComplete(false);
58 Composite container = new Composite(parent, SWT.NULL);
59 GridLayout layout = new GridLayout();
60 container.setLayout(layout);
61 layout.numColumns = 2;
62 layout.verticalSpacing = 9;
64 Label label = new Label(container, SWT.NULL);
65 label.setText(Messages.getString(getClass(), "userid")); //$NON-NLS-1$
66 Text username = new Text(container, SWT.BORDER | SWT.SINGLE);
69 GridData fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
70 username.setLayoutData(fullHorizontal);
71 username.addModifyListener(new ModifyListener() {
72 public void modifyText(ModifyEvent event) {
73 String userid = ((Text) event.getSource()).getText();
79 label = new Label(container, SWT.NULL);
80 label.setText(Messages.getString(getClass(), "password")); //$NON-NLS-1$
81 final Text password = new Text(container, SWT.BORDER | SWT.SINGLE);
82 password.setEchoChar('*');
83 fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
84 password.setLayoutData(fullHorizontal);
85 password.addModifyListener(new ModifyListener() {
86 public void modifyText(ModifyEvent event) {
87 String password = ((Text) event.getSource()).getText();
88 setPassword(password);
93 Button prompt = new Button(container, SWT.CHECK);
94 prompt.setText(Messages.getString(getClass(), "prompt")); //$NON-NLS-1$
95 fullHorizontal = new GridData(GridData.FILL_HORIZONTAL);
96 fullHorizontal.horizontalSpan = 2;
97 prompt.setLayoutData(fullHorizontal);
99 createStandardJDBCWidgets(container);
100 prompt.addSelectionListener(new SelectionAdapter() {
101 public void widgetSelected(SelectionEvent event) {
102 Button prompt = ((Button) event.getSource());
103 password.setEditable(!prompt.getSelection());
104 setPrompt(prompt.getSelection());
109 this.container = container;
110 setControl(container);
116 private void createStandardJDBCWidgets(Composite container) {
117 setConnectionURL("");
119 this.jdbcLabel = new Label(container, SWT.NULL);
120 this.jdbcLabel.setText(Messages.getString(getClass(), "url")); //$NON-NLS-1$
122 this.jdbcUrl = new Text(container, SWT.BORDER | SWT.SINGLE);
123 this.jdbcUrl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
124 this.jdbcUrl.addModifyListener(new ModifyListener() {
125 public void modifyText(ModifyEvent event) {
126 setConnectionURL(((Text) event.getSource()).getText());
134 * @return Returns the driver.
136 public JDBCDriver getDriver() {
140 * @param driver The driver to set.
142 public void setDriver(JDBCDriver driver) {
143 String oldDriverClassName = this.driver == null ? null : this.driver.getClassName();
144 this.driver = driver;
146 if (oldDriverClassName == null
147 || !oldDriverClassName.equals(this.driver.getClassName())) {
148 rebuildJDBCControls(this.driver);
154 private void rebuildJDBCControls(JDBCDriver driver) {
155 Point windowSize = getShell().getSize();
156 Point oldSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
158 if (URLSetupControlFactory.hasControl(driver)) {
159 disposeOfCurrentJDBCControls();
161 this.urlSetupControl = URLSetupControlFactory.create(driver, this.container);
162 GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
163 data.horizontalSpan = 2;
164 this.urlSetupControl.setLayoutData(data);
166 this.urlSetupControl.addPropertyChangeListener(this.listener);
168 setConnectionURL(this.urlSetupControl.getConnectionURL());
171 resizeWindow(windowSize, oldSize);
172 this.container.layout();
174 } else if (this.jdbcLabel == null || this.jdbcUrl == null) {
176 disposeOfCurrentJDBCControls();
177 createStandardJDBCWidgets(this.container);
179 resizeWindow(windowSize, oldSize);
181 this.container.layout();
183 this.container.setVisible(true);
184 this.container.redraw();
191 private void resizeWindow(Point windowSize, Point oldSize) {
192 Point newSize = getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT);
193 if (newSize.y > windowSize.y) {
195 new Point(windowSize.x, windowSize.y + (newSize.y - oldSize.y)));
198 private void disposeOfCurrentJDBCControls() {
199 if (this.jdbcUrl != null) {
200 this.jdbcUrl.dispose();
203 if (this.jdbcLabel != null) {
204 this.jdbcLabel.dispose();
205 this.jdbcLabel = null;
207 if (this.urlSetupControl != null) {
208 this.urlSetupControl.removePropertyChangeListener(this.listener);
209 this.urlSetupControl.dispose();
210 this.urlSetupControl = null;
216 private void updateButtonState() {
217 boolean complete = true;
218 complete &= (this.connectionURL != null
219 && this.connectionURL.trim().length() > 0);
220 complete &= (this.userid != null
221 && this.userid.trim().length() > 0);
222 setPageComplete(complete);
225 * @return Returns the userid.
227 public String getUserid() {
231 * @param userid The userid to set.
233 public void setUserid(String userid) {
234 if (userid != null && !userid.equals(this.userid)) {
235 String original = this.userid;
236 this.userid = userid;
237 firePropertyChange("userid", original, userid);
241 * @return Returns the prompt.
243 public boolean isPrompt() {
247 * @param prompt The prompt to set.
249 public void setPrompt(boolean prompt) {
250 if (this.prompt != prompt) {
251 boolean original = this.prompt;
252 this.prompt = prompt;
253 firePropertyChange("prompt", original, prompt);
257 * @return Returns the connectionURL.
259 public String getConnectionURL() {
260 return this.connectionURL;
263 * @param connectionURL The connectionURL to set.
265 public void setConnectionURL(String connectionURL) {
266 if (connectionURL != null && !connectionURL.equals(this.connectionURL)) {
267 String original = this.connectionURL;
268 this.connectionURL = connectionURL;
269 firePropertyChange("connectionURL", original, connectionURL);
273 * @return Returns the password.
275 public String getPassword() {
276 return this.password;
279 * @param password The password to set.
281 public void setPassword(String password) {
282 if (password != null && !password.equals(this.password)) {
283 String original = this.password;
284 this.password = password;
285 firePropertyChange("password", original, password);