1 package net.sourceforge.phpdt.sql.wizards;
3 import org.eclipse.jface.wizard.Wizard;
4 import org.eclipse.jface.wizard.WizardPage;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.events.SelectionEvent;
7 import org.eclipse.swt.events.SelectionListener;
8 import org.eclipse.swt.layout.GridData;
9 import org.eclipse.swt.layout.GridLayout;
10 import org.eclipse.swt.widgets.Button;
11 import org.eclipse.swt.widgets.Combo;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.FileDialog;
14 import org.eclipse.swt.widgets.Label;
15 import org.eclipse.swt.widgets.Text;
17 import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
18 import net.sourceforge.phpdt.sql.adapters.DriverInfo;
19 import net.sourceforge.phpdt.sql.view.BookmarkView;
20 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
22 public class BookmarkWizard extends Wizard {
23 BookmarkPage mainPage;
25 private BookmarkNode current;
27 public void init(BookmarkNode selection) {
28 System.out.println("Initing workbench");
29 this.current = selection;
30 setWindowTitle("New Bookmark");
33 System.out.println("Initing workbench");
35 setWindowTitle("New Bookmark");
37 public boolean performFinish() {
38 System.out.println("perform finish workbench");
39 mainPage.performFinish();
42 public void addPages() {
43 System.out.println("adding pages");
44 if (current != null) {
45 mainPage = new BookmarkPage("Testing...", current);
47 mainPage = new BookmarkPage("Testing...");
50 System.out.println("adding pages");
54 class BookmarkPage extends WizardPage {
55 public static final String ADD = "ADD";
67 BookmarkNode initialData = null;
71 DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
73 * Constructor for BookmarkPage.
76 public BookmarkPage(String pageName) {
81 * Constructor for BookmarkPage.
84 public BookmarkPage(String pageName, BookmarkNode bookmark) {
86 this.initialData = bookmark;
89 public void createControl(Composite parent) {
90 System.out.println("page create control");
91 dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
92 dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"});
93 dialog.setFilterNames(new String[]{"Jar Files (*.jar)","Zip Files (*.zip)", "All Files (*.*)"});
94 Composite container = new Composite(parent, SWT.NULL);
95 GridLayout layout = new GridLayout();
96 container.setLayout(layout);
97 layout.numColumns = 2;
98 layout.verticalSpacing = 9;
101 Label label = new Label(container, SWT.NULL);
102 label.setText("*Bookmark Name");
103 name = new Text(container, SWT.BORDER | SWT.SINGLE);
104 GridData fullHorizontal = new GridData();
105 fullHorizontal.horizontalAlignment = GridData.FILL;
106 name.setLayoutData(fullHorizontal);
108 label = new Label(container, SWT.NULL);
109 label.setText("*Username");
110 username = new Text(container, SWT.BORDER | SWT.SINGLE);
111 fullHorizontal = new GridData();
112 fullHorizontal.horizontalAlignment = GridData.FILL;
113 username.setLayoutData(fullHorizontal);
115 label = new Label(container, SWT.NULL);
116 label.setText("*Password");
117 password = new Text(container, SWT.BORDER | SWT.SINGLE);
118 password.setEchoChar('*');
119 fullHorizontal = new GridData();
120 fullHorizontal.horizontalAlignment = GridData.FILL;
121 password.setLayoutData(fullHorizontal);
123 label = new Label(container, SWT.NULL);
124 label.setText("Schema (optional)");
125 schema = new Text(container, SWT.BORDER | SWT.SINGLE);
126 fullHorizontal = new GridData();
127 fullHorizontal.horizontalAlignment = GridData.FILL;
128 schema.setLayoutData(fullHorizontal);
130 label = new Label(container, SWT.NULL);
131 label.setText("*Connect");
132 connect = new Text(container, SWT.BORDER | SWT.SINGLE);
133 fullHorizontal = new GridData();
134 fullHorizontal.horizontalAlignment = GridData.FILL;
135 connect.setLayoutData(fullHorizontal);
137 label = new Label(container, SWT.NULL);
138 label.setText("*Driver");
139 driver = new Text(container, SWT.BORDER | SWT.SINGLE);
140 fullHorizontal = new GridData();
141 fullHorizontal.horizontalAlignment = GridData.FILL;
142 driver.setLayoutData(fullHorizontal);
144 //label = new Label(container, SWT.NULL);
145 //fullHorizontal = new GridData();
146 //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
147 //fullHorizontal.verticalSpan = 3;
148 //label.setLayoutData(fullHorizontal);
149 //label.setText("(Drivers Found in File)");
150 /*driverList = new List(container, SWT.SINGLE);
151 fullHorizontal = new GridData();
152 fullHorizontal.horizontalAlignment = GridData.FILL;
153 fullHorizontal.verticalAlignment = GridData.FILL;
154 fullHorizontal.verticalSpan = 3;
155 driverList.setLayoutData(fullHorizontal);
156 driverList.addSelectionListener(new SelectionListener() {
157 public void widgetDefaultSelected(SelectionEvent e) {
159 public void widgetSelected(SelectionEvent e) {
160 String[] selection = driverList.getSelection();
161 if (selection != null && selection.length > 0) {
162 driver.setText(selection[0]);
167 label = new Label(container, SWT.NULL);
168 label.setText("*Type");
169 type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
170 String driverNames[] = new String[drivers.length];
171 for (int i = 0; i < drivers.length; i++) {
172 driverNames[i] = drivers[i].getDisplayName();
174 type.setItems(driverNames);
176 fullHorizontal = new GridData();
177 fullHorizontal.horizontalAlignment = GridData.FILL;
178 type.setLayoutData(fullHorizontal);
180 label = new Label(container, SWT.NULL);
181 label.setText("*Driver Filename");
182 driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
183 fullHorizontal = new GridData();
184 fullHorizontal.horizontalAlignment = GridData.FILL;
185 driverFile.setLayoutData(fullHorizontal);
187 Button button = new Button(container, SWT.PUSH);
188 button.setText("Browse...");
190 button.addSelectionListener(new SelectionListener() {
191 public void widgetDefaultSelected(SelectionEvent e) {
193 public void widgetSelected(SelectionEvent e) {
194 String filename = dialog.open();
195 if (filename != null) {
196 driverFile.setText(filename);
200 if (initialData != null) {
201 name.setText(initialData.getName());
202 username.setText(initialData.getUsername());
203 password.setText(initialData.getPassword());
204 schema.setText(initialData.getSchema());
205 connect.setText(initialData.getConnect());
206 driver.setText(initialData.getDriver());
207 String typeData = initialData.getType();
208 int selectedIndex = 0;
209 for (int i = 0; i < drivers.length; i++) {
210 if (typeData.equals(drivers[i].getDriverType())) {
214 type.select(selectedIndex);
215 driverFile.setText(initialData.getDriverFile());
218 setControl(container);
220 setPageComplete(true);
222 public void updateDriverList() {
224 JarFile file = new JarFile(driverFile.getText());
225 Enumeration enum = file.entries();
226 while (enum.hasMoreElements()) {
227 JarEntry entry = (JarEntry) enum.nextElement();
228 String className = entry.getName().replace('/', '.');
229 if (className.endsWith("Driver.class")) {
230 className = className.substring(0, className.lastIndexOf('.'));
231 //driverList.add(className);
234 } catch (IOException ex) {
235 //driverList.removeAll();
238 public void performFinish() {
239 if (initialData == null) {
240 initialData = new BookmarkNode();
242 initialData.setName(name.getText());
243 initialData.setUsername(username.getText());
244 initialData.setPassword(password.getText());
245 initialData.setSchema(schema.getText());
246 initialData.setConnect(connect.getText());
247 initialData.setDriver(driver.getText());
248 int selection = type.getSelectionIndex();
249 if (selection >= 0) {
250 initialData.setType(drivers[selection].getDriverType());
252 initialData.setDriverFile(driverFile.getText());
253 BookmarkView.getInstance().addNewBookmark(initialData);