1 package com.quantum.properties;
3 import org.eclipse.swt.SWT;
4 import org.eclipse.swt.events.SelectionAdapter;
5 import org.eclipse.swt.events.SelectionEvent;
6 import org.eclipse.swt.layout.GridData;
7 import org.eclipse.swt.layout.GridLayout;
8 import org.eclipse.swt.widgets.Button;
9 import org.eclipse.swt.widgets.Combo;
10 import org.eclipse.swt.widgets.Composite;
11 import org.eclipse.swt.widgets.Control;
12 import org.eclipse.swt.widgets.Label;
13 import org.eclipse.swt.widgets.TabFolder;
14 import org.eclipse.swt.widgets.TabItem;
15 import org.eclipse.swt.widgets.Text;
16 import org.eclipse.ui.dialogs.PropertyPage;
18 import com.quantum.IQuantumConstants;
19 import com.quantum.adapters.AdapterFactory;
20 import com.quantum.adapters.DatabaseAdapter;
21 import com.quantum.model.Bookmark;
22 import com.quantum.model.BookmarkCollection;
23 import com.quantum.model.BookmarkHolder;
24 import com.quantum.model.JDBCDriver;
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 DatabaseAdapter[] 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 composite.setLayoutData(new GridData(GridData.FILL_BOTH));
48 Label nameLabel = new Label(composite, SWT.NONE);
49 nameLabel.setText("Name:");
51 Label name = new Label(composite, SWT.NONE);
53 Bookmark bookmark = getBookmark();
54 String description = bookmark.getName();
55 name.setText(description);
57 new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING
58 | GridData.VERTICAL_ALIGN_BEGINNING));
60 TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
61 layout = new GridLayout();
62 tabFolder.setLayout(layout);
63 GridData data = new GridData(GridData.FILL_BOTH);
64 data.horizontalSpan = 2;
65 tabFolder.setLayoutData(data);
67 createUserTab(tabFolder);
68 createDriverTab(tabFolder);
69 createOptionsTab(tabFolder);
75 private Bookmark getBookmark() {
77 ((BookmarkHolder) getElement()).getBookmark();
81 private void createDriverTab(TabFolder tabFolder) {
82 TabItem driverTab = new TabItem(tabFolder, SWT.NONE);
83 driverTab.setText("JDBC Driver");
85 Composite composite = new Composite(tabFolder, SWT.NONE);
86 GridLayout layout = new GridLayout();
87 layout.numColumns = 2;
88 composite.setLayout(layout);
89 GridData data = new GridData(GridData.FILL);
90 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
91 data.grabExcessHorizontalSpace = true;
92 composite.setLayoutData(data);
94 Label label = new Label(composite, SWT.NONE);
95 label.setText("Driver Name:");
97 this.driverName = new Text(composite, SWT.BORDER);
98 data = new GridData(GridData.FILL);
99 data.horizontalAlignment = GridData.FILL;
100 data.grabExcessHorizontalSpace = true;
101 this.driverName.setLayoutData(data);
103 label = new Label(composite, SWT.NONE);
104 label.setText("Driver Location:");
106 this.driverPath = new Text(composite, SWT.BORDER);
107 data = new GridData(GridData.FILL);
108 data.horizontalAlignment = GridData.FILL;
109 data.grabExcessHorizontalSpace = true;
110 this.driverPath.setLayoutData(data);
112 label = new Label(composite, SWT.NULL);
113 label.setText("Type:");
114 this.type = new Combo(composite, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
115 String adapterNames[] = new String[adapters.length];
116 for (int i = 0; i < adapters.length; i++) {
117 adapterNames[i] = adapters[i].getDisplayName();
119 this.type.setItems(adapterNames);
121 data = new GridData();
122 data.horizontalAlignment = GridData.FILL;
123 this.type.setLayoutData(data);
125 driverTab.setControl(composite);
128 private void createUserTab(TabFolder tabFolder) {
129 TabItem userTab = new TabItem(tabFolder, SWT.NONE);
130 userTab.setText("Connection");
132 Composite composite = new Composite(tabFolder, SWT.NONE);
133 GridLayout layout = new GridLayout();
134 layout.numColumns = 2;
135 composite.setLayout(layout);
136 GridData data = new GridData(GridData.FILL);
137 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
138 data.grabExcessHorizontalSpace = true;
139 composite.setLayoutData(data);
141 Label useridLabel = new Label(composite, SWT.NONE);
142 useridLabel.setText("Userid:");
144 this.userid = new Text(composite, SWT.BORDER);
145 data = new GridData(GridData.FILL);
146 data.horizontalAlignment = GridData.FILL;
147 data.grabExcessHorizontalSpace = true;
148 data.grabExcessHorizontalSpace = true;
149 this.userid.setLayoutData(data);
151 Label passworLabel = new Label(composite, SWT.NONE);
152 passworLabel.setText("Password:");
154 this.password = new Text(composite, SWT.BORDER);
155 this.password.setEchoChar('*');
156 data = new GridData(GridData.FILL);
157 data.horizontalAlignment = GridData.FILL;
158 data.grabExcessHorizontalSpace = true;
159 this.password.setLayoutData(data);
161 this.prompt = new Button(composite, SWT.CHECK);
162 this.prompt.setText("Prompt for password");
163 data = new GridData(GridData.FILL);
164 data.horizontalSpan = 2;
165 data.horizontalAlignment = GridData.FILL;
166 data.grabExcessHorizontalSpace = true;
167 this.prompt.setLayoutData(data);
169 this.prompt.addSelectionListener(new SelectionAdapter() {
170 public void widgetSelected(SelectionEvent event) {
171 password.setEditable(!((Button) event.getSource()).getSelection());
175 Label label = new Label(composite, SWT.NONE);
176 label.setText("Connection URL:");
178 this.jdbcURL = new Text(composite, SWT.BORDER);
179 data = new GridData(GridData.FILL);
180 data.horizontalAlignment = GridData.FILL;
181 data.grabExcessHorizontalSpace = true;
182 data.grabExcessHorizontalSpace = true;
183 this.jdbcURL.setLayoutData(data);
185 userTab.setControl(composite);
191 private void createOptionsTab(TabFolder tabFolder) {
192 TabItem optionsTab = new TabItem(tabFolder, SWT.NONE);
193 optionsTab.setText("Options");
195 Composite composite = new Composite(tabFolder, SWT.NONE);
196 GridLayout layout = new GridLayout();
197 layout.numColumns = 2;
198 composite.setLayout(layout);
199 GridData data = new GridData(GridData.FILL);
200 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
201 data.grabExcessHorizontalSpace = true;
202 composite.setLayoutData(data);
206 label = new Label(composite, SWT.NULL);
207 label.setText("On connection, Auto-Commit should be:");
208 this.autoCommit = new Combo(composite, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
209 String autoCommitTypes[] = new String[] {
210 IQuantumConstants.autoCommitTrue,
211 IQuantumConstants.autoCommitFalse,
212 IQuantumConstants.autoCommitSaved
214 this.autoCommit.setItems(autoCommitTypes);
216 data = new GridData();
217 data.horizontalAlignment = GridData.FILL;
218 this.autoCommit.setLayoutData(data);
220 optionsTab.setControl(composite);
227 * @see org.eclipse.jface.preference.PreferencePage#performApply()
229 public boolean performOk() {
230 Bookmark bookmark = getBookmark();
231 bookmark.setUsername(this.userid.getText());
232 bookmark.setPromptForPassword(this.prompt.getSelection());
233 if (this.prompt.getSelection()) {
234 bookmark.setPassword("");
236 bookmark.setPassword(this.password.getText());
239 int index = this.type.getSelectionIndex();
240 bookmark.setConnect(this.jdbcURL.getText());
241 JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver(
242 this.driverName.getText(), this.driverPath.getText(), this.adapters[index].getType());
243 bookmark.setJDBCDriver(jdbcDriver);
244 if (this.autoCommit.getSelectionIndex() >= 0)
245 bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex()));
246 return super.performOk();
249 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
251 protected void performDefaults() {
252 super.performDefaults();
253 Bookmark bookmark = getBookmark();
255 this.prompt.setSelection(bookmark.getPromptForPassword());
256 this.password.setEditable(!bookmark.getPromptForPassword());
257 String password = bookmark.getPassword();
258 this.password.setText(password == null ? "" : password);
259 this.userid.setText(bookmark.getUsername());
262 boolean done = false;
264 length = (adapters == null) ? 0 : adapters.length;
267 if (bookmark.getJDBCDriver().getType() != null &&
268 bookmark.getJDBCDriver().getType().equals(adapters[i].getType())) {
273 if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitTrue))
274 this.autoCommit.select(0);
275 else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitFalse))
276 this.autoCommit.select(1);
277 else if (bookmark.getAutoCommitPreference().equals(IQuantumConstants.autoCommitSaved))
278 this.autoCommit.select(2);
280 this.driverName.setText(bookmark.getJDBCDriver().getClassName());
281 this.jdbcURL.setText(bookmark.getConnect());
282 this.driverPath.setText(bookmark.getJDBCDriver().getJarFileName());