}
private void initTableProperties(String sql) {
CacheTableModel tm = new CacheTableModel(object, sql, stat);
TableColumnModel rowHeaderModel = new DefaultTableColumnModel() {
boolean first = true;
public void addColumn(TableColumn tc) {
if (first) {
super.addColumn(tc);
first = false;
}
}
};
headerColumn.setModel(tm);
headerColumn.setColumnModel(rowHeaderModel);
headerColumn.createDefaultColumnsFromModel();
headerColumn.setEnabled(false);
TableColumn indexColumn = headerColumn.getColumnModel().getColumn(0);
indexColumn.setCellRenderer(new IndexRenderer());
indexColumn.setMinWidth(50);
indexColumn.setResizable(false);
headerColumn.setGridColor(Color.LIGHT_GRAY);
headerColumn.setRowHeight(18);
table.setRowHeight(18);
table.setGridColor(Color.LIGHT_GRAY);
TableColumnModel cm = new DefaultTableColumnModel() {
boolean first = true;
public void addColumn(TableColumn tc) {
if (first) {
first = false;
return;
}
tc.setResizable(true);
super.addColumn(tc);
}
};
table.setModel(tm);
table.setColumnModel(cm);
table.createDefaultColumnsFromModel();
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
TableColumn column = table.getColumnModel().getColumn(i);
String columnName = (String)column.getHeaderValue();
if (sortStates.get(columnName) == null)
column.setHeaderRenderer(new SortRenderer(null, -1));
}
for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
TableColumn tcolumn = table.getColumnModel().getColumn(i);
//String columnName = (String)tcolumn.getHeaderValue();
//fort report table
if (((String)tm.getTables().get(i)).trim().length() <= 0) {
String name = (String)tm.getColumns().get(i);
String value = null;
StringTokenizer st = new StringTokenizer(name, "_");
st.nextElement();
String tableName = (String)st.nextElement();
String columnName = (String)st.nextElement();
Column column = ObjectUtil.findColumn(object, tableName, columnName);
if (column != null)
value = column.toString();
else
value = tableName + "_" + columnName;
if (name.indexOf("SUM_") > -1)
tcolumn.setHeaderRenderer(new ImageRenderer("SUM(" + value + ")", ImageManager.getImage(ImageManager.SUM_IMAGE)));
else if (name.indexOf("COUNT_") > -1)
tcolumn.setHeaderRenderer(new ImageRenderer("COUNT(" + value + ")", ImageManager.getImage(ImageManager.COUNT_IMAGE)));
}
}
try {
for (int i = 1; i < tm.getColumnCount(); i++) {
if (tm.getRs().getMetaData().getColumnDisplaySize(i) == 6)
cm.getColumn(i - 1).setPreferredWidth(150);
else if (tm.getRs().getMetaData().getColumnDisplaySize(i) >= 256)
cm.getColumn(i -1).setPreferredWidth(100);
else
cm.getColumn(i - 1).setMinWidth(tm.getRs().getMetaData().getColumnDisplaySize(i) * 5);
cm.getColumn(i - 1).setMaxWidth(200);
}
} catch (Exception e) {
e.printStackTrace();
}
int n = 0;