Search in sources :

Example 11 with TableColumnExt

use of org.jdesktop.swingx.table.TableColumnExt 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;
}
Also used : TableColumnExt(org.jdesktop.swingx.table.TableColumnExt) SingleRecordTableCellRenderer(com.revolsys.swing.table.record.renderer.SingleRecordTableCellRenderer) BaseJTable(com.revolsys.swing.table.BaseJTable) NumericComparator(com.revolsys.comparator.NumericComparator) RecordTableCellEditor(com.revolsys.swing.table.record.editor.RecordTableCellEditor) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Aggregations

TableColumnExt (org.jdesktop.swingx.table.TableColumnExt)11 TableColumn (javax.swing.table.TableColumn)5 BaseJTable (com.revolsys.swing.table.BaseJTable)4 Element (org.dom4j.Element)3 JXTable (org.jdesktop.swingx.JXTable)3 Table (com.haulmont.cuba.gui.components.Table)2 MetaClass (com.haulmont.chile.core.model.MetaClass)1 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 RowSorterImpl (com.haulmont.cuba.desktop.gui.data.RowSorterImpl)1 FocusableTable (com.haulmont.cuba.desktop.sys.vcl.FocusableTable)1 Action (com.haulmont.cuba.gui.components.Action)1 CollectionDsActionsNotifier (com.haulmont.cuba.gui.data.impl.CollectionDsActionsNotifier)1 WeakCollectionChangeListener (com.haulmont.cuba.gui.data.impl.WeakCollectionChangeListener)1 WeakItemPropertyChangeListener (com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener)1 NumericComparator (com.revolsys.comparator.NumericComparator)1 RecordDefinition (com.revolsys.record.schema.RecordDefinition)1 RecordTableCellEditor (com.revolsys.swing.table.record.editor.RecordTableCellEditor)1 SingleRecordTableCellRenderer (com.revolsys.swing.table.record.renderer.SingleRecordTableCellRenderer)1 MouseAdapter (java.awt.event.MouseAdapter)1