Search in sources :

Example 1 with MiniCellEditor

use of org.compiere.minigrid.MiniCellEditor 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)

Aggregations

Insets (java.awt.Insets)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 TableColumn (javax.swing.table.TableColumn)1 VCellRenderer (org.compiere.grid.ed.VCellRenderer)1 VHeaderRenderer (org.compiere.grid.ed.VHeaderRenderer)1 CheckRenderer (org.compiere.minigrid.CheckRenderer)1 IDColumnEditor (org.compiere.minigrid.IDColumnEditor)1 IDColumnRenderer (org.compiere.minigrid.IDColumnRenderer)1 MiniCellEditor (org.compiere.minigrid.MiniCellEditor)1 ROCellEditor (org.compiere.minigrid.ROCellEditor)1 CCheckBox (org.compiere.swing.CCheckBox)1