1 package com.quantum.wizards;
3 import org.eclipse.jface.dialogs.MessageDialog;
4 import org.eclipse.jface.wizard.Wizard;
5 import org.eclipse.jface.wizard.WizardPage;
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.events.SelectionAdapter;
8 import org.eclipse.swt.events.SelectionEvent;
9 import org.eclipse.swt.events.SelectionListener;
10 import org.eclipse.swt.layout.GridData;
11 import org.eclipse.swt.layout.GridLayout;
12 import org.eclipse.swt.widgets.Button;
13 import org.eclipse.swt.widgets.Combo;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.FileDialog;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Text;
19 import com.quantum.Messages;
20 import com.quantum.QuantumPlugin;
21 import com.quantum.adapters.AdapterFactory;
22 import com.quantum.adapters.DriverInfo;
23 import com.quantum.model.Bookmark;
24 import com.quantum.model.BookmarkCollection;
25 import com.quantum.model.JDBCDriver;
27 public class BookmarkWizard extends Wizard {
28 BookmarkPage mainPage;
31 System.out.println("Initing workbench"); //$NON-NLS-1$
32 setWindowTitle(Messages.getString("BookmarkWizard.NewBookmark")); //$NON-NLS-1$
34 public boolean performFinish() {
35 System.out.println("perform finish workbench"); //$NON-NLS-1$
36 String bookmarkName = mainPage.name.getText();
37 if ( BookmarkCollection.getInstance().find(bookmarkName) != null){
38 MessageDialog.openInformation(
39 this.getShell(),Messages.getString("BookmarkWizard.Error"),Messages.getString("BookmarkWizard.bookmarkAlreadyExists")); //$NON-NLS-1$ //$NON-NLS-2$
43 mainPage.performFinish();
46 public void addPages() {
47 System.out.println("adding pages"); //$NON-NLS-1$
48 // WizardPage page = new NewBookmarkPage1(Messages.getString("BookmarkWizard.Testing")); //$NON-NLS-1$
50 mainPage = new BookmarkPage(Messages.getString("BookmarkWizard.Testing")); //$NON-NLS-1$
52 System.out.println("adding pages"); //$NON-NLS-1$
56 class BookmarkPage extends WizardPage {
57 public static final String ADD = "ADD"; //$NON-NLS-1$
72 DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
74 * Constructor for BookmarkPage.
77 public BookmarkPage(String pageName) {
80 public void createControl(Composite parent) {
81 System.out.println("page create control"); //$NON-NLS-1$
82 dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
83 dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
84 dialog.setFilterNames(new String[]{Messages.getString("BookmarkWizard.JarFiles"),Messages.getString("BookmarkWizard.ZipFiles"), Messages.getString("BookmarkWizard.AllFiles")}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
85 Composite container = new Composite(parent, SWT.NULL);
86 GridLayout layout = new GridLayout();
87 container.setLayout(layout);
88 layout.numColumns = 2;
89 layout.verticalSpacing = 9;
92 Label label = new Label(container, SWT.NULL);
93 label.setText(Messages.getString("BookmarkWizard.BookmarkNameAst")); //$NON-NLS-1$
94 name = new Text(container, SWT.BORDER | SWT.SINGLE);
95 GridData fullHorizontal = new GridData();
96 fullHorizontal.horizontalAlignment = GridData.FILL;
97 name.setLayoutData(fullHorizontal);
99 label = new Label(container, SWT.NULL);
100 label.setText(Messages.getString("BookmarkWizard.UsernameAst")); //$NON-NLS-1$
101 username = new Text(container, SWT.BORDER | SWT.SINGLE);
102 fullHorizontal = new GridData();
103 fullHorizontal.horizontalAlignment = GridData.FILL;
104 username.setLayoutData(fullHorizontal);
106 label = new Label(container, SWT.NULL);
107 label.setText(Messages.getString("BookmarkWizard.PasswordAst")); //$NON-NLS-1$
108 password = new Text(container, SWT.BORDER | SWT.SINGLE);
109 password.setEchoChar('*');
110 fullHorizontal = new GridData();
111 fullHorizontal.horizontalAlignment = GridData.FILL;
112 password.setLayoutData(fullHorizontal);
114 this.prompt = new Button(container, SWT.CHECK);
115 this.prompt.setText(Messages.getString("BookmarkWizard.Prompt")); //$NON-NLS-1$
116 fullHorizontal = new GridData();
117 fullHorizontal.horizontalAlignment = GridData.FILL;
118 fullHorizontal.horizontalSpan = 2;
119 this.prompt.setLayoutData(fullHorizontal);
121 label = new Label(container, SWT.NULL);
122 label.setText(Messages.getString("BookmarkWizard.Schema")); //$NON-NLS-1$
123 schema = new Text(container, SWT.BORDER | SWT.SINGLE);
124 fullHorizontal = new GridData();
125 fullHorizontal.horizontalAlignment = GridData.FILL;
126 schema.setLayoutData(fullHorizontal);
128 label = new Label(container, SWT.NULL);
129 label.setText(Messages.getString("BookmarkWizard.ConnectAst")); //$NON-NLS-1$
130 connect = new Text(container, SWT.BORDER | SWT.SINGLE);
131 fullHorizontal = new GridData();
132 fullHorizontal.horizontalAlignment = GridData.FILL;
133 connect.setLayoutData(fullHorizontal);
135 label = new Label(container, SWT.NULL);
136 label.setText(Messages.getString("BookmarkWizard.DriverAst")); //$NON-NLS-1$
137 driver = new Text(container, SWT.BORDER | SWT.SINGLE);
138 fullHorizontal = new GridData();
139 fullHorizontal.horizontalAlignment = GridData.FILL;
140 driver.setLayoutData(fullHorizontal);
142 label = new Label(container, SWT.NULL);
143 label.setText(Messages.getString("BookmarkWizard.TypeAst")); //$NON-NLS-1$
144 type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
145 String driverNames[] = new String[drivers.length];
146 for (int i = 0; i < drivers.length; i++) {
147 driverNames[i] = drivers[i].getDisplayName();
149 type.setItems(driverNames);
151 fullHorizontal = new GridData();
152 fullHorizontal.horizontalAlignment = GridData.FILL;
153 type.setLayoutData(fullHorizontal);
155 label = new Label(container, SWT.NULL);
156 label.setText(Messages.getString("BookmarkWizard.DriverFilenameAst")); //$NON-NLS-1$
157 driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
158 fullHorizontal = new GridData();
159 fullHorizontal.horizontalAlignment = GridData.FILL;
160 driverFile.setLayoutData(fullHorizontal);
162 Button button = new Button(container, SWT.PUSH);
163 button.setText(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$
165 button.addSelectionListener(new SelectionListener() {
166 public void widgetDefaultSelected(SelectionEvent e) {
168 public void widgetSelected(SelectionEvent e) {
169 // We retrieve the last saved path
170 dialog.setFilterPath(QuantumPlugin.getDefault().getPreferenceStore().getString("quantum.dialogs.bookmarkwizard.path")); //$NON-NLS-1$
171 String filename = dialog.open();
172 if (filename != null) {
173 driverFile.setText(filename);
174 // We save the used path
175 QuantumPlugin.getDefault().getPreferenceStore().setValue("quantum.dialogs.bookmarkwizard.path", filename); //$NON-NLS-1$
181 prompt.addSelectionListener(new SelectionAdapter() {
182 public void widgetSelected(SelectionEvent event) {
183 BookmarkPage.this.password.setEditable(!prompt.getSelection());
187 setControl(container);
189 setPageComplete(true);
191 public void updateDriverList() {
193 JarFile file = new JarFile(driverFile.getText());
194 Enumeration enum = file.entries();
195 while (enum.hasMoreElements()) {
196 JarEntry entry = (JarEntry) enum.nextElement();
197 String className = entry.getName().replace('/', '.');
198 if (className.endsWith("Driver.class")) {
199 className = className.substring(0, className.lastIndexOf('.'));
200 //driverList.add(className);
203 } catch (IOException ex) {
204 //driverList.removeAll();
207 public void performFinish() {
208 Bookmark initialData = new Bookmark();
209 initialData.setName(name.getText());
210 initialData.setUsername(username.getText());
211 initialData.setPromptForPassword(this.prompt.getSelection());
212 if (initialData.getPromptForPassword()) {
213 initialData.setPassword(""); //$NON-NLS-1$
215 initialData.setPassword(password.getText());
217 initialData.addSchema(schema.getText());
218 initialData.setConnect(connect.getText());
219 JDBCDriver jdbcDriver = BookmarkCollection.getInstance().findDriver(
220 driver.getText(), driverFile.getText());
221 initialData.setJDBCDriver(jdbcDriver);
222 int selection = type.getSelectionIndex();
223 if (selection >= 0) {
224 initialData.setType(drivers[selection].getDriverType());
226 BookmarkCollection.getInstance().addBookmark(initialData);