1 package com.quantum.properties;
3 import com.quantum.IQuantumConstants;
4 import com.quantum.adapters.AdapterFactory;
5 import com.quantum.adapters.DriverInfo;
6 import com.quantum.model.Bookmark;
7 import com.quantum.model.BookmarkCollection;
8 import com.quantum.model.JDBCDriver;
9 import com.quantum.view.bookmark.TreeNode;
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.events.SelectionAdapter;
13 import org.eclipse.swt.events.SelectionEvent;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Combo;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Control;
20 import org.eclipse.swt.widgets.Label;
21 import org.eclipse.swt.widgets.TabFolder;
22 import org.eclipse.swt.widgets.TabItem;
23 import org.eclipse.swt.widgets.Text;
24 import org.eclipse.ui.dialogs.PropertyPage;
26 public class BookmarkPropertyPage extends PropertyPage {
28 private Text password;
30 private Button prompt;
33 private Text driverName;
34 private Text driverPath;
37 private Combo autoCommit;
38 private DriverInfo[] adapters = AdapterFactory.getInstance().getDriverList();
40 protected Control createContents(Composite parent) {
42 Composite composite = new Composite(parent, SWT.NONE);
43 GridLayout layout = new GridLayout();
44 layout.numColumns = 2;
45 composite.setLayout(layout);
46 GridData data = new GridData(GridData.FILL);
47 data.grabExcessHorizontalSpace = true;
48 composite.setLayoutData(data);
50 Label nameLabel = new Label(composite, SWT.NONE);
51 nameLabel.setText("Name:");
53 Label name = new Label(composite, SWT.NONE);
55 Bookmark bookmark = getBookmark();
56 String description = bookmark.getName();
57 name.setText(description);
59 TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
60 layout = new GridLayout();
61 tabFolder.setLayout(layout);
62 data = new GridData(GridData.FILL_BOTH);
63 data.grabExcessHorizontalSpace = true;
64 data.grabExcessVerticalSpace = true;
65 data.verticalAlignment = GridData.FILL;
66 data.horizontalSpan = 2;
67 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
68 tabFolder.setLayoutData(data);
70 createUserTab(tabFolder);
71 createDriverTab(tabFolder);
72 createOptionsTab(tabFolder);
78 private Bookmark getBookmark() {
80 ((TreeNode) getElement()).getBookmark();
84 private void createDriverTab(TabFolder tabFolder) {
85 TabItem driverTab = new TabItem(tabFolder, SWT.NONE);
86 driverTab.setText("JDBC Driver");
88 Composite composite = new Composite(tabFolder, SWT.NONE);
89 GridLayout layout = new GridLayout();
90 layout.numColumns = 2;
91 composite.setLayout(layout);
92 GridData data = new GridData(GridData.FILL);
93 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
94 data.grabExcessHorizontalSpace = true;
95 composite.setLayoutData(data);
97 Label label = new Label(composite, SWT.NONE);
98 label.setText("Connection URL:");
100 this.jdbcURL = new Text(composite, SWT.BORDER);
101 data = new GridData(GridData.FILL);
102 data.horizontalAlignment = GridData.FILL;
103 data.grabExcessHorizontalSpace = true;
104 data.grabExcessHorizontalSpace = true;
105 this.jdbcURL.setLayoutData(data);
107 label = new Label(composite, SWT.NONE);
108 label.setText("Driver Name:");
110 this.driverName = new Text(composite, SWT.BORDER);
111 data = new GridData(GridData.FILL);
112 data.horizontalAlignment = GridData.FILL;
113 data.grabExcessHorizontalSpace = true;
114 this.driverName.setLayoutData(data);
116 label = new Label(composite, SWT.NONE);
117 label.setText("Driver Location:");
119 this.driverPath = new Text(composite, SWT.BORDER);
120 data = new GridData(GridData.FILL);
121 data.horizontalAlignment = GridData.FILL;
122 data.grabExcessHorizontalSpace = true;
123 this.driverPath.setLayoutData(data);
125 label = new Label(composite, SWT.NULL);
126 label.setText("Type:");
127 this.type = new Combo(composite, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
128 String adapterNames[] = new String[adapters.length];
129 for (int i = 0; i < adapters.length; i++) {
130 adapterNames[i] = adapters[i].getDisplayName();
132 this.type.setItems(adapterNames);
134 data = new GridData();
135 data.horizontalAlignment = GridData.FILL;
136 this.type.setLayoutData(data);
138 driverTab.setControl(composite);
141 private void createUserTab(TabFolder tabFolder) {
142 TabItem userTab = new TabItem(tabFolder, SWT.NONE);
143 userTab.setText("User");
145 Composite composite = new Composite(tabFolder, SWT.NONE);
146 GridLayout layout = new GridLayout();
147 layout.numColumns = 2;
148 composite.setLayout(layout);
149 GridData data = new GridData(GridData.FILL);
150 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
151 data.grabExcessHorizontalSpace = true;
152 composite.setLayoutData(data);
154 Label useridLabel = new Label(composite, SWT.NONE);
155 useridLabel.setText("Userid:");
157 this.userid = new Text(composite, SWT.BORDER);
158 data = new GridData(GridData.FILL);
159 data.horizontalAlignment = GridData.FILL;
160 data.grabExcessHorizontalSpace = true;
161 data.grabExcessHorizontalSpace = true;
162 this.userid.setLayoutData(data);
164 Label passworLabel = new Label(composite, SWT.NONE);
165 passworLabel.setText("Password:");
167 this.password = new Text(composite, SWT.BORDER);
168 this.password.setEchoChar('*');
169 data = new GridData(GridData.FILL);
170 data.horizontalAlignment = GridData.FILL;
171 data.grabExcessHorizontalSpace = true;
172 this.password.setLayoutData(data);
174 this.prompt = new Button(composite, SWT.CHECK);
175 this.prompt.setText("Prompt for password");
176 data = new GridData(GridData.FILL);
177 data.horizontalSpan = 2;
178 data.horizontalAlignment = GridData.FILL;
179 data.grabExcessHorizontalSpace = true;
180 this.prompt.setLayoutData(data);
182 this.prompt.addSelectionListener(new SelectionAdapter() {
183 public void widgetSelected(SelectionEvent event) {
184 password.setEditable(!((Button) event.getSource()).getSelection());
188 userTab.setControl(composite);
194 private void createOptionsTab(TabFolder tabFolder) {
195 TabItem optionsTab = new TabItem(tabFolder, SWT.NONE);
196 optionsTab.setText("Options");
198 Composite composite = new Composite(tabFolder, SWT.NONE);
199 GridLayout layout = new GridLayout();
200 layout.numColumns = 2;
201 composite.setLayout(layout);
202 GridData data = new GridData(GridData.FILL);
203 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
204 data.grabExcessHorizontalSpace = true;
205 composite.setLayoutData(data);
209 label = new Label(composite, SWT.NULL);
210 label.setText("On connection, Auto-Commit should be:");
211 this.autoCommit = new Combo(composite, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
212 String autoCommitTypes[] = new String[] {
213 IQuantumConstants.autoCommitTrue,
214 IQuantumConstants.autoCommitFalse,
215 IQuantumConstants.autoCommitSaved
217 this.autoCommit.setItems(autoCommitTypes);
219 data = new GridData();
220 data.horizontalAlignment = GridData.FILL;
221 this.autoCommit.setLayoutData(data);
223 optionsTab.setControl(composite);
230 * @see org.eclipse.jface.preference.PreferencePage#performApply()
232 public boolean performOk() {
233 Bookmark bookmark = getBookmark();
234 bookmark.setUsername(this.userid.getText());
235 bookmark.setPromptForPassword(this.prompt.getSelection());
236 if (this.prompt.getSelection()) {
237 bookmark.setPassword("");
239 bookmark.setPassword(this.password.getText());
242 int index = this.type.getSelectionIndex();
243 bookmark.setType(this.adapters[index].getDriverType());
244 bookmark.setConnect(this.jdbcURL.getText());
245 JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver(
246 this.driverName.getText(), this.driverPath.getText());
247 bookmark.setJDBCDriver(jdbcDriver);
248 if (this.autoCommit.getSelectionIndex() >= 0)
249 bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex()));
250 return super.performOk();
253 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
255 protected void performDefaults() {
256 super.performDefaults();
257 Bookmark bookmark = getBookmark();
259 this.prompt.setSelection(bookmark.getPromptForPassword());
260 this.password.setEditable(!bookmark.getPromptForPassword());
261 this.password.setText(bookmark.getPassword());
262 this.userid.setText(bookmark.getUsername());
265 boolean done = false;
267 length = (adapters == null) ? 0 : adapters.length;
270 if (bookmark.getType() != null &&
271 bookmark.getType().equals(adapters[i].getDriverType())) {
276 if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitTrue))
277 this.autoCommit.select(0);
278 else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitFalse))
279 this.autoCommit.select(1);
280 else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitSaved))
281 this.autoCommit.select(2);
283 this.driverName.setText(bookmark.getJDBCDriver().getClassName());
284 this.jdbcURL.setText(bookmark.getConnect());
285 this.driverPath.setText(bookmark.getJDBCDriver().getJarFileName());