1 package org.sapia.gumby.swing.widgets; 2 3 import java.util.Vector ; 4 5 import javax.swing.JTable ; 6 import javax.swing.table.DefaultTableModel ; 7 8 import org.sapia.util.xml.confix.ConfigurationException; 9 import org.sapia.util.xml.confix.ObjectCreationCallback; 10 11 26 public class JTablePeer extends JTable implements ObjectCreationCallback { 27 28 static final long serialVersionUID = 1L; 29 30 private Vector _rows = new Vector (); 31 private Vector _headers = new Vector (); 32 33 public Row createTr() { 34 return new Row(this); 35 } 36 37 protected void addRow(Vector cols) { 38 _rows.add(cols); 39 } 40 41 public void addTh(String value) { 42 _headers.add(value); 43 } 44 45 48 public Object onCreate() throws ConfigurationException { 49 DefaultTableModel model = new DefaultTableModel (_rows, _headers); 50 super.setModel(model); 51 return this; 52 } 53 54 public static final class Header implements ObjectCreationCallback { 55 private JTablePeer _owner; 56 private String _value; 57 58 public Header(JTablePeer owner) { 59 _owner = owner; 60 } 61 62 public void setValue(String value) { 63 _value = value; 64 } 65 66 public Object onCreate() throws ConfigurationException { 67 _owner.addTh(_value == null ? "" : _value); 68 return this; 69 } 70 } 71 72 public static final class Row implements ObjectCreationCallback { 73 private Vector _cols = new Vector (); 74 private JTablePeer _owner; 75 76 Row(JTablePeer owner) { 77 _owner = owner; 78 } 79 80 public void addTd(Object colValue) { 81 _cols.add(colValue); 82 } 83 84 public Object onCreate() throws ConfigurationException { 85 _owner.addRow(_cols); 86 return this; 87 } 88 } 89 90 } 91 | Popular Tags |