1 package com.quantum.view;
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
6 import org.eclipse.jface.viewers.TableViewer;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.swt.widgets.Control;
10 import org.eclipse.swt.widgets.Table;
11 import org.eclipse.swt.widgets.TableColumn;
13 import com.quantum.Messages;
14 import com.quantum.model.BookmarkCollection;
15 import com.quantum.model.JDBCDriver;
21 public class JDBCDriverTableViewer implements PropertyChangeListener {
23 private TableViewer tableViewer;
25 public JDBCDriverTableViewer(Composite container) {
26 Table table = new Table(container, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER);
27 table.setHeaderVisible(true);
28 for (int i = 0, length = 4; i < length; i++) {
29 TableColumn column = new TableColumn(table, SWT.NONE);
30 column.setText(Messages.getString(getClass(), "driverColumn" + i));
33 for (int i = 0, length = 4; i < length; i++) {
34 table.getColumn(i).pack();
37 this.tableViewer = new TableViewer(table);
38 this.tableViewer.setContentProvider(new JDBCDriverContentProvider());
39 this.tableViewer.setLabelProvider(new JDBCDriverLabelProvider());
40 this.tableViewer.setColumnProperties(new String[] { "name", "className", "version", "jarFileName" });
41 this.tableViewer.setInput(BookmarkCollection.getInstance());
43 BookmarkCollection.getInstance().addPropertyChangeListener(this);
44 registerWithAllDrivers();
49 private void registerWithAllDrivers() {
50 JDBCDriver[] drivers = BookmarkCollection.getInstance().getJDBCDrivers();
51 for (int i = 0, length = drivers == null ? 0 : drivers.length; i < length; i++) {
52 drivers[i].addPropertyChangeListener(this);
58 public Control getControl() {
59 return this.tableViewer.getControl();
62 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
64 public void propertyChange(PropertyChangeEvent event) {
65 if ("drivers".equals(event.getPropertyName())) {
66 registerWithAllDrivers();
67 this.tableViewer.refresh();
68 } else if (event.getSource() instanceof JDBCDriver) {
69 this.tableViewer.refresh(event.getSource());
73 public void dispose() {
74 JDBCDriver[] drivers = BookmarkCollection.getInstance().getJDBCDrivers();
75 for (int i = 0, length = drivers == null ? 0 : drivers.length; i < length; i++) {
76 drivers[i].removePropertyChangeListener(this);
78 BookmarkCollection.getInstance().removePropertyChangeListener(this);