1 package com.quantum.wizards;
3 import java.beans.PropertyChangeListener;
4 import java.beans.PropertyChangeSupport;
5 import java.util.Collections;
6 import java.util.HashMap;
7 import java.util.Iterator;
10 import com.quantum.Messages;
11 import com.quantum.adapters.AdapterFactory;
12 import com.quantum.adapters.DatabaseAdapter;
13 import com.quantum.model.JDBCDriver;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Group;
25 public abstract class URLSetupControl extends Composite {
27 private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
28 private String urlPattern;
29 private Map properties = Collections.synchronizedMap(new HashMap());
30 private final JDBCDriver driver;
31 private String connectionURL;
37 public URLSetupControl(Composite parent, JDBCDriver driver) {
38 super(parent, SWT.NONE);
40 GridLayout layout = new GridLayout();
42 this.urlPattern = AdapterFactory.getInstance().getURLPattern(driver.getClassName());
44 setPropertyDefaults();
45 setConnectionURL(URLBuilder.createURL(this.urlPattern, getProperties()));
51 protected void createPart() {
52 Group group = new Group(this, SWT.SHADOW_ETCHED_IN);
53 group.setText(Messages.getString(URLSetupControl.class, "text"));
54 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
62 private void setPropertyDefaults() {
63 DatabaseAdapter adapter =
64 AdapterFactory.getInstance().getAdapter(getDriver().getType());
65 Map properties = (adapter == null) ? new HashMap() : adapter.getDefaultConnectionParameters();
66 for (Iterator i = properties.keySet().iterator(); i.hasNext();) {
67 String key = (String) i.next();
68 putProperty(key, (String) properties.get(key));
73 protected abstract void createPart(Composite parent);
75 private Map getProperties() {
76 return this.properties;
79 protected String getProperty(String name) {
80 String value = (String) this.properties.get(name);
81 return value == null ? "" : value;
84 protected void putProperty(String name, String value) {
85 this.properties.put(name, value);
86 setConnectionURL(URLBuilder.createURL(this.urlPattern, getProperties()));
89 public void addPropertyChangeListener(PropertyChangeListener listener) {
90 this.propertyChangeSupport.addPropertyChangeListener(listener);
92 public void removePropertyChangeListener(PropertyChangeListener listener) {
93 this.propertyChangeSupport.removePropertyChangeListener(listener);
95 protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
96 this.propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
99 protected JDBCDriver getDriver() {
102 public String getConnectionURL() {
103 return this.connectionURL == null ? "" : this.connectionURL;
105 public void setConnectionURL(String connectionURL) {
106 if (connectionURL != null && !connectionURL.equals(this.connectionURL)) {
107 String original = this.connectionURL;
108 this.connectionURL = connectionURL;
109 firePropertyChange("connectionURL", original, connectionURL);