public abstract class DvsTable<DATA> extends JPanel {
protected SQLDataProxy<DATA> proxy;
protected ArrayList<DATA> items;
protected JTable table;
protected AbstractTableModel tableModel;
protected DvsDetailPanel<DATA> detailPanel;
...
public DvsTable(DatenSchnittstelle db, ...) {
...
init();
}
protected void init() {
...
initTable();
initCustom();
}
abstract protected void initTable();
abstract protected void initCustom();
}
public class CustomerTable extends DvsTable<Kunde> {
public CustomerTable(...) {
super(...);
}
@Override
protected void init() {
this.proxy = new SQLDataProxy<Kunde>(Kunde.class, this.db);
super.init();
}
@Override
protected void initCustom() {
super.detailPanel = new CustomerDetailPanel(super.proxy, super.iM,
super.info);
((CustomerDetailPanel) super.detailPanel)
.setExpandListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
...
}
});
}
@Override
protected void initTable() {
super.tableModel = new CustomerTableModel();
}
private class CustomerTableModel extends AbstractTableModel {
...
@SuppressWarnings("boxing")
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
Object o = null;
switch (columnIndex) {
case 0:
o = CustomerTable.super.items.get(rowIndex).getKundenID();
break;
case 1:
o = CustomerTable.super.items.get(rowIndex).getName();
break;
case 2:
o = CustomerTable.super.items.get(rowIndex).getVorname();
break;
default:
break;
}
return o;
}
}
public static void main(String[] args) {
JFrame f = new JFrame("CustomerTable");
...
f.add(new CustomerTable(new DatenSchnittstelle(...), ...);
...
}
}
public abstract class DvsDetailPanel<DATA> extends JPanel {
protected SQLDataProxy<DATA> proxy;
protected DATA data;
...
public DvsDetailPanel(...) {
...
init();
}
protected void init() {
...
}
}
public class CustomerDetailPanel extends DvsDetailPanel<Kunde> {
private JTextField kundenTextField;
...
public CustomerDetailPanel(...) {
super(...);
}
@Override
protected void init() {
this.kundenTextField = new JTextField(super.data.getKundenName());
JPanel.add(this.kundenTextField);
...
super.init();
}
}
public class SQLDataProxy<E> {
private Class<?> e;
private DatenSchnittstelle db;
...
public SQLDataProxy(Class<?> e, DatenSchnittstelle db) {
this.e = e;
this.db = db;
}
...
@SuppressWarnings("unchecked")
public E getItem(int id) {
E item = null;
if (this.e == Artikel.class) {
item = (E) this.db.getArtikel(id);
} else if (this.e == Kunde.class) {
item = (E) this.db.getKunde(id);
}
return item;
}
public void addItem(E item) {
if (this.e == Artikel.class) {
this.db.addArtikel((Artikel) item);
} else if (this.e == Kunde.class) {
this.db.addKunde((Kunde) item);
}
}
}
public class DatenSchnittstelle {
...
public Artikel getArtikel(int ArtikelNr) {
...
}
public Kunde getKunde(int kundenID) {
...
}
}