1 package com.quantum.wizards;
3 import com.quantum.Messages;
4 import com.quantum.QuantumPlugin;
5 import com.quantum.adapters.AdapterFactory;
6 import com.quantum.adapters.DriverInfo;
7 import com.quantum.model.Bookmark;
8 import com.quantum.model.BookmarkCollection;
9 import com.quantum.view.bookmark.BookmarkNode;
11 import org.eclipse.jface.dialogs.MessageDialog;
12 import org.eclipse.jface.wizard.Wizard;
13 import org.eclipse.jface.wizard.WizardPage;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.SelectionAdapter;
16 import org.eclipse.swt.events.SelectionEvent;
17 import org.eclipse.swt.events.SelectionListener;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Combo;
22 import org.eclipse.swt.widgets.Composite;
23 import org.eclipse.swt.widgets.FileDialog;
24 import org.eclipse.swt.widgets.Label;
25 import org.eclipse.swt.widgets.Text;
27 public class BookmarkWizard extends Wizard {
28 BookmarkPage mainPage;
30 private Bookmark current;
32 public void init(BookmarkNode selection) {
33 System.out.println("Initing workbench"); //$NON-NLS-1$
34 this.current = selection.getBookmark();
35 setWindowTitle(Messages.getString("BookmarkWizard.NewBookmark")); //$NON-NLS-1$
38 System.out.println("Initing workbench"); //$NON-NLS-1$
40 setWindowTitle(Messages.getString("BookmarkWizard.NewBookmark")); //$NON-NLS-1$
42 public boolean performFinish() {
43 System.out.println("perform finish workbench"); //$NON-NLS-1$
44 String bookmarkName = mainPage.name.getText();
45 if ( BookmarkCollection.getInstance().find(bookmarkName) != null){
46 MessageDialog.openInformation(
47 this.getShell(),Messages.getString("BookmarkWizard.Error"),Messages.getString("BookmarkWizard.bookmarkAlreadyExists")); //$NON-NLS-1$ //$NON-NLS-2$
51 mainPage.performFinish();
54 public void addPages() {
55 System.out.println("adding pages"); //$NON-NLS-1$
56 if (current != null) {
57 mainPage = new BookmarkPage(Messages.getString("BookmarkWizard.Testing"), current); //$NON-NLS-1$
59 mainPage = new BookmarkPage(Messages.getString("BookmarkWizard.Testing")); //$NON-NLS-1$
62 System.out.println("adding pages"); //$NON-NLS-1$
66 class BookmarkPage extends WizardPage {
67 public static final String ADD = "ADD"; //$NON-NLS-1$
80 Bookmark initialData = null;
84 DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
86 * Constructor for BookmarkPage.
89 public BookmarkPage(String pageName) {
94 * Constructor for BookmarkPage.
97 public BookmarkPage(String pageName, Bookmark bookmark) {
99 this.initialData = bookmark;
102 public void createControl(Composite parent) {
103 System.out.println("page create control"); //$NON-NLS-1$
104 dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
105 dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
106 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$
107 Composite container = new Composite(parent, SWT.NULL);
108 GridLayout layout = new GridLayout();
109 container.setLayout(layout);
110 layout.numColumns = 2;
111 layout.verticalSpacing = 9;
114 Label label = new Label(container, SWT.NULL);
115 label.setText(Messages.getString("BookmarkWizard.BookmarkNameAst")); //$NON-NLS-1$
116 name = new Text(container, SWT.BORDER | SWT.SINGLE);
117 GridData fullHorizontal = new GridData();
118 fullHorizontal.horizontalAlignment = GridData.FILL;
119 name.setLayoutData(fullHorizontal);
121 label = new Label(container, SWT.NULL);
122 label.setText(Messages.getString("BookmarkWizard.UsernameAst")); //$NON-NLS-1$
123 username = new Text(container, SWT.BORDER | SWT.SINGLE);
124 fullHorizontal = new GridData();
125 fullHorizontal.horizontalAlignment = GridData.FILL;
126 username.setLayoutData(fullHorizontal);
128 label = new Label(container, SWT.NULL);
129 label.setText(Messages.getString("BookmarkWizard.PasswordAst")); //$NON-NLS-1$
130 password = new Text(container, SWT.BORDER | SWT.SINGLE);
131 password.setEchoChar('*');
132 fullHorizontal = new GridData();
133 fullHorizontal.horizontalAlignment = GridData.FILL;
134 password.setLayoutData(fullHorizontal);
136 this.prompt = new Button(container, SWT.CHECK);
137 this.prompt.setText(Messages.getString("BookmarkWizard.Prompt")); //$NON-NLS-1$
138 fullHorizontal = new GridData();
139 fullHorizontal.horizontalAlignment = GridData.FILL;
140 fullHorizontal.horizontalSpan = 2;
141 this.prompt.setLayoutData(fullHorizontal);
143 label = new Label(container, SWT.NULL);
144 label.setText(Messages.getString("BookmarkWizard.Schema")); //$NON-NLS-1$
145 schema = new Text(container, SWT.BORDER | SWT.SINGLE);
146 fullHorizontal = new GridData();
147 fullHorizontal.horizontalAlignment = GridData.FILL;
148 schema.setLayoutData(fullHorizontal);
150 label = new Label(container, SWT.NULL);
151 label.setText(Messages.getString("BookmarkWizard.ConnectAst")); //$NON-NLS-1$
152 connect = new Text(container, SWT.BORDER | SWT.SINGLE);
153 fullHorizontal = new GridData();
154 fullHorizontal.horizontalAlignment = GridData.FILL;
155 connect.setLayoutData(fullHorizontal);
157 label = new Label(container, SWT.NULL);
158 label.setText(Messages.getString("BookmarkWizard.DriverAst")); //$NON-NLS-1$
159 driver = new Text(container, SWT.BORDER | SWT.SINGLE);
160 fullHorizontal = new GridData();
161 fullHorizontal.horizontalAlignment = GridData.FILL;
162 driver.setLayoutData(fullHorizontal);
164 //label = new Label(container, SWT.NULL);
165 //fullHorizontal = new GridData();
166 //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
167 //fullHorizontal.verticalSpan = 3;
168 //label.setLayoutData(fullHorizontal);
169 //label.setText("(Drivers Found in File)");
170 /*driverList = new List(container, SWT.SINGLE);
171 fullHorizontal = new GridData();
172 fullHorizontal.horizontalAlignment = GridData.FILL;
173 fullHorizontal.verticalAlignment = GridData.FILL;
174 fullHorizontal.verticalSpan = 3;
175 driverList.setLayoutData(fullHorizontal);
176 driverList.addSelectionListener(new SelectionListener() {
177 public void widgetDefaultSelected(SelectionEvent e) {
179 public void widgetSelected(SelectionEvent e) {
180 String[] selection = driverList.getSelection();
181 if (selection != null && selection.length > 0) {
182 driver.setText(selection[0]);
187 label = new Label(container, SWT.NULL);
188 label.setText(Messages.getString("BookmarkWizard.TypeAst")); //$NON-NLS-1$
189 type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
190 String driverNames[] = new String[drivers.length];
191 for (int i = 0; i < drivers.length; i++) {
192 driverNames[i] = drivers[i].getDisplayName();
194 type.setItems(driverNames);
196 fullHorizontal = new GridData();
197 fullHorizontal.horizontalAlignment = GridData.FILL;
198 type.setLayoutData(fullHorizontal);
200 label = new Label(container, SWT.NULL);
201 label.setText(Messages.getString("BookmarkWizard.DriverFilenameAst")); //$NON-NLS-1$
202 driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
203 fullHorizontal = new GridData();
204 fullHorizontal.horizontalAlignment = GridData.FILL;
205 driverFile.setLayoutData(fullHorizontal);
207 Button button = new Button(container, SWT.PUSH);
208 button.setText(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$
210 button.addSelectionListener(new SelectionListener() {
211 public void widgetDefaultSelected(SelectionEvent e) {
213 public void widgetSelected(SelectionEvent e) {
214 // We retrieve the last saved path
215 dialog.setFilterPath(QuantumPlugin.getDefault().getPreferenceStore().getString("quantum.dialogs.bookmarkwizard.path")); //$NON-NLS-1$
216 String filename = dialog.open();
217 if (filename != null) {
218 driverFile.setText(filename);
219 // We save the used path
220 QuantumPlugin.getDefault().getPreferenceStore().setValue("quantum.dialogs.bookmarkwizard.path", filename); //$NON-NLS-1$
226 // if (initialData != null) {
227 // name.setText(initialData.getName());
228 // username.setText(initialData.getUsername());
229 // if (initialData.getPromptForPassword()) {
230 // this.password.setEditable(false);
232 // password.setText(initialData.getPassword());
234 // connect.setText(initialData.getConnect());
235 // driver.setText(initialData.getDriver());
236 // String typeData = initialData.getType();
237 // this.prompt.setSelection(initialData.getPromptForPassword());
238 // int selectedIndex = 0;
239 // for (int i = 0; i < drivers.length; i++) {
240 // if (typeData.equals(drivers[i].getDriverType())) {
241 // selectedIndex = i;
244 // type.select(selectedIndex);
245 // driverFile.setText(initialData.getDriverFile());
246 // updateDriverList();
249 prompt.addSelectionListener(new SelectionAdapter() {
250 public void widgetSelected(SelectionEvent event) {
251 BookmarkPage.this.password.setEditable(!prompt.getSelection());
255 setControl(container);
257 setPageComplete(true);
259 public void updateDriverList() {
261 JarFile file = new JarFile(driverFile.getText());
262 Enumeration enum = file.entries();
263 while (enum.hasMoreElements()) {
264 JarEntry entry = (JarEntry) enum.nextElement();
265 String className = entry.getName().replace('/', '.');
266 if (className.endsWith("Driver.class")) {
267 className = className.substring(0, className.lastIndexOf('.'));
268 //driverList.add(className);
271 } catch (IOException ex) {
272 //driverList.removeAll();
275 public void performFinish() {
276 if (initialData == null) {
277 initialData = new Bookmark();
279 initialData.setName(name.getText());
280 initialData.setUsername(username.getText());
281 initialData.setPromptForPassword(this.prompt.getSelection());
282 if (initialData.getPromptForPassword()) {
283 initialData.setPassword(""); //$NON-NLS-1$
285 initialData.setPassword(password.getText());
287 initialData.addSchema(schema.getText());
288 initialData.setConnect(connect.getText());
289 initialData.setDriver(driver.getText());
290 int selection = type.getSelectionIndex();
291 if (selection >= 0) {
292 initialData.setType(drivers[selection].getDriverType());
294 initialData.setDriverFile(driverFile.getText());
295 BookmarkCollection.getInstance().addBookmark(initialData);