1 package net.sourceforge.phpdt.sql.wizards;
3 import net.sourceforge.phpdt.sql.IConstants;
4 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
5 import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
6 import net.sourceforge.phpdt.sql.adapters.DriverInfo;
7 import net.sourceforge.phpdt.sql.view.BookmarkView;
8 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
10 import org.eclipse.jface.preference.IPreferenceStore;
11 import org.eclipse.jface.wizard.Wizard;
12 import org.eclipse.jface.wizard.WizardPage;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.SelectionEvent;
15 import org.eclipse.swt.events.SelectionListener;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Combo;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.FileDialog;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.swt.widgets.Text;
25 public class BookmarkWizard extends Wizard implements IConstants {
26 BookmarkPage mainPage;
28 private BookmarkNode current;
30 public void init(BookmarkNode selection) {
32 System.out.println("Initing workbench");
34 this.current = selection;
35 setWindowTitle("New Bookmark");
40 System.out.println("Initing workbench");
43 setWindowTitle("New Bookmark");
46 public boolean performFinish() {
48 System.out.println("perform finish workbench");
50 mainPage.performFinish();
54 public void addPages() {
56 System.out.println("adding pages");
58 if (current != null) {
59 mainPage = new BookmarkPage("Testing...", current);
61 mainPage = new BookmarkPage("Testing...");
65 System.out.println("adding pages");
70 class BookmarkPage extends WizardPage implements IConstants {
71 public static final String ADD = "ADD";
83 BookmarkNode initialData = null;
87 DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
89 * Constructor for BookmarkPage.
92 public BookmarkPage(String pageName) {
97 * Constructor for BookmarkPage.
100 public BookmarkPage(String pageName, BookmarkNode bookmark) {
102 this.initialData = bookmark;
105 public void createControl(Composite parent) {
107 System.out.println("page create control");
109 dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
110 dialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" });
111 dialog.setFilterNames(
115 "All Files (*.*)" });
116 Composite container = new Composite(parent, SWT.NULL);
117 GridLayout layout = new GridLayout();
118 container.setLayout(layout);
119 layout.numColumns = 2;
120 layout.verticalSpacing = 9;
122 Label label = new Label(container, SWT.NULL);
123 label.setText("*Bookmark Name");
124 name = new Text(container, SWT.BORDER | SWT.SINGLE);
125 GridData fullHorizontal = new GridData();
126 fullHorizontal.horizontalAlignment = GridData.FILL;
127 name.setLayoutData(fullHorizontal);
129 label = new Label(container, SWT.NULL);
130 label.setText("*Username");
131 username = new Text(container, SWT.BORDER | SWT.SINGLE);
132 fullHorizontal = new GridData();
133 fullHorizontal.horizontalAlignment = GridData.FILL;
134 username.setLayoutData(fullHorizontal);
136 label = new Label(container, SWT.NULL);
137 label.setText("*Password");
138 password = new Text(container, SWT.BORDER | SWT.SINGLE);
139 password.setEchoChar('*');
140 fullHorizontal = new GridData();
141 fullHorizontal.horizontalAlignment = GridData.FILL;
142 password.setLayoutData(fullHorizontal);
144 label = new Label(container, SWT.NULL);
145 label.setText("Schema (optional)");
146 schema = new Text(container, SWT.BORDER | SWT.SINGLE);
147 fullHorizontal = new GridData();
148 fullHorizontal.horizontalAlignment = GridData.FILL;
149 schema.setLayoutData(fullHorizontal);
151 label = new Label(container, SWT.NULL);
152 label.setText("*Connect");
153 connect = new Text(container, SWT.BORDER | SWT.SINGLE);
154 fullHorizontal = new GridData();
155 fullHorizontal.horizontalAlignment = GridData.FILL;
156 connect.setLayoutData(fullHorizontal);
158 label = new Label(container, SWT.NULL);
159 label.setText("*Driver");
160 driver = new Text(container, SWT.BORDER | SWT.SINGLE);
161 fullHorizontal = new GridData();
162 fullHorizontal.horizontalAlignment = GridData.FILL;
163 driver.setLayoutData(fullHorizontal);
165 //label = new Label(container, SWT.NULL);
166 //fullHorizontal = new GridData();
167 //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
168 //fullHorizontal.verticalSpan = 3;
169 //label.setLayoutData(fullHorizontal);
170 //label.setText("(Drivers Found in File)");
171 /*driverList = new List(container, SWT.SINGLE);
172 fullHorizontal = new GridData();
173 fullHorizontal.horizontalAlignment = GridData.FILL;
174 fullHorizontal.verticalAlignment = GridData.FILL;
175 fullHorizontal.verticalSpan = 3;
176 driverList.setLayoutData(fullHorizontal);
177 driverList.addSelectionListener(new SelectionListener() {
178 public void widgetDefaultSelected(SelectionEvent e) {
180 public void widgetSelected(SelectionEvent e) {
181 String[] selection = driverList.getSelection();
182 if (selection != null && selection.length > 0) {
183 driver.setText(selection[0]);
188 label = new Label(container, SWT.NULL);
189 label.setText("*Type");
190 type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
191 String driverNames[] = new String[drivers.length];
192 for (int i = 0; i < drivers.length; i++) {
193 driverNames[i] = drivers[i].getDisplayName();
195 type.setItems(driverNames);
197 fullHorizontal = new GridData();
198 fullHorizontal.horizontalAlignment = GridData.FILL;
199 type.setLayoutData(fullHorizontal);
201 label = new Label(container, SWT.NULL);
202 label.setText("*Driver Filename");
203 driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
204 fullHorizontal = new GridData();
205 fullHorizontal.horizontalAlignment = GridData.FILL;
206 driverFile.setLayoutData(fullHorizontal);
208 Button button = new Button(container, SWT.PUSH);
209 button.setText("Browse...");
211 button.addSelectionListener(new SelectionListener() {
212 public void widgetDefaultSelected(SelectionEvent e) {
214 public void widgetSelected(SelectionEvent e) {
215 String filename = dialog.open();
216 if (filename != null) {
217 driverFile.setText(filename);
221 if (initialData != null) {
222 name.setText(initialData.getName());
223 username.setText(initialData.getUsername());
224 password.setText(initialData.getPassword());
225 schema.setText(initialData.getSchema());
226 connect.setText(initialData.getConnect());
227 driver.setText(initialData.getDriver());
228 String typeData = initialData.getType();
229 int selectedIndex = 0;
230 for (int i = 0; i < drivers.length; i++) {
231 if (typeData.equals(drivers[i].getDriverType())) {
235 type.select(selectedIndex);
236 driverFile.setText(initialData.getDriverFile());
240 IPreferenceStore fStore =
241 PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
242 username.setText(fStore.getString("phpeclipse.sql.username.connect"));
243 connect.setText(fStore.getString("phpeclipse.sql.connect.connect"));
244 driver.setText(fStore.getString("phpeclipse.sql.driver.connect"));
245 String typeData = fStore.getString("phpeclipse.sql.type.connect");
246 int selectedIndex = 0;
247 for (int i = 0; i < drivers.length; i++) {
248 if (typeData.equals(drivers[i].getDisplayName())) {
252 type.select(selectedIndex);
253 driverFile.setText(fStore.getString("phpeclipse.sql.filename.connect"));
254 // updateDriverList();
256 setControl(container);
258 setPageComplete(true);
260 public void updateDriverList() {
262 JarFile file = new JarFile(driverFile.getText());
263 Enumeration enum = file.entries();
264 while (enum.hasMoreElements()) {
265 JarEntry entry = (JarEntry) enum.nextElement();
266 String className = entry.getName().replace('/', '.');
267 if (className.endsWith("Driver.class")) {
268 className = className.substring(0, className.lastIndexOf('.'));
269 //driverList.add(className);
272 } catch (IOException ex) {
273 //driverList.removeAll();
276 public void performFinish() {
277 if (initialData == null) {
278 initialData = new BookmarkNode();
280 initialData.setName(name.getText());
281 initialData.setUsername(username.getText());
282 initialData.setPassword(password.getText());
283 initialData.setSchema(schema.getText());
284 initialData.setConnect(connect.getText());
285 initialData.setDriver(driver.getText());
286 int selection = type.getSelectionIndex();
287 if (selection >= 0) {
288 initialData.setType(drivers[selection].getDriverType());
290 initialData.setDriverFile(driverFile.getText());
291 BookmarkView.getInstance().addNewBookmark(initialData);