89bb37f3aa4bc24ad0fe0366d3be8f877d31f24d
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / NewBookmarkPage1.java
1 package com.quantum.wizards;
2
3 import java.io.File;
4
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;
20
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;
27
28 /**
29  * @author BC
30  */
31 public class NewBookmarkPage1 extends WizardPage {
32
33         private FileDialog fileDialog;
34
35         private Text driverFileName;
36         
37         private TableViewer tableViewer;
38
39         /**
40          * @param pageName
41          */
42         protected NewBookmarkPage1(String pageName) {
43                 super(pageName);
44         }
45
46         public void createControl(Composite parent) {
47                 Composite container = createBasicContainer(parent, 1);
48                 GridLayout layout = new GridLayout(2, false);
49                 container.setLayout(layout);
50                 
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);
56                 
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));
62         }
63                 
64         for (int i = 0, length = 4; i < length; i++) {
65             table.getColumn(i).pack();
66         }
67                 
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());
76                 
77                 
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());
83                         dialog.open();
84                         }
85                 });
86                 data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
87                 newDriver.setLayoutData(data);
88                 
89                 setControl(container);
90         }
91
92         /**
93          * @param parent
94          */
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, 
104                                 true, false);
105                 container.setLayoutData(fullHorizontal);
106                 return container;
107         }
108
109         /**
110          * @param parent
111          * @return
112          */
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") });
120
121                 Composite container = createBasicContainer(parent, 3);
122
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, 
129                                 false, false);
130                 this.driverFileName.setLayoutData(fullHorizontal);
131
132                 Button button = new Button(container, SWT.PUSH);
133                 button.setText(Messages.getString("BookmarkWizard.Browse")); //$NON-NLS-1$
134
135                 button.addSelectionListener(new SelectionListener() {
136
137                         public void widgetDefaultSelected(SelectionEvent e) {
138                         }
139
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);
149                                 }
150                         }
151                 });
152                 return container;
153         }
154
155         //      public boolean isPageComplete() {
156         //              File file = getDriverFile();
157         //              if (file == null) {
158         //                      return false;
159         //              } else if (!file.exists() || !file.isFile()) {
160         //                      return false;
161         //              } else {
162         //                      return true;
163         //              }
164         //      }
165         //      
166         private File getDriverFile() {
167                 return (this.driverFileName == null || this.driverFileName.getText() == null) ? null
168                                 : new File(this.driverFileName.getText());
169         }
170 }