bcab770a9c512706b9916c7ba7a9f9721c9c20ec
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / ui / dialog / AddDriverDialog.java
1 package com.quantum.ui.dialog;
2
3 import org.eclipse.jface.dialogs.Dialog;
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.events.SelectionAdapter;
6 import org.eclipse.swt.events.SelectionEvent;
7 import org.eclipse.swt.layout.GridData;
8 import org.eclipse.swt.layout.GridLayout;
9 import org.eclipse.swt.widgets.Button;
10 import org.eclipse.swt.widgets.Composite;
11 import org.eclipse.swt.widgets.Control;
12 import org.eclipse.swt.widgets.FileDialog;
13 import org.eclipse.swt.widgets.Label;
14 import org.eclipse.swt.widgets.Shell;
15 import org.eclipse.swt.widgets.Text;
16
17 import com.quantum.Messages;
18 import com.quantum.QuantumPlugin;
19 import com.quantum.util.JarUtil;
20
21 /**
22  * @author BC
23  */
24 public class AddDriverDialog extends Dialog {
25
26         private FileDialog fileDialog;
27
28         private Text driverFileName;
29         private Text driverClassName;
30
31         
32         /**
33          * @param parentShell
34          */
35         public AddDriverDialog(Shell parentShell) {
36                 super(parentShell);
37         }
38
39         protected void configureShell(Shell shell) {
40                 super.configureShell(shell);
41                 shell.setText(Messages.getString(getClass(), "title"));
42         }
43         
44     /* (non-Javadoc)
45      * Method declared on Dialog
46      */
47     protected Control createDialogArea(Composite parent) {
48         parent.setLayout(new GridLayout());
49         Composite composite = (Composite) super.createDialogArea(parent);
50                 GridLayout layout = new GridLayout();
51                 composite.setLayout(layout);
52                 layout.numColumns = 3;
53                 GridData fullHorizontal = new GridData(
54                                 GridData.HORIZONTAL_ALIGN_BEGINNING,
55                                 GridData.VERTICAL_ALIGN_BEGINNING, 
56                                 true, false);
57                 composite.setLayoutData(fullHorizontal);
58                 
59
60                 this.fileDialog = new FileDialog(composite.getShell(), SWT.OPEN);
61                 this.fileDialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" });
62                 this.fileDialog.setFilterNames(new String[] {
63                                 Messages.getString("BookmarkWizard.JarFiles"),
64                                 Messages.getString("BookmarkWizard.ZipFiles"),
65                                 Messages.getString("BookmarkWizard.AllFiles") });
66
67                 Label label = new Label(composite, SWT.NULL);
68                 label.setText(Messages.getString(getClass(), "fileName"));
69                 this.driverFileName = new Text(composite, SWT.BORDER | SWT.SINGLE);
70                 fullHorizontal = new GridData(
71                                 GridData.HORIZONTAL_ALIGN_FILL,
72                                 GridData.VERTICAL_ALIGN_BEGINNING, 
73                                 true, false);
74                 fullHorizontal.widthHint = 150;
75                 this.driverFileName.setLayoutData(fullHorizontal);
76
77                 Button button = new Button(composite, SWT.PUSH);
78                 button.setText(Messages.getString(getClass(), "browse"));
79
80                 button.addSelectionListener(new SelectionAdapter() {
81                         public void widgetSelected(SelectionEvent event) {
82                                 AddDriverDialog.this.fileDialog.setFilterPath(QuantumPlugin.getDefault()
83                                                 .getPreferenceStore().getString(
84                                                                 "quantum.dialogs.bookmarkwizard.path"));
85                                 String filename = AddDriverDialog.this.fileDialog.open();
86                                 if (filename != null) {
87                                         AddDriverDialog.this.driverFileName.setText(filename);
88                                         QuantumPlugin.getDefault().getPreferenceStore().setValue(
89                                                         "quantum.dialogs.bookmarkwizard.path", filename);
90                                 }
91                         }
92                 });
93
94                 label = new Label(composite, SWT.NULL);
95                 label.setText(Messages.getString(getClass(), "driverClassName"));
96                 this.driverClassName = new Text(composite, SWT.BORDER | SWT.SINGLE);
97                 fullHorizontal = new GridData(
98                                 GridData.HORIZONTAL_ALIGN_FILL,
99                                 GridData.VERTICAL_ALIGN_BEGINNING, 
100                                 true, false);
101                 fullHorizontal.widthHint = 150;
102                 this.driverClassName.setLayoutData(fullHorizontal);
103
104                 button = new Button(composite, SWT.PUSH);
105                 button.setText(Messages.getString(getClass(), "browse"));
106
107                 button.addSelectionListener(new SelectionAdapter() {
108                         public void widgetSelected(SelectionEvent event) {
109                                 SimpleSelectionDialog dialog = new SimpleSelectionDialog(
110                                                 getShell(), "Select a Driver", JarUtil.getAllDriverNames(
111                                                                 getDriverFile()), QuantumPlugin.getImage("class.gif"));
112                                 if (dialog.open() == SimpleSelectionDialog.OK) {
113                                         AddDriverDialog.this.driverClassName.setText(
114                                                         dialog.getSelectedElement());
115                                 }
116                         }
117                 });
118                 return composite;
119     }
120     
121     protected String getDriverFile() {
122         return this.driverFileName.getText();
123     }
124 }