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.view.bookmark.TreeNode;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.SelectionAdapter;
11 import org.eclipse.swt.events.SelectionEvent;
12 import org.eclipse.swt.layout.GridData;
13 import org.eclipse.swt.layout.GridLayout;
14 import org.eclipse.swt.widgets.Button;
15 import org.eclipse.swt.widgets.Combo;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.swt.widgets.Label;
19 import org.eclipse.swt.widgets.TabFolder;
20 import org.eclipse.swt.widgets.TabItem;
21 import org.eclipse.swt.widgets.Text;
22 import org.eclipse.ui.dialogs.PropertyPage;
24 public class BookmarkPropertyPage extends PropertyPage {
26 private Text password;
28 private Button prompt;
31 private Text driverName;
32 private Text driverPath;
35 private Combo autoCommit;
36 private DriverInfo[] adapters = AdapterFactory.getInstance().getDriverList();
38 protected Control createContents(Composite parent) {
40 Composite composite = new Composite(parent, SWT.NONE);
41 GridLayout layout = new GridLayout();
42 layout.numColumns = 2;
43 composite.setLayout(layout);
44 GridData data = new GridData(GridData.FILL);
45 data.grabExcessHorizontalSpace = true;
46 composite.setLayoutData(data);
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 TabFolder tabFolder = new TabFolder(parent, SWT.NONE);
58 layout = new GridLayout();
59 tabFolder.setLayout(layout);
60 data = new GridData(GridData.FILL_BOTH);
61 data.grabExcessHorizontalSpace = true;
62 data.grabExcessVerticalSpace = true;
63 data.verticalAlignment = GridData.FILL;
64 data.horizontalSpan = 2;
65 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
66 tabFolder.setLayoutData(data);
68 createUserTab(tabFolder);
69 createDriverTab(tabFolder);
70 createOptionsTab(tabFolder);
76 private Bookmark getBookmark() {
78 ((TreeNode) getElement()).getBookmark();
82 private void createDriverTab(TabFolder tabFolder) {
83 TabItem driverTab = new TabItem(tabFolder, SWT.NONE);
84 driverTab.setText("JDBC Driver");
86 Composite composite = new Composite(tabFolder, SWT.NONE);
87 GridLayout layout = new GridLayout();
88 layout.numColumns = 2;
89 composite.setLayout(layout);
90 GridData data = new GridData(GridData.FILL);
91 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
92 data.grabExcessHorizontalSpace = true;
93 composite.setLayoutData(data);
95 Label label = new Label(composite, SWT.NONE);
96 label.setText("Connection URL:");
98 this.jdbcURL = new Text(composite, SWT.BORDER);
99 data = new GridData(GridData.FILL);
100 data.horizontalAlignment = GridData.FILL;
101 data.grabExcessHorizontalSpace = true;
102 data.grabExcessHorizontalSpace = true;
103 this.jdbcURL.setLayoutData(data);
105 label = new Label(composite, SWT.NONE);
106 label.setText("Driver Name:");
108 this.driverName = new Text(composite, SWT.BORDER);
109 data = new GridData(GridData.FILL);
110 data.horizontalAlignment = GridData.FILL;
111 data.grabExcessHorizontalSpace = true;
112 this.driverName.setLayoutData(data);
114 label = new Label(composite, SWT.NONE);
115 label.setText("Driver Location:");
117 this.driverPath = new Text(composite, SWT.BORDER);
118 data = new GridData(GridData.FILL);
119 data.horizontalAlignment = GridData.FILL;
120 data.grabExcessHorizontalSpace = true;
121 this.driverPath.setLayoutData(data);
123 label = new Label(composite, SWT.NULL);
124 label.setText("Type:");
125 this.type = new Combo(composite, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
126 String adapterNames[] = new String[adapters.length];
127 for (int i = 0; i < adapters.length; i++) {
128 adapterNames[i] = adapters[i].getDisplayName();
130 this.type.setItems(adapterNames);
132 data = new GridData();
133 data.horizontalAlignment = GridData.FILL;
134 this.type.setLayoutData(data);
136 driverTab.setControl(composite);
139 private void createUserTab(TabFolder tabFolder) {
140 TabItem userTab = new TabItem(tabFolder, SWT.NONE);
141 userTab.setText("User");
143 Composite composite = new Composite(tabFolder, SWT.NONE);
144 GridLayout layout = new GridLayout();
145 layout.numColumns = 2;
146 composite.setLayout(layout);
147 GridData data = new GridData(GridData.FILL);
148 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
149 data.grabExcessHorizontalSpace = true;
150 composite.setLayoutData(data);
152 Label useridLabel = new Label(composite, SWT.NONE);
153 useridLabel.setText("Userid:");
155 this.userid = new Text(composite, SWT.BORDER);
156 data = new GridData(GridData.FILL);
157 data.horizontalAlignment = GridData.FILL;
158 data.grabExcessHorizontalSpace = true;
159 data.grabExcessHorizontalSpace = true;
160 this.userid.setLayoutData(data);
162 Label passworLabel = new Label(composite, SWT.NONE);
163 passworLabel.setText("Password:");
165 this.password = new Text(composite, SWT.BORDER);
166 this.password.setEchoChar('*');
167 data = new GridData(GridData.FILL);
168 data.horizontalAlignment = GridData.FILL;
169 data.grabExcessHorizontalSpace = true;
170 this.password.setLayoutData(data);
172 this.prompt = new Button(composite, SWT.CHECK);
173 this.prompt.setText("Prompt for password");
174 data = new GridData(GridData.FILL);
175 data.horizontalSpan = 2;
176 data.horizontalAlignment = GridData.FILL;
177 data.grabExcessHorizontalSpace = true;
178 this.prompt.setLayoutData(data);
180 this.prompt.addSelectionListener(new SelectionAdapter() {
181 public void widgetSelected(SelectionEvent event) {
182 password.setEditable(!((Button) event.getSource()).getSelection());
186 userTab.setControl(composite);
192 private void createOptionsTab(TabFolder tabFolder) {
193 TabItem optionsTab = new TabItem(tabFolder, SWT.NONE);
194 optionsTab.setText("Options");
196 Composite composite = new Composite(tabFolder, SWT.NONE);
197 GridLayout layout = new GridLayout();
198 layout.numColumns = 2;
199 composite.setLayout(layout);
200 GridData data = new GridData(GridData.FILL);
201 data.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
202 data.grabExcessHorizontalSpace = true;
203 composite.setLayoutData(data);
207 label = new Label(composite, SWT.NULL);
208 label.setText("On connection, Auto-Commit should be:");
209 this.autoCommit = new Combo(composite, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
210 String autoCommitTypes[] = new String[] {
211 IQuantumConstants.autoCommitTrue,
212 IQuantumConstants.autoCommitFalse,
213 IQuantumConstants.autoCommitSaved
215 this.autoCommit.setItems(autoCommitTypes);
217 data = new GridData();
218 data.horizontalAlignment = GridData.FILL;
219 this.autoCommit.setLayoutData(data);
221 optionsTab.setControl(composite);
228 * @see org.eclipse.jface.preference.PreferencePage#performApply()
230 public boolean performOk() {
231 Bookmark bookmark = getBookmark();
232 bookmark.setUsername(this.userid.getText());
233 bookmark.setPromptForPassword(this.prompt.getSelection());
234 if (this.prompt.getSelection()) {
235 bookmark.setPassword("");
237 bookmark.setPassword(this.password.getText());
240 int index = this.type.getSelectionIndex();
241 bookmark.setType(this.adapters[index].getDriverType());
242 bookmark.setConnect(this.jdbcURL.getText());
243 bookmark.setDriver(this.driverName.getText());
244 bookmark.setDriverFile(this.driverPath.getText());
245 if (this.autoCommit.getSelectionIndex() >= 0)
246 bookmark.setAutoCommitPreference(this.autoCommit.getItem(this.autoCommit.getSelectionIndex()));
247 return super.performOk();
250 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
252 protected void performDefaults() {
253 super.performDefaults();
254 Bookmark bookmark = getBookmark();
256 this.prompt.setSelection(bookmark.getPromptForPassword());
257 this.password.setEditable(!bookmark.getPromptForPassword());
258 this.password.setText(bookmark.getPassword());
259 this.userid.setText(bookmark.getUsername());
262 boolean done = false;
264 length = (adapters == null) ? 0 : adapters.length;
267 if (bookmark.getType() != null &&
268 bookmark.getType().equals(adapters[i].getDriverType())) {
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.getDriver());
281 this.jdbcURL.setText(bookmark.getConnect());
282 this.driverPath.setText(bookmark.getDriverFile());