1 package com.quantum.ui.dialog;
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;
17 import com.quantum.Messages;
18 import com.quantum.QuantumPlugin;
19 import com.quantum.util.JarUtil;
24 public class AddDriverDialog extends Dialog {
26 private FileDialog fileDialog;
28 private Text driverFileName;
29 private Text driverClassName;
35 public AddDriverDialog(Shell parentShell) {
39 protected void configureShell(Shell shell) {
40 super.configureShell(shell);
41 shell.setText(Messages.getString(getClass(), "title"));
45 * Method declared on Dialog
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,
57 composite.setLayoutData(fullHorizontal);
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") });
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,
74 fullHorizontal.widthHint = 150;
75 this.driverFileName.setLayoutData(fullHorizontal);
77 Button button = new Button(composite, SWT.PUSH);
78 button.setText(Messages.getString(getClass(), "browse"));
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);
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,
101 fullHorizontal.widthHint = 150;
102 this.driverClassName.setLayoutData(fullHorizontal);
104 button = new Button(composite, SWT.PUSH);
105 button.setText(Messages.getString(getClass(), "browse"));
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());
121 protected String getDriverFile() {
122 return this.driverFileName.getText();