Search in sources :

Example 46 with TableColumn

use of javax.swing.table.TableColumn in project adempiere by adempiere.

the class VBrowserTable method setColumnClass.

//  addColumn
/**
     * Set Column Editor & Renderer to Class
     *
     * @param index       column index
     * @param gridField
     * @param displayType define Type Value IDColumn, Boolean, Double (Quantity), BigDecimal (Amount), Integer, Timestamp, String (default)
     * @param readOnly    read only flag
     * @param header      optional header value
     */
public void setColumnClass(int index, GridField gridField, int displayType, boolean readOnly, String header) {
    //	log.config( "MiniTable.setColumnClass - " + index, c.getName() + ", r/o=" + readOnly);
    TableColumn tc = getColumnModel().getColumn(index);
    if (tc == null)
        return;
    //  Set R/O
    setColumnReadOnly(index, readOnly);
    //  Header
    if (header != null && header.length() > 0)
        tc.setHeaderValue(Util.cleanAmp(header));
    //  ID Column & Selection
    if (index == p_keyColumnIndex) {
        tc.setCellRenderer(new IDColumnRenderer(m_multiSelection));
        if (m_multiSelection) {
            tc.setCellEditor(new IDColumnEditor());
            setColumnReadOnly(index, false);
        } else {
            tc.setCellEditor(new ROCellEditor());
        }
        m_minWidth.add(new Integer(10));
        tc.setMaxWidth(20);
        tc.setPreferredWidth(20);
        tc.setResizable(false);
        tc.setHeaderRenderer(new VHeaderRenderer(DisplayType.Number));
    } else {
        tc.setCellRenderer(new VCellRenderer(gridField));
        tc.setCellEditor(new VBrowserCellEditor(gridField));
        m_minWidth.add(new Integer(30));
        tc.setHeaderRenderer(new VHeaderRenderer(displayType));
    }
}
Also used : IDColumnRenderer(org.compiere.minigrid.IDColumnRenderer) VCellRenderer(org.compiere.grid.ed.VCellRenderer) VHeaderRenderer(org.compiere.grid.ed.VHeaderRenderer) IDColumnEditor(org.compiere.minigrid.IDColumnEditor) TableColumn(javax.swing.table.TableColumn) ROCellEditor(org.compiere.minigrid.ROCellEditor)

Example 47 with TableColumn

use of javax.swing.table.TableColumn in project adempiere by adempiere.

the class MiniTable method setColumnClass.

/**
	 *  Set Column Editor & Renderer to Class
	 *  (after all columns were added)
	 *  Layout of IDColumn depends on multiSelection
	 *  @param index column index
	 *  @param c   class of column - determines renderer/editors supported:
	 *  @param DisplayType define Type Value
	 *  IDColumn, Boolean, Double (Quantity), BigDecimal (Amount), Integer, Timestamp, String (default)
	 *  @param readOnly read only flag
	 *  @param header optional header value
	 */
