1 package com.quantum.wizards;
5 import org.eclipse.jface.viewers.TableViewer;
6 import org.eclipse.jface.wizard.WizardPage;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.events.SelectionAdapter;
9 import org.eclipse.swt.events.SelectionEvent;
10 import org.eclipse.swt.events.SelectionListener;
11 import org.eclipse.swt.layout.GridData;
12 import org.eclipse.swt.layout.GridLayout;
13 import org.eclipse.swt.widgets.Button;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.FileDialog;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Table;
18 import org.eclipse.swt.widgets.TableColumn;
19 import org.eclipse.swt.widgets.Text;
21 import com.quantum.Messages;
22 import com.quantum.QuantumPlugin;
23 import com.quantum.model.BookmarkCollection;
24 import com.quantum.ui.dialog.AddDriverDialog;
25 import com.quantum.view.JDBCDriverContentProvider;
26 import com.quantum.view.JDBCDriverLabelProvider;
31 public class NewBookmarkPage1 extends WizardPage {
33 private FileDialog fileDialog;
35 private Text driverFileName;
37 private TableViewer tableViewer;
42 protected NewBookmarkPage1(String pageName) {
46 public void createControl(Composite parent) {
47 Composite container = createBasicContainer(parent, 1);
48 GridLayout layout = new GridLayout(2, false);
49 container.setLayout(layout);
51 Label label = new Label(container, SWT.NONE);
52 label.setText("Select a driver");
53 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
54 data.horizontalSpan = 2;
55 label.setLayoutData(data);
57 Table table = new Table(container, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
58 table.setHeaderVisible(true);
59 for (int i = 0, length = 4; i < length; i++) {
60 TableColumn column = new TableColumn(table, SWT.NONE);
61 column.setText(Messages.getString(getClass(), "driverColumn" + i));
64 for (int i = 0, length = 4; i < length; i++) {
65 table.getColumn(i).pack();
68 this.tableViewer = new TableViewer(table);
69 data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
70 this.tableViewer.getControl().setLayoutData(data);
71 this.tableViewer.setContentProvider(new JDBCDriverContentProvider());
72 this.tableViewer.setLabelProvider(new JDBCDriverLabelProvider());
73 this.tableViewer.setColumnProperties(new String[] { "name", "className", "version", "jarFileName" });
74 // Table table = ((Table) this.tableViewer.getControl());
75 this.tableViewer.setInput(BookmarkCollection.getInstance());
78 Button newDriver = new Button(container, SWT.PUSH);
79 newDriver.setText("Add driver...");
80 newDriver.addSelectionListener(new SelectionAdapter() {
81 public void widgetSelected(SelectionEvent e) {
82 AddDriverDialog dialog = new AddDriverDialog(getShell());
86 data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
87 newDriver.setLayoutData(data);
89 setControl(container);
95 private Composite createBasicContainer(Composite parent, int numberOfColumns) {
96 Composite container = new Composite(parent, SWT.NULL);
97 GridLayout layout = new GridLayout();
98 container.setLayout(layout);
99 layout.numColumns = numberOfColumns;
100 layout.verticalSpacing = 9;
101 GridData fullHorizontal = new GridData(
102 GridData.HORIZONTAL_ALIGN_BEGINNING,
103 GridData.VERTICAL_ALIGN_BEGINNING,
105 container.setLayoutData(fullHorizontal);
113 private Composite createNewDriverSelection(Composite parent) {
114 this.fileDialog = new FileDialog(getContainer().getShell(), SWT.OPEN);
115 this.fileDialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" });
116 this.fileDialog.setFilterNames(new String[] {
117 Messages.getString("BookmarkWizard.JarFiles"),
118 Messages.getString("BookmarkWizard.ZipFiles"),
119 Messages.getString("BookmarkWizard.AllFiles") });
121 Composite container = createBasicContainer(parent, 3);
123 Label label = new Label(container, SWT.NULL);
124 label.setText(Messages.getString("BookmarkWizard.DriverAst")); //$NON-NLS-1$
125 this.driverFileName = new Text(container, SWT.BORDER | SWT.SINGLE);
126 GridData fullHorizontal = new GridData(
127 GridData.HORIZONTAL_ALIGN_BEGINNING,
128 GridData.VERTICAL_ALIGN_BEGINNING,
130 this.driverFileName.setLayoutData(fullHorizontal);
132 Button button = new Button(container, SWT.PUSH);
133 button.setText(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$
135 button.addSelectionListener(new SelectionListener() {
137 public void widgetDefaultSelected(SelectionEvent e) {
140 public void widgetSelected(SelectionEvent e) {
141 NewBookmarkPage1.this.fileDialog.setFilterPath(QuantumPlugin.getDefault()
142 .getPreferenceStore().getString(
143 "quantum.dialogs.bookmarkwizard.path"));
144 String filename = NewBookmarkPage1.this.fileDialog.open();
145 if (filename != null) {
146 NewBookmarkPage1.this.driverFileName.setText(filename);
147 QuantumPlugin.getDefault().getPreferenceStore().setValue(
148 "quantum.dialogs.bookmarkwizard.path", filename);
155 // public boolean isPageComplete() {
156 // File file = getDriverFile();
157 // if (file == null) {
159 // } else if (!file.exists() || !file.isFile()) {
166 private File getDriverFile() {
167 return (this.driverFileName == null || this.driverFileName.getText() == null) ? null
168 : new File(this.driverFileName.getText());