1 package net.sourceforge.phpdt.sql.wizards;
3 import org.eclipse.jface.preference.IPreferenceStore;
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.SelectionEvent;
8 import org.eclipse.swt.events.SelectionListener;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Combo;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.FileDialog;
15 import org.eclipse.swt.widgets.Label;
16 import org.eclipse.swt.widgets.Text;
18 import net.sourceforge.phpdt.sql.Messages;
19 import net.sourceforge.phpdt.sql.PHPEclipseSQLPlugin;
20 import net.sourceforge.phpdt.sql.adapters.AdapterFactory;
21 import net.sourceforge.phpdt.sql.adapters.DriverInfo;
22 import net.sourceforge.phpdt.sql.view.BookmarkView;
23 import net.sourceforge.phpdt.sql.view.bookmark.BookmarkNode;
25 public class BookmarkWizard extends Wizard {
26 BookmarkPage mainPage;
28 private BookmarkNode current;
30 public void init(BookmarkNode selection) {
31 System.out.println("Initing workbench"); //$NON-NLS-1$
32 this.current = selection;
33 setWindowTitle(Messages.getString("BookmarkWizard.NewBookmark")); //$NON-NLS-1$
36 System.out.println("Initing workbench"); //$NON-NLS-1$
38 setWindowTitle(Messages.getString("BookmarkWizard.NewBookmark")); //$NON-NLS-1$
40 public boolean performFinish() {
41 System.out.println("perform finish workbench"); //$NON-NLS-1$
42 mainPage.performFinish();
45 public void addPages() {
46 System.out.println("adding pages"); //$NON-NLS-1$
47 if (current != null) {
48 mainPage = new BookmarkPage(Messages.getString("BookmarkWizard.Testing"), current); //$NON-NLS-1$
50 mainPage = new BookmarkPage(Messages.getString("BookmarkWizard.Testing")); //$NON-NLS-1$
53 System.out.println("adding pages"); //$NON-NLS-1$
57 class BookmarkPage extends WizardPage {
58 public static final String ADD = "ADD"; //$NON-NLS-1$
69 private IPreferenceStore fStore = PHPEclipseSQLPlugin.getDefault().getPreferenceStore();
71 BookmarkNode initialData = null;
75 DriverInfo[] drivers = AdapterFactory.getInstance().getDriverList();
77 * Constructor for BookmarkPage.
80 public BookmarkPage(String pageName) {
85 * Constructor for BookmarkPage.
88 public BookmarkPage(String pageName, BookmarkNode bookmark) {
90 this.initialData = bookmark;
93 public void createControl(Composite parent) {
94 System.out.println("page create control"); //$NON-NLS-1$
95 dialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
96 dialog.setFilterExtensions(new String[]{"*.jar", "*.zip","*.*"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
97 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$
98 Composite container = new Composite(parent, SWT.NULL);
99 GridLayout layout = new GridLayout();
100 container.setLayout(layout);
101 layout.numColumns = 2;
102 layout.verticalSpacing = 9;
105 Label label = new Label(container, SWT.NULL);
106 label.setText(Messages.getString("BookmarkWizard.BookmarkNameAst")); //$NON-NLS-1$
107 name = new Text(container, SWT.BORDER | SWT.SINGLE);
108 GridData fullHorizontal = new GridData();
109 fullHorizontal.horizontalAlignment = GridData.FILL;
110 name.setLayoutData(fullHorizontal);
112 label = new Label(container, SWT.NULL);
113 label.setText(Messages.getString("BookmarkWizard.UsernameAst")); //$NON-NLS-1$
114 username = new Text(container, SWT.BORDER | SWT.SINGLE);
115 fullHorizontal = new GridData();
116 fullHorizontal.horizontalAlignment = GridData.FILL;
117 username.setLayoutData(fullHorizontal);
119 label = new Label(container, SWT.NULL);
120 label.setText(Messages.getString("BookmarkWizard.PasswordAst")); //$NON-NLS-1$
121 password = new Text(container, SWT.BORDER | SWT.SINGLE);
122 password.setEchoChar('*');
123 fullHorizontal = new GridData();
124 fullHorizontal.horizontalAlignment = GridData.FILL;
125 password.setLayoutData(fullHorizontal);
127 label = new Label(container, SWT.NULL);
128 label.setText(Messages.getString("BookmarkWizard.Schema")); //$NON-NLS-1$
129 schema = new Text(container, SWT.BORDER | SWT.SINGLE);
130 fullHorizontal = new GridData();
131 fullHorizontal.horizontalAlignment = GridData.FILL;
132 schema.setLayoutData(fullHorizontal);
134 label = new Label(container, SWT.NULL);
135 label.setText(Messages.getString("BookmarkWizard.ConnectAst")); //$NON-NLS-1$
136 connect = new Text(container, SWT.BORDER | SWT.SINGLE);
137 fullHorizontal = new GridData();
138 fullHorizontal.horizontalAlignment = GridData.FILL;
139 connect.setLayoutData(fullHorizontal);
141 label = new Label(container, SWT.NULL);
142 label.setText(Messages.getString("BookmarkWizard.DriverAst")); //$NON-NLS-1$
143 driver = new Text(container, SWT.BORDER | SWT.SINGLE);
144 fullHorizontal = new GridData();
145 fullHorizontal.horizontalAlignment = GridData.FILL;
146 driver.setLayoutData(fullHorizontal);
148 //label = new Label(container, SWT.NULL);
149 //fullHorizontal = new GridData();
150 //fullHorizontal.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING;
151 //fullHorizontal.verticalSpan = 3;
152 //label.setLayoutData(fullHorizontal);
153 //label.setText("(Drivers Found in File)");
154 /*driverList = new List(container, SWT.SINGLE);
155 fullHorizontal = new GridData();
156 fullHorizontal.horizontalAlignment = GridData.FILL;
157 fullHorizontal.verticalAlignment = GridData.FILL;
158 fullHorizontal.verticalSpan = 3;
159 driverList.setLayoutData(fullHorizontal);
160 driverList.addSelectionListener(new SelectionListener() {
161 public void widgetDefaultSelected(SelectionEvent e) {
163 public void widgetSelected(SelectionEvent e) {
164 String[] selection = driverList.getSelection();
165 if (selection != null && selection.length > 0) {
166 driver.setText(selection[0]);
171 label = new Label(container, SWT.NULL);
172 label.setText(Messages.getString("BookmarkWizard.TypeAst")); //$NON-NLS-1$
173 type = new Combo(container, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
174 String driverNames[] = new String[drivers.length];
175 for (int i = 0; i < drivers.length; i++) {
176 driverNames[i] = drivers[i].getDisplayName();
178 type.setItems(driverNames);
180 fullHorizontal = new GridData();
181 fullHorizontal.horizontalAlignment = GridData.FILL;
182 type.setLayoutData(fullHorizontal);
184 label = new Label(container, SWT.NULL);
185 label.setText(Messages.getString("BookmarkWizard.DriverFilenameAst")); //$NON-NLS-1$
186 driverFile = new Text(container, SWT.BORDER | SWT.SINGLE);
187 fullHorizontal = new GridData();
188 fullHorizontal.horizontalAlignment = GridData.FILL;
189 driverFile.setLayoutData(fullHorizontal);
191 Button button = new Button(container, SWT.PUSH);
192 button.setText(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$
194 button.addSelectionListener(new SelectionListener() {
195 public void widgetDefaultSelected(SelectionEvent e) {
197 public void widgetSelected(SelectionEvent e) {
198 String filename = dialog.open();
199 if (filename != null) {
200 driverFile.setText(filename);
204 if (initialData != null) {
205 name.setText(initialData.getName());
206 username.setText(initialData.getUsername());
207 password.setText(initialData.getPassword());
208 schema.setText(initialData.getSchema());
209 connect.setText(initialData.getConnect());
210 driver.setText(initialData.getDriver());
211 String typeData = initialData.getType();
212 int selectedIndex = 0;
213 for (int i = 0; i < drivers.length; i++) {
214 if (typeData.equals(drivers[i].getDriverType())) {
218 type.select(selectedIndex);
219 driverFile.setText(initialData.getDriverFile());
223 username.setText(fStore.getString("phpeclipse.sql.username.connect"));
224 connect.setText(fStore.getString("phpeclipse.sql.connect.connect"));
225 driver.setText(fStore.getString("phpeclipse.sql.driver.connect"));
226 String typeData = fStore.getString("phpeclipse.sql.type.connect");
227 int selectedIndex = 0;
228 for (int i = 0; i < drivers.length; i++) {
229 if (typeData.equals(drivers[i].getDisplayName())) {
233 type.select(selectedIndex);
234 driverFile.setText(fStore.getString("phpeclipse.sql.filename.connect"));
236 setControl(container);
238 setPageComplete(true);
240 public void updateDriverList() {
242 JarFile file = new JarFile(driverFile.getText());
243 Enumeration enum = file.entries();
244 while (enum.hasMoreElements()) {
245 JarEntry entry = (JarEntry) enum.nextElement();
246 String className = entry.getName().replace('/', '.');
247 if (className.endsWith("Driver.class")) {
248 className = className.substring(0, className.lastIndexOf('.'));
249 //driverList.add(className);
252 } catch (IOException ex) {
253 //driverList.removeAll();
256 public void performFinish() {
257 if (initialData == null) {
258 initialData = new BookmarkNode();
261 initialData.setName(name.getText());
262 initialData.setUsername(username.getText());
263 initialData.setPassword(password.getText());
264 initialData.setSchema(schema.getText());
265 initialData.setConnect(connect.getText());
266 initialData.setDriver(driver.getText());
267 int selection = type.getSelectionIndex();
268 if (selection >= 0) {
269 initialData.setType(drivers[selection].getDriverType());
271 initialData.setDriverFile(driverFile.getText());
272 BookmarkView.getInstance().addNewBookmark(initialData);
274 //PHP Specific section
275 fStore.putValue("phpeclipse.sql.username.connect", username.getText());
276 fStore.putValue("phpeclipse.sql.connect.connect", connect.getText());
277 fStore.putValue("phpeclipse.sql.driver.connect", driver.getText());
278 fStore.putValue("phpeclipse.sql.filename.connect",driverFile.getText());