public void setColumnClass(int index, @SuppressWarnings("rawtypes") Class c, int displayType, boolean readOnly, String header) {
    //	log.config( "MiniTable.setColumnClass - " + index, c.getName() + ", r/o=" + readOnly);
    TableColumn tc = getColumnModel().getColumn(index);
    if (tc == null)
        return;
    //  Set R/O
    setColumnReadOnly(index, readOnly);
    //  Header
    if (header != null && header.length() > 0)
        tc.setHeaderValue(Util.cleanAmp(header));
    //  ID Column & Selection
    if (c == IDColumn.class) {
        IDColumnRenderer idcr = new IDColumnRenderer(m_multiSelection);
        tc.setCellRenderer(idcr);
        if (m_multiSelection) {
            VHeaderRenderer vhr = new VHeaderRenderer(m_multiSelection);
            tc.setCellEditor(new IDColumnEditor());
            tc.setHeaderRenderer(vhr);
            //  Connect the IDColumn with the header
            idcr.addChangeListener(vhr);
            setColumnReadOnly(index, false);
        } else {
            tc.setCellEditor(new ROCellEditor());
            tc.setHeaderRenderer(new VHeaderRenderer(DisplayType.Number));
        }
        m_minWidth.add(new Integer(10));
        tc.setMaxWidth(20);
        tc.setPreferredWidth(20);
        tc.setResizable(false);
    } else //  Boolean
    if (DisplayType.YesNo == displayType || c == Boolean.class) {
        CheckRenderer cr = new CheckRenderer();
        tc.setCellRenderer(cr);
        if (readOnly) {
            tc.setCellEditor(new ROCellEditor());
            tc.setHeaderRenderer(new VHeaderRenderer(DisplayType.YesNo));
        } else {
            if (m_multiSelection) {
                VHeaderRenderer vhr = new VHeaderRenderer(m_multiSelection);
                setColumnReadOnly(index, false);
                CCheckBox check = new CCheckBox();
                check.setMargin(new Insets(0, 0, 0, 0));
                check.setHorizontalAlignment(SwingConstants.CENTER);
                tc.setCellEditor(new DefaultCellEditor(check));
                tc.setHeaderRenderer(vhr);
                //  Connect the check control with the header
                cr.addChangeListener(vhr);
            }
        }
        m_minWidth.add(new Integer(30));
    } else //  Date
    if (DisplayType.Date == displayType || DisplayType.DateTime == displayType || c == Timestamp.class) {
        if (DisplayType.DateTime == displayType)
            tc.setCellRenderer(new VCellRenderer(DisplayType.DateTime));
        else
            tc.setCellRenderer(new VCellRenderer(DisplayType.Date));
        if (readOnly)
            tc.setCellEditor(new ROCellEditor());
        else if (DisplayType.Date == displayType || DisplayType.DateTime == displayType)
            tc.setCellEditor(new MiniCellEditor(c, displayType));
        else
            tc.setCellEditor(new MiniCellEditor(c));
        m_minWidth.add(new Integer(30));
        if (DisplayType.DateTime == displayType)
            tc.setHeaderRenderer(new VHeaderRenderer(DisplayType.DateTime));
        else
            tc.setHeaderRenderer(new VHeaderRenderer(DisplayType.Date));
    } else //  Amount
    if (DisplayType.Amount == displayType || c == BigDecimal.class) {
        tc.setCellRenderer(new VCellRenderer(DisplayType.Amount));
        if (readOnly) {
            tc.setCellEditor(new ROCellEditor());
            m_minWidth.add(new Integer(70));
        } else {
            tc.setCellEditor(new MiniCellEditor(c));
            m_minWidth.add(new Integer(80));
        }
        tc.setHeaderRenderer(new VHeaderRenderer(DisplayType.Number));
    } else //  Number
    if (DisplayType.Number == displayType || c == Double.class) {
        tc.setCellRenderer(new VCellRenderer(DisplayType.Number));
        if (readOnly) {
            tc.setCellEditor(new ROCellEditor());
            m_minWidth.add(new Integer(70));
        } else {
            tc.setCellEditor(new MiniCellEditor(c));
            m_minWidth.add(new Integer(80));
        }
        tc.setHeaderRenderer(new VHeaderRenderer(DisplayType.Number));
    } else //  Integer
    if (DisplayType.Integer == displayType || c == Integer.class) {
        tc.setCellRenderer(new VCellRenderer(DisplayType.Integer));
        if (readOnly)
            tc.setCellEditor(new ROCellEditor());
        else
            tc.setCellEditor(new MiniCellEditor(c));
        m_minWidth.add(new Integer(30));
        tc.setHeaderRenderer(new VHeaderRenderer(DisplayType.Number));
    } else //  String
    {
        tc.setCellRenderer(new VCellRenderer(DisplayType.String));
        if (readOnly)
            tc.setCellEditor(new ROCellEditor());
        else
            tc.setCellEditor(new MiniCellEditor(String.class));
        m_minWidth.add(new Integer(30));
        tc.setHeaderRenderer(new VHeaderRenderer(DisplayType.String));
    }
//	log.fine( "Renderer=" + tc.getCellRenderer().toString() + ", Editor=" + tc.getCellEditor().toString());
}
Also used : Insets(java.awt.Insets) VCellRenderer(org.compiere.grid.ed.VCellRenderer) TableColumn(javax.swing.table.TableColumn) Timestamp(java.sql.Timestamp) DefaultCellEditor(javax.swing.DefaultCellEditor) CCheckBox(org.compiere.swing.CCheckBox) VHeaderRenderer(org.compiere.grid.ed.VHeaderRenderer)

