1 package com.quantum.properties;
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
6 import com.quantum.IQuantumConstants;
7 import com.quantum.adapters.AdapterFactory;
8 import com.quantum.model.Bookmark;
9 import com.quantum.model.BookmarkHolder;
10 import com.quantum.model.JDBCDriver;
11 import com.quantum.wizards.BookmarkWizard;
12 import com.quantum.wizards.JDBCDriverSelectionWizardPage;
14 import org.eclipse.jface.wizard.Wizard;
15 import org.eclipse.jface.wizard.WizardDialog;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.SelectionAdapter;
18 import org.eclipse.swt.events.SelectionEvent;
19 import org.eclipse.swt.events.SelectionListener;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.widgets.Button;
23 import org.eclipse.swt.widgets.Combo;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.TabFolder;
28 import org.eclipse.swt.widgets.TabItem;
29 import org.eclipse.swt.widgets.Text;
30 import org.eclipse.ui.dialogs.PropertyPage;
32 public class BookmarkPropertyPage extends PropertyPage {
34 class ChooseDriverWizard extends Wizard {
36 private JDBCDriver selection;
37 private JDBCDriverSelectionWizardPage page;
38 private PropertyChangeListener listener = new PropertyChangeListener() {
39 public void propertyChange(PropertyChangeEvent event) {
40 if ("driver".equals(event.getPropertyName())) {
41 ChooseDriverWizard.this.selection = (JDBCDriver) event.getNewValue();
46 public void addPages() {
47 this.page = new JDBCDriverSelectionWizardPage("page1");
48 this.page.addPropertyChangeListener(this.listener);
52 public void dispose() {
53 this.page.removePropertyChangeListener(this.listener);
56 public boolean performFinish() {
57 BookmarkPropertyPage.this.driver = this.selection;
58 BookmarkPropertyPage.this.setDriverDetails();
65 private Text password;
67 private Button prompt;
70 private Text driverName;
71 private Text driverPath;
72 private Text driverClassName;
73 private Text driverVersion;
76 private Combo autoCommit;
77 private JDBCDriver driver;
79 protected Control createContents(Composite parent) {
81 Composite composite = new Composite(parent, SWT.NONE);
82 GridLayout layout = new GridLayout();
83 layout.numColumns = 2;
84 composite.setLayout(layout);
85 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
87 Label nameLabel = new Label(composite, SWT.NONE);
88 nameLabel.setText("Name:");
90 Label name = new Label(composite, SWT.NONE);
92 Bookmark bookmark = getBookmark();
93 String description = bookmark.getName();
94 name.setText(description);
96 new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING
97 | GridData.VERTICAL_ALIGN_BEGINNING));
99 TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
100 layout = new GridLayout();
101 tabFolder.setLayout(layout);
102 GridData data = new GridData(GridData.FILL_BOTH);
103 data.horizontalSpan = 2;
104 tabFolder.setLayoutData(data);
106 createConnectionTab(tabFolder);
107 createDriverTab(tabFolder);
108 createOptionsTab(tabFolder);
114 private Bookmark getBookmark() {
116 ((BookmarkHolder) getElement()).getBookmark();
120 private void createDriverTab(TabFolder tabFolder) {
121 TabItem driverTab = new TabItem(tabFolder, SWT.NONE);
122 driverTab.setText("JDBC Driver");
124 Composite composite = new Composite(tabFolder, SWT.NONE);
125 GridLayout layout = new GridLayout();
126 layout.numColumns = 2;
127 composite.setLayout(layout);
128 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
130 Label label = new Label(composite, SWT.NONE);
131 label.setText("Driver Name:");
133 this.driverName = new Text(composite, SWT.BORDER);
134 this.driverName.setLayoutData(createFillHorizontalGridData());
135 this.driverName.setEditable(false);
137 label = new Label(composite, SWT.NONE);
138 label.setText("Driver Class Name:");
140 this.driverClassName = new Text(composite, SWT.BORDER);
141 this.driverClassName.setLayoutData(createFillHorizontalGridData());
142 this.driverClassName.setEditable(false);
144 label = new Label(composite, SWT.NONE);
145 label.setText("Driver Version:");
147 this.driverVersion = new Text(composite, SWT.BORDER);
148 this.driverVersion.setLayoutData(createFillHorizontalGridData());
149 this.driverVersion.setEditable(false);
151 label = new Label(composite, SWT.NONE);
152 label.setText("Driver Path:");
154 this.driverPath = new Text(composite, SWT.BORDER);
155 this.driverPath.setLayoutData(createFillHorizontalGridData());
156 this.driverPath.setEditable(false);
158 label = new Label(composite, SWT.NULL);
159 label.setText("Type:");
160 this.type = new Text(composite, SWT.BORDER);
161 this.type.setLayoutData(createFillHorizontalGridData());
162 this.type.setEditable(false);
164 driverTab.setControl(composite);
166 Button button = new Button(composite, SWT.PUSH);
167 button.setText("Change");
168 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END);
169 data.horizontalSpan = 2;
170 button.setLayoutData(data);
171 button.addSelectionListener(new SelectionListener() {
172 public void widgetSelected(SelectionEvent event) {
173 WizardDialog dialog =
174 new WizardDialog(getShell(), new ChooseDriverWizard());
177 public void widgetDefaultSelected(SelectionEvent event) {
182 private GridData createFillHorizontalGridData() {
183 GridData data = new GridData(GridData.FILL_HORIZONTAL);
184 data.widthHint = 200;
188 private void createConnectionTab(TabFolder tabFolder) {
189 TabItem userTab = new TabItem(tabFolder, SWT.NONE);
190 userTab.setText("Connection");
192 Composite composite = new Composite(tabFolder, SWT.NONE);
193 GridLayout layout = new GridLayout();
194 layout.numColumns = 2;
195 composite.setLayout(layout);
196 GridData data = new GridData(GridData.FILL);
197 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
198 data.grabExcessHorizontalSpace = true;
199 composite.setLayoutData(data);
201 Label useridLabel = new Label(composite, SWT.NONE);
202 useridLabel.setText("Userid:");
204 this.userid = new Text(composite, SWT.BORDER);
205 data = new GridData(GridData.FILL);
206 data.horizontalAlignment = GridData.FILL;
207 data.grabExcessHorizontalSpace = true;
208 data.grabExcessHorizontalSpace = true;
209 this.userid.setLayoutData(data);
211 Label passworLabel = new Label(composite, SWT.NONE);
212 passworLabel.setText("Password:");
214 this.password = new Text(composite, SWT.BORDER);
215 this.password.setEchoChar('*');
216 data = new GridData(GridData.FILL);
217 data.horizontalAlignment = GridData.FILL;
218 data.grabExcessHorizontalSpace = true;
219 this.password.setLayoutData(data);
221 this.prompt = new Button(composite, SWT.CHECK);
222 this.prompt.setText("Prompt for password");
223 data = new GridData(GridData.FILL);
224 data.horizontalSpan = 2;
225 data.horizontalAlignment = GridData.FILL;
226 data.grabExcessHorizontalSpace = true;
227 this.prompt.setLayoutData(data);
229 this.prompt.addSelectionListener(new SelectionAdapter() {
230 public void widgetSelected(SelectionEvent event) {
231 password.setEditable(!((Button) event.getSource()).getSelection());
235 Label label = new Label(composite, SWT.NONE);
236 label.setText("Connection URL:");
238 this.jdbcURL = new Text(composite, SWT.BORDER);
239 data = new GridData(GridData.FILL);
240 data.horizontalAlignment = GridData.FILL;
241 data.grabExcessHorizontalSpace = true;
242 data.grabExcessHorizontalSpace = true;
243 this.jdbcURL.setLayoutData(data);
245 userTab.setControl(composite);
251 private void createOptionsTab(TabFolder tabFolder) {
252 TabItem optionsTab = new TabItem(tabFolder, SWT.NONE);
253 optionsTab.setText("Options");
255 Composite composite = new Composite(tabFolder, SWT.NONE);
256 GridLayout layout = new GridLayout();
257 layout.numColumns = 2;
258 composite.setLayout(layout);
259 GridData data = new GridData(GridData.FILL);
260 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
261 data.grabExcessHorizontalSpace = true;
262 composite.setLayoutData(data);
266 label = new Label(composite, SWT.NULL);
267 label.setText("On connection, Auto-Commit should be:");
268 this.autoCommit = new Combo(composite, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
269 String autoCommitTypes[] = new String[] {
270 IQuantumConstants.autoCommitTrue,
271 IQuantumConstants.autoCommitFalse,
272 IQuantumConstants.autoCommitSaved
274 this.autoCommit.setItems(autoCommitTypes);
276 data = new GridData();
277 data.horizontalAlignment = GridData.FILL;
278 this.autoCommit.setLayoutData(data);
280 optionsTab.setControl(composite);
286 * @see org.eclipse.jface.preference.PreferencePage#performApply()
288 public boolean performOk() {
289 Bookmark bookmark = getBookmark();
290 bookmark.setUsername(this.userid.getText());
291 bookmark.setPromptForPassword(this.prompt.getSelection());
292 if (this.prompt.getSelection()) {
293 bookmark.setPassword("");
295 bookmark.setPassword(this.password.getText());
297 bookmark.setConnect(this.jdbcURL.getText());
299 bookmark.setJDBCDriver(this.driver);
300 if (this.autoCommit.getSelectionIndex() >= 0)
301 bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex()));
302 return super.performOk();
305 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
307 protected void performDefaults() {
308 super.performDefaults();
309 Bookmark bookmark = getBookmark();
311 this.prompt.setSelection(bookmark.getPromptForPassword());
312 this.password.setEditable(!bookmark.getPromptForPassword());
313 String password = bookmark.getPassword();
314 this.password.setText(password == null ? "" : password);
315 this.userid.setText(bookmark.getUsername());
316 this.jdbcURL.setText(bookmark.getConnect());
318 this.driver = bookmark.getJDBCDriver();
322 if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitTrue))
323 this.autoCommit.select(0);
324 else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitFalse))
325 this.autoCommit.select(1);
326 else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitSaved))
327 this.autoCommit.select(2);
334 private void setDriverDetails() {
335 this.driverName.setText(this.driver.getName());
336 this.driverClassName.setText(this.driver.getClassName());
337 String path = this.driver.getJarFilePath();
338 this.driverPath.setText(path == null ? "" : path);
339 String version = this.driver.getVersion();
340 this.driverVersion.setText(version == null ? "" : version);
341 this.type.setText(AdapterFactory.getInstance().getAdapter(this.driver.getType()).getDisplayName());