fixed "bracket matching highlighting" bug
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / wizards / AddDriverWizard.java
index e3cb426..6525e05 100644 (file)
@@ -1,5 +1,10 @@
 package com.quantum.wizards;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
 import com.quantum.ImageStore;
 import com.quantum.Messages;
 import com.quantum.QuantumPlugin;
@@ -13,9 +18,13 @@ import com.quantum.view.widget.ComboViewer;
 
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredContentProvider;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.jface.wizard.WizardPage;
@@ -31,20 +40,45 @@ 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.Text;
 
 /**
  * @author BC Holmes
+ * @author Sirkware
  */
 public class AddDriverWizard extends Wizard {
        
+       public class LabelProviderImpl extends LabelProvider {
+               
+               public Image getImage(Object element) {
+                       return ImageStore.getImage(ImageStore.EXTERNAL_JAR);
+               }
+       }
+       
+       public class ContentProviderImpl implements IStructuredContentProvider {
+               public Object[] getElements(Object inputElement) {
+                       if (inputElement instanceof List) {
+                               return ((List) inputElement).toArray();
+                       } else if (inputElement instanceof Object[]){
+                               return (Object[]) inputElement;
+                       } else {
+                               return null;
+                       }
+               }
+               public void dispose() {
+               }
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+               }
+       }
+       
        public class PageImpl extends WizardPage {
 
                private FileDialog fileDialog;
 
-               private Text driverFileName;
                private Text driverClassName;
                private ComboViewer type;
+               private TableViewer driverFiles;
                private DatabaseAdapter[] adapters = AdapterFactory.getInstance().getDriverList();
 
                public PageImpl() {
@@ -56,16 +90,12 @@ public class AddDriverWizard extends Wizard {
                        setTitle(Messages.getString(getClass(), "title"));
                        setDescription(Messages.getString(getClass(), "description"));
                        
-                       
                parent.setLayout(new GridLayout());
                Composite composite = new Composite(parent, SWT.NONE);
                        GridLayout layout = new GridLayout();
                        composite.setLayout(layout);
                        layout.numColumns = 3;
-                       GridData fullHorizontal = new GridData(
-                                       GridData.FILL_HORIZONTAL |
-                                       GridData.VERTICAL_ALIGN_BEGINNING);
-                       composite.setLayoutData(fullHorizontal);
+                       composite.setLayoutData(new GridData(GridData.FILL_BOTH));
                        
        
                        this.fileDialog = new FileDialog(composite.getShell(), SWT.OPEN);
@@ -76,41 +106,76 @@ public class AddDriverWizard extends Wizard {
                                        Messages.getString("BookmarkWizard.AllFiles") });
        
                        Label label = new Label(composite, SWT.NULL);
-                       label.setText(Messages.getString(getClass(), "fileName"));
-                       this.driverFileName = new Text(composite, SWT.BORDER | SWT.SINGLE);
-                       fullHorizontal = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
-                       this.driverFileName.setLayoutData(fullHorizontal);
+                       label.setText(Messages.getString(AddDriverWizard.class, "jars"));
+                       GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
+                       gridData.horizontalSpan = 3;
+                       label.setLayoutData(gridData);
                        
-                       this.driverFileName.addModifyListener(new ModifyListener() {
-                               public void modifyText(ModifyEvent event) {
-                                       updateButtons();
-                               }
-                               
-                       });
-       
-                       Button button = new Button(composite, SWT.PUSH);
-                       button.setText(Messages.getString(getClass(), "browse"));
+                       Table table = new Table(composite, SWT.BORDER);
+                       gridData = new GridData(GridData.FILL_BOTH);
+                       gridData.horizontalSpan = 2;
+                       table.setLayoutData(gridData);
+                       this.driverFiles = new TableViewer(table);
+                       this.driverFiles.setLabelProvider(new LabelProviderImpl());
+                       this.driverFiles.setContentProvider(new ContentProviderImpl());
+                       this.driverFiles.setInput(AddDriverWizard.this.driverFileNames);
+                       
+                       Composite buttonArea = new Composite(composite, SWT.NONE);
+                       GridLayout gridLayout = new GridLayout();
+                       gridLayout.marginWidth = 0;
+                       buttonArea.setLayout(gridLayout);
+                       buttonArea.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+                       
+                       Button addExternalJar = new Button(buttonArea, SWT.PUSH);
+                       addExternalJar.setText(Messages.getString(AddDriverWizard.class, "addExternalJar"));
+                       addExternalJar.setLayoutData(
+                                       new GridData(GridData.FILL_HORIZONTAL 
+                                                       | GridData.VERTICAL_ALIGN_BEGINNING));
        
-                       button.addSelectionListener(new SelectionAdapter() {
+                       addExternalJar.addSelectionListener(new SelectionAdapter() {
                                public void widgetSelected(SelectionEvent event) {
                                        PageImpl.this.fileDialog.setFilterPath(QuantumPlugin.getDefault()
                                                        .getPreferenceStore().getString(
                                                                        "quantum.dialogs.bookmarkwizard.path"));
                                        String filename = PageImpl.this.fileDialog.open();
                                        if (filename != null) {
-                                               PageImpl.this.driverFileName.setText(filename);
+                                               driverFileNames.add(filename);
+                                               PageImpl.this.driverFiles.refresh();
                                                QuantumPlugin.getDefault().getPreferenceStore().setValue(
                                                                "quantum.dialogs.bookmarkwizard.path", filename);
-                                               AddDriverWizard.this.setDriverFileName(filename);
                                                updateButtons();
                                        }
                                }
                        });
-       
+
+                       final Button removeJar = new Button(buttonArea, SWT.PUSH);
+                       removeJar.setText(Messages.getString(AddDriverWizard.class, "removeJar"));
+                       removeJar.setLayoutData(
+                                       new GridData(GridData.HORIZONTAL_ALIGN_FILL 
+                                                       | GridData.VERTICAL_ALIGN_BEGINNING));
+                       removeJar.setEnabled(false);
+                       
+                       this.driverFiles.addSelectionChangedListener(new ISelectionChangedListener() {
+                               public void selectionChanged(SelectionChangedEvent event) {
+                                       removeJar.setEnabled(!event.getSelection().isEmpty());
+                               }
+                       });
+                       
+                       removeJar.addSelectionListener(new SelectionAdapter(){
+                               public void widgetSelected(SelectionEvent event) {
+                                       IStructuredSelection selection = 
+                                               (IStructuredSelection) PageImpl.this.driverFiles.getSelection();
+                                       for (Iterator i = selection.iterator(); i.hasNext();) {
+                                               driverFileNames.remove(i.next());
+                                       }
+                                       PageImpl.this.driverFiles.refresh();
+                               }
+                       });
+                       
                        label = new Label(composite, SWT.NULL);
-                       label.setText(Messages.getString(getClass(), "driverClassName"));
+                       label.setText(Messages.getString(AddDriverWizard.class, "driverClassName"));
                        this.driverClassName = new Text(composite, SWT.BORDER | SWT.SINGLE);
-                       fullHorizontal = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
+                       GridData fullHorizontal = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING);
                        this.driverClassName.setLayoutData(fullHorizontal);
        
                        this.driverClassName.addModifyListener(new ModifyListener() {
@@ -118,16 +183,18 @@ public class AddDriverWizard extends Wizard {
                                        AddDriverWizard.this.setDriverClassName(((Text) event.getSource()).getText());
                                        updateButtons();
                                }
-                               
                        });
-                       button = new Button(composite, SWT.PUSH);
-                       button.setText(Messages.getString(getClass(), "browse"));
+                       
+                       
+                       Button browse = new Button(composite, SWT.PUSH);
+                       browse.setText(Messages.getString(AddDriverWizard.class, "browse"));
+                       browse.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
        
-                       button.addSelectionListener(new SelectionAdapter() {
+                       browse.addSelectionListener(new SelectionAdapter() {
                                public void widgetSelected(SelectionEvent event) {
                                        SimpleSelectionDialog dialog = new SimpleSelectionDialog(
                                                        getShell(), "Select a Driver", JarUtil.getAllDriverNames(
-                                                                       getDriverFile()), ImageStore.getImage(ImageStore.CLASS));
+                                                                       getDriverFileNames()), ImageStore.getImage(ImageStore.CLASS));
                                        if (dialog.open() == SimpleSelectionDialog.OK) {
                                                IStructuredSelection selection = dialog.getSelection();
                                                if (!selection.isEmpty()) {
@@ -137,23 +204,13 @@ public class AddDriverWizard extends Wizard {
                                                        AddDriverWizard.this.setDriverClassName(className);
                                                        updateButtons();
                                                }
-                                               
-                                               
                                        }
                                }
                        });
-                       label = new Label(composite, SWT.NULL);
+\r                      label = new Label(composite, SWT.NULL);
                        label.setText(Messages.getString("BookmarkWizard.TypeAst")); //$NON-NLS-1$
                        this.type = new ComboViewer(composite);
-                       this.type.setContentProvider(new IStructuredContentProvider() {
-                               public void dispose() {
-                               }
-                               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-                               }
-                               public Object[] getElements(Object inputElement) {
-                                       return PageImpl.this.adapters;
-                               }
-                       });
+                       this.type.setContentProvider(new ContentProviderImpl());
                        
                        this.type.setLabelProvider(new ILabelProvider() {
                                public Image getImage(Object element) {
@@ -177,7 +234,7 @@ public class AddDriverWizard extends Wizard {
                                }
                        });
                        
-                       type.setInput(this);
+                       type.setInput(this.adapters);
                        fullHorizontal = new GridData();
                        fullHorizontal.horizontalAlignment = GridData.FILL;
                        type.getControl().setLayoutData(fullHorizontal);
@@ -188,7 +245,9 @@ public class AddDriverWizard extends Wizard {
                        setControl(composite);
            }
            protected void updateButtons() {
-               Class driver = JarUtil.loadDriverClass(getDriverFile(), getDriverClassName());
+               Class driver = JarUtil.loadDriverClass(
+                               getDriverFileNames(), 
+                                       getDriverClassName());
                setPageComplete(driver != null);
                
                String adapterType = AdapterFactory.getInstance().getAdapterType(getDriverClassName());
@@ -197,13 +256,6 @@ public class AddDriverWizard extends Wizard {
                                        AdapterFactory.getInstance().getAdapter(adapterType)));
                }
            }
-               protected String getDriverClassName() {
-               return this.driverClassName == null ? null : this.driverClassName.getText();
-               }
-               protected String getDriverFile() {
-               return this.driverFileName == null ? null : this.driverFileName.getText();
-           }
-               
                protected String getDriverType() {
                        DatabaseAdapter driverInfo = (DatabaseAdapter) 
                                        ((IStructuredSelection) this.type.getSelection()).getFirstElement();
@@ -213,8 +265,8 @@ public class AddDriverWizard extends Wizard {
        private PageImpl page;
        
        private String driverClassName;
-       private String driverFileName;
        private String driverType;
+       private List driverFileNames = Collections.synchronizedList(new ArrayList());
 
        
        public void addPages() {
@@ -230,7 +282,7 @@ public class AddDriverWizard extends Wizard {
        public boolean performFinish() {
                JDBCDriver driver = new JDBCDriver(
                                getDriverClassName(), 
-                               getDriverFileName(), 
+                               getDriverFileNames(), 
                                this.page.getDriverType());
                BookmarkCollection.getInstance().addDriver(driver);
                return true;
@@ -261,16 +313,8 @@ public class AddDriverWizard extends Wizard {
        public void setDriverType(String driverType) {
                this.driverType = driverType;
        }
-       /**
-        * @return Returns the driverFileName.
-        */
-       public String getDriverFileName() {
-               return this.driverFileName;
-       }
-       /**
-        * @param driverFileName The driverFileName to set.
-        */
-       public void setDriverFileName(String driverFileName) {
-               this.driverFileName = driverFileName;
+       
+       public String[] getDriverFileNames() {
+               return (String[]) this.driverFileNames.toArray(new String[this.driverFileNames.size()]);
        }
 }
\ No newline at end of file