Example 48 with TableColumn

use of javax.swing.table.TableColumn in project adempiere by adempiere.

the class POSTable method setColumnClass.

@Override
public void setColumnClass(int index, @SuppressWarnings("rawtypes") Class c, int displayType, boolean readOnly, String header) {
    //	logger.config( "MiniTable.setColumnClass - " + index, c.getName() + ", r/o=" + readOnly);
    TableColumn tableColumn = getColumnModel().getColumn(index);
    if (tableColumn == null)
        return;
    //  Set R/O
    setColumnReadOnly(index, readOnly);
    //  Header
    if (header != null && header.length() > 0)
        tableColumn.setHeaderValue(Util.cleanAmp(header));
    ArrayList<Integer> minWidth = new ArrayList<Integer>();
    boolean multiSelection = false;
    //  ID Column & Selection
    if (c == IDColumn.class) {
        IDColumnRenderer columnRenderer = new IDColumnRenderer(multiSelection);
        tableColumn.setCellRenderer(columnRenderer);
        if (multiSelection) {
            VHeaderRenderer headerRenderer = new VHeaderRenderer(multiSelection);
            tableColumn.setCellEditor(new IDColumnEditor());
            tableColumn.setHeaderRenderer(headerRenderer);
            //  Connect the IDColumn with the header
            columnRenderer.addChangeListener(headerRenderer);
            setColumnReadOnly(index, false);
        } else {
            tableColumn.setCellEditor(new ROCellEditor());
            tableColumn.setHeaderRenderer(new VHeaderRenderer(DisplayType.Number));
        }
        minWidth.add(new Integer(10));
        tableColumn.setMaxWidth(20);
        tableColumn.setPreferredWidth(20);
        tableColumn.setResizable(false);
    } else //  Boolean
    if (DisplayType.YesNo == displayType || c == Boolean.class) {
        CheckRenderer checkRenderer = new CheckRenderer();
        tableColumn.setCellRenderer(checkRenderer);
        if (readOnly) {
            tableColumn.setCellEditor(new ROCellEditor());
            tableColumn.setHeaderRenderer(new VHeaderRenderer(DisplayType.YesNo));
        } else {
            if (multiSelection) {
                VHeaderRenderer headerRenderer = new VHeaderRenderer(multiSelection);
                setColumnReadOnly(index, false);
                CCheckBox check = new CCheckBox();
                check.setMargin(new Insets(0, 0, 0, 0));
                check.setHorizontalAlignment(SwingConstants.CENTER);
                tableColumn.setCellEditor(new DefaultCellEditor(check));
                tableColumn.setHeaderRenderer(headerRenderer);
                //  Connect the check control with the header
                checkRenderer.addChangeListener(headerRenderer);
            }
        }
        minWidth.add(new Integer(30));
    } else //  Date
    if (DisplayType.Date == displayType || DisplayType.DateTime == displayType || c == Timestamp.class) {
        if (DisplayType.DateTime == displayType)
            tableColumn.setCellRenderer(new VCellRenderer(DisplayType.DateTime));
        else
            tableColumn.setCellRenderer(new VCellRenderer(DisplayType.Date));
        if (readOnly)
            tableColumn.setCellEditor(new ROCellEditor());
        else if (DisplayType.Date == displayType || DisplayType.DateTime == displayType)
            tableColumn.setCellEditor(new MiniCellEditor(c, displayType));
        else
            tableColumn.setCellEditor(new MiniCellEditor(c));
        minWidth.add(new Integer(30));
        if (DisplayType.DateTime == displayType)
            tableColumn.setHeaderRenderer(new VHeaderRenderer(DisplayType.DateTime));
        else
            tableColumn.setHeaderRenderer(new VHeaderRenderer(DisplayType.Date));
    } else //  Amount
    if (DisplayType.Amount == displayType || c == BigDecimal.class) {
        tableColumn.setCellRenderer(new VCellRenderer(DisplayType.Amount));
        if (readOnly) {
            tableColumn.setCellEditor(new ROCellEditor());
            minWidth.add(new Integer(70));
        } else {
            tableColumn.setCellEditor(new MiniCellEditor(c));
            minWidth.add(new Integer(80));
        }
        tableColumn.setHeaderRenderer(new VHeaderRenderer(DisplayType.Number));
    } else //  Number
    if (DisplayType.Number == displayType || c == Double.class) {
        tableColumn.setCellRenderer(new VCellRenderer(DisplayType.Number));
        if (readOnly) {
            tableColumn.setCellEditor(new ROCellEditor());
            minWidth.add(new Integer(70));
        } else {
            tableColumn.setCellEditor(new MiniCellEditor(c));
            minWidth.add(new Integer(80));
        }
        tableColumn.setHeaderRenderer(new VHeaderRenderer(DisplayType.Number));
    } else //  Integer
    if (DisplayType.Integer == displayType || c == Integer.class) {
        tableColumn.setCellRenderer(new VCellRenderer(DisplayType.Integer));
        if (readOnly)
            tableColumn.setCellEditor(new ROCellEditor());
        else
            tableColumn.setCellEditor(new MiniCellEditor(c));
        minWidth.add(new Integer(30));
        tableColumn.setHeaderRenderer(new VHeaderRenderer(DisplayType.Number));
    } else //  String
    {
        tableColumn.setCellRenderer(new VCellRenderer(DisplayType.String));
        if (readOnly)
            tableColumn.setCellEditor(new ROCellEditor());
        else
            tableColumn.setCellEditor(new MiniCellEditor(String.class));
        minWidth.add(new Integer(30));
        tableColumn.setHeaderRenderer(new VHeaderRenderer(DisplayType.String));
    }
//	logger.fine( "Renderer=" + tc.getCellRenderer().toString() + ", Editor=" + tc.getCellEditor().toString());
}
Also used : Insets(java.awt.Insets) CheckRenderer(org.compiere.minigrid.CheckRenderer) ArrayList(java.util.ArrayList) IDColumnRenderer(org.compiere.minigrid.IDColumnRenderer) VCellRenderer(org.compiere.grid.ed.VCellRenderer) IDColumnEditor(org.compiere.minigrid.IDColumnEditor) TableColumn(javax.swing.table.TableColumn) Timestamp(java.sql.Timestamp) ROCellEditor(org.compiere.minigrid.ROCellEditor) DefaultCellEditor(javax.swing.DefaultCellEditor) CCheckBox(org.compiere.swing.CCheckBox) MiniCellEditor(org.compiere.minigrid.MiniCellEditor) VHeaderRenderer(org.compiere.grid.ed.VHeaderRenderer)

