use of com.revolsys.swing.table.record.editor.RecordTableCellEditor in project com.revolsys.open by revolsys.
the class AbstractSingleRecordTableModel method newTable.
public static BaseJTable newTable(final AbstractSingleRecordTableModel model) {
final BaseJTable table = new BaseJTable(model);
table.setModel(model);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.setAutoCreateColumnsFromModel(false);
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
final SingleRecordTableCellRenderer cellRenderer = new SingleRecordTableCellRenderer();
final RecordTableCellEditor cellEditor = new RecordTableCellEditor(table);
cellEditor.setPopupMenu(model.getMenu()::newJPopupMenu);
final RecordDefinition recordDefinition = model.getRecordDefinition();
final List<String> allFieldNames = recordDefinition.getFieldNames();
int maxTitleWidth = 100;
for (final String fieldName : allFieldNames) {
final String title = model.getFieldTitle(fieldName);
final int titleWidth = Math.max(title.length(), fieldName.length()) * 8;
if (titleWidth > maxTitleWidth) {
maxTitleWidth = titleWidth;
}
}
final int columnCount = model.getColumnCount();
int columnWidth;
if (columnCount > 3) {
columnWidth = (740 - maxTitleWidth) / 2;
} else {
columnWidth = (740 - maxTitleWidth) / 2;
}
for (int i = 0; i < columnCount; i++) {
final TableColumnExt column = table.getColumnExt(i);
column.setCellRenderer(cellRenderer);
if (i == 0) {
column.setMinWidth(40);
column.setPreferredWidth(40);
column.setMaxWidth(40);
column.setComparator(new NumericComparator());
} else if (i == 1) {
column.setMinWidth(maxTitleWidth);
column.setPreferredWidth(maxTitleWidth);
column.setMaxWidth(maxTitleWidth);
} else {
column.setPreferredWidth(columnWidth);
if (i == 2) {
column.setCellEditor(cellEditor);
}
}
}
return table;
}
Aggregations