package com.quantum.wizards; import java.io.File; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; import com.quantum.Messages; import com.quantum.QuantumPlugin; import com.quantum.model.BookmarkCollection; import com.quantum.ui.dialog.AddDriverDialog; import com.quantum.view.JDBCDriverContentProvider; import com.quantum.view.JDBCDriverLabelProvider; /** * @author BC */ public class NewBookmarkPage1 extends WizardPage { private FileDialog fileDialog; private Text driverFileName; private TableViewer tableViewer; /** * @param pageName */ protected NewBookmarkPage1(String pageName) { super(pageName); } public void createControl(Composite parent) { Composite container = createBasicContainer(parent, 1); GridLayout layout = new GridLayout(2, false); container.setLayout(layout); Label label = new Label(container, SWT.NONE); label.setText("Select a driver"); GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); data.horizontalSpan = 2; label.setLayoutData(data); Table table = new Table(container, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER); table.setHeaderVisible(true); for (int i = 0, length = 4; i < length; i++) { TableColumn column = new TableColumn(table, SWT.NONE); column.setText(Messages.getString(getClass(), "driverColumn" + i)); } for (int i = 0, length = 4; i < length; i++) { table.getColumn(i).pack(); } this.tableViewer = new TableViewer(table); data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); this.tableViewer.getControl().setLayoutData(data); this.tableViewer.setContentProvider(new JDBCDriverContentProvider()); this.tableViewer.setLabelProvider(new JDBCDriverLabelProvider()); this.tableViewer.setColumnProperties(new String[] { "name", "className", "version", "jarFileName" }); // Table table = ((Table) this.tableViewer.getControl()); this.tableViewer.setInput(BookmarkCollection.getInstance()); Button newDriver = new Button(container, SWT.PUSH); newDriver.setText("Add driver..."); newDriver.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { AddDriverDialog dialog = new AddDriverDialog(getShell()); dialog.open(); } }); data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); newDriver.setLayoutData(data); setControl(container); } /** * @param parent */ private Composite createBasicContainer(Composite parent, int numberOfColumns) { Composite container = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); container.setLayout(layout); layout.numColumns = numberOfColumns; layout.verticalSpacing = 9; GridData fullHorizontal = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_BEGINNING, true, false); container.setLayoutData(fullHorizontal); return container; } /** * @param parent * @return */ private Composite createNewDriverSelection(Composite parent) { this.fileDialog = new FileDialog(getContainer().getShell(), SWT.OPEN); this.fileDialog.setFilterExtensions(new String[] { "*.jar", "*.zip", "*.*" }); this.fileDialog.setFilterNames(new String[] { Messages.getString("BookmarkWizard.JarFiles"), Messages.getString("BookmarkWizard.ZipFiles"), Messages.getString("BookmarkWizard.AllFiles") }); Composite container = createBasicContainer(parent, 3); Label label = new Label(container, SWT.NULL); label.setText(Messages.getString("BookmarkWizard.DriverAst")); //$NON-NLS-1$ this.driverFileName = new Text(container, SWT.BORDER | SWT.SINGLE); GridData fullHorizontal = new GridData( GridData.HORIZONTAL_ALIGN_BEGINNING, GridData.VERTICAL_ALIGN_BEGINNING, false, false); this.driverFileName.setLayoutData(fullHorizontal); Button button = new Button(container, SWT.PUSH); button.setText(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$ button.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { NewBookmarkPage1.this.fileDialog.setFilterPath(QuantumPlugin.getDefault() .getPreferenceStore().getString( "quantum.dialogs.bookmarkwizard.path")); String filename = NewBookmarkPage1.this.fileDialog.open(); if (filename != null) { NewBookmarkPage1.this.driverFileName.setText(filename); QuantumPlugin.getDefault().getPreferenceStore().setValue( "quantum.dialogs.bookmarkwizard.path", filename); } } }); return container; } // public boolean isPageComplete() { // File file = getDriverFile(); // if (file == null) { // return false; // } else if (!file.exists() || !file.isFile()) { // return false; // } else { // return true; // } // } // private File getDriverFile() { return (this.driverFileName == null || this.driverFileName.getText() == null) ? null : new File(this.driverFileName.getText()); } }