Example 49 with TableColumn

use of javax.swing.table.TableColumn in project adempiere by adempiere.

the class ResultTable method setModel.

//  ResultTable
/**
	 *  Set Model
	 *  @param reportModel
	 */
public void setModel(RModel reportModel) {
    log.config(reportModel.toString());
    m_model = reportModel;
    super.setModel(new ResultTableModel(reportModel));
    //
    TableColumnModel tcm = getColumnModel();
    //  Set Editor/Renderer
    for (int i = 0; i < tcm.getColumnCount(); i++) {
        TableColumn tc = tcm.getColumn(i);
        RColumn rc = reportModel.getRColumn(i);
        if (rc.getColHeader().equals(tc.getHeaderValue())) {
            ResultTableCellRenderer rtcr = new ResultTableCellRenderer(reportModel, rc);
            tc.setCellRenderer(rtcr);
        //
        } else
            log.log(Level.SEVERE, "RColumn=" + rc.getColHeader() + " <> TableColumn=" + tc.getHeaderValue());
    }
    autoSize();
}
Also used : TableColumnModel(javax.swing.table.TableColumnModel) TableColumn(javax.swing.table.TableColumn)

Example 50 with TableColumn

use of javax.swing.table.TableColumn in project adempiere by adempiere.

the class CTable method autoSize.

