1. Fix #1589403 - wrap double/single quoted strings
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / JDBCDriverSelectionWizardPage.java
1 package com.quantum.wizards;
2
3 import org.eclipse.jface.viewers.ISelectionChangedListener;
4 import org.eclipse.jface.viewers.IStructuredSelection;
5 import org.eclipse.jface.viewers.SelectionChangedEvent;
6 import org.eclipse.jface.wizard.WizardDialog;
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.layout.GridData;
11 import org.eclipse.swt.layout.GridLayout;
12 import org.eclipse.swt.widgets.Button;
13 import org.eclipse.swt.widgets.Composite;
14
15 import com.quantum.Messages;
16 import com.quantum.model.JDBCDriver;
17 import com.quantum.view.JDBCDriverTableViewer;
18
19 /**
20  * @author BC
21  */
22 public class JDBCDriverSelectionWizardPage extends PropertyChangeWizardPage implements ISelectionChangedListener {
23
24         private JDBCDriverTableViewer tableViewer;
25         
26         private JDBCDriver driver;
27         
28         /**
29          * @param pageName
30          */
31         public JDBCDriverSelectionWizardPage(String pageName) {
32                 super(pageName);
33
34                 setTitle(Messages.getString(getClass(), "title"));
35                 setDescription(Messages.getString(getClass(), "description"));
36         }
37
38         public void createControl(Composite parent) {
39                 setPageComplete(false);
40                 Composite container = createBasicContainer(parent, 1);
41                 GridLayout layout = new GridLayout(1, false);
42                 container.setLayout(layout);
43                 
44                 this.tableViewer = new JDBCDriverTableViewer(container);
45                 GridData data = new GridData(GridData.FILL_BOTH);
46                 this.tableViewer.getControl().setLayoutData(data);
47                 this.tableViewer.addSelectionChangedListener(this);
48
49                 Button newDriver = new Button(container, SWT.PUSH);
50                 newDriver.setText(Messages.getString(getClass(), "addDriver"));
51                 newDriver.addSelectionListener(new SelectionAdapter() {
52                         public void widgetSelected(SelectionEvent e) {
53                         AddDriverWizard wizard = new AddDriverWizard();
54                         WizardDialog dialog =
55                             new WizardDialog(getShell(), wizard);
56                         dialog.open();
57                         }
58                 });
59                 data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
60                 newDriver.setLayoutData(data);
61                 
62                 setControl(container);
63         }
64         /**
65          * @param parent
66          */
67         private Composite createBasicContainer(Composite parent, int numberOfColumns) {
68                 Composite container = new Composite(parent, SWT.NULL);
69                 GridLayout layout = new GridLayout();
70                 container.setLayout(layout);
71                 layout.numColumns = numberOfColumns;
72                 layout.verticalSpacing = 9;
73                 GridData fullHorizontal = new GridData(GridData.FILL_BOTH);
74                 container.setLayoutData(fullHorizontal);
75                 return container;
76         }
77         public void selectionChanged(SelectionChangedEvent event) {
78                 IStructuredSelection selection = (IStructuredSelection) event.getSelection();
79                 setPageComplete(!selection.isEmpty());
80                 if (!selection.isEmpty()) {
81                         setDriver((JDBCDriver) selection.getFirstElement());
82                 }
83                 
84         }
85         /**
86          * @return Returns the driver.
87          */
88         public JDBCDriver getDriver() {
89                 return this.driver;
90         }
91         /**
92          * @param driver The driver to set.
93          */
94         public void setDriver(JDBCDriver driver) {
95                 if (this.driver != driver) {
96                         JDBCDriver original = this.driver;
97                         this.driver = driver;
98                         firePropertyChange("driver", original, driver);
99                 }
100         }
101         public void dispose() {
102                 this.tableViewer.dispose();
103                 super.dispose();
104         }
105 }