use of org.compiere.minigrid.CheckRenderer 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());
}
Aggregations