//  stopEditor
/**************************************************************************
	 *	Size Columns.
	 *	@param useColumnIdentifier if false uses plain content -
	 *  otherwise uses Column Identifier to indicate displayed columns
	 */
public void autoSize(boolean useColumnIdentifier) {
    TableModel model = this.getModel();
    int size = model.getColumnCount();
    //	for all columns
    for (int c = 0; c < size; c++) {
        TableColumn column = getColumnModel().getColumn(c);
        //	Not displayed columns
        if (useColumnIdentifier && (column.getIdentifier() == null || column.getMaxWidth() == 0 || column.getIdentifier().toString().length() == 0))
            continue;
        int width = 0;
        //	Header
        TableCellRenderer renderer = column.getHeaderRenderer();
        if (renderer == null)
            renderer = new DefaultTableCellRenderer();
        Component comp = null;
        if (renderer != null)
            comp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false, false, 0, 0);
        //
        if (comp != null) {
            width = comp.getPreferredSize().width;
            width = Math.max(width, comp.getWidth());
            //	Cells
            int col = column.getModelIndex();
            int maxRow = Math.min(20, getRowCount());
            try {
                for (int row = 0; row < maxRow; row++) {
                    renderer = getCellRenderer(row, col);
                    comp = renderer.getTableCellRendererComponent(this, getValueAt(row, col), false, false, row, col);
                    if (comp != null) {
                        int rowWidth = comp.getPreferredSize().width;
                        width = Math.max(width, rowWidth);
                    }
                }
            } catch (Exception e) {
                log.log(Level.SEVERE, column.getIdentifier().toString(), e);
            }
            //	Width not greater than 250
            width = Math.min(MAXSIZE, width + SLACK);
        }
        //
        column.setPreferredWidth(width);
    }
//	for all columns
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JComponent(javax.swing.JComponent) Component(java.awt.Component) TableColumn(javax.swing.table.TableColumn) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Aggregations

TableColumn (javax.swing.table.TableColumn)272 TableColumnModel (javax.swing.table.TableColumnModel)75 JTable (javax.swing.JTable)51 TableCellRenderer (javax.swing.table.TableCellRenderer)50 JScrollPane (javax.swing.JScrollPane)44 JPanel (javax.swing.JPanel)33 Component (java.awt.Component)31 JLabel (javax.swing.JLabel)26 BoxLayout (javax.swing.BoxLayout)25 JComboBox (javax.swing.JComboBox)23 ActionEvent (java.awt.event.ActionEvent)21 Dimension (java.awt.Dimension)20 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)20 DefaultCellEditor (javax.swing.DefaultCellEditor)19 ActionListener (java.awt.event.ActionListener)17 JButton (javax.swing.JButton)17 FlowLayout (java.awt.FlowLayout)16 DefaultTableModel (javax.swing.table.DefaultTableModel)15 ArrayList (java.util.ArrayList)14 DefaultTableColumnModel (javax.swing.table.DefaultTableColumnModel)12