use of org.compiere.grid.ed.VCellRenderer 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));
}
}
use of org.compiere.grid.ed.VCellRenderer 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());
}
use of org.compiere.grid.ed.VCellRenderer 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());
}
use of org.compiere.grid.ed.VCellRenderer in project adempiere by adempiere.
the class GridController method setupVTable.
// getTitle
/**
* Setup Multi-Row Table (add fields)
* @param aPanel Panel
* @param mTab Model Tab
* @param table JTable
* @return size
*/
private int setupVTable(APanel aPanel, GridTab mTab, VTable table) {
if (!mTab.isDisplayed())
return 0;
int size = mTab.getFieldCount();
TableColumnModel tcm = table.getColumnModel();
if (size != tcm.getColumnCount())
throw new IllegalStateException("TableColumn Size <> TableModel");
for (int i = 0; i < size; i++) {
GridField mField = mTab.getField(i);
TableColumn tc = tcm.getColumn(i);
tc.setMinWidth(30);
// FR 3051618 - Hide in list view
if (!mField.isDisplayedGrid()) {
vTable.setColumnVisibility(tc, false);
}
if (mField.getColumnName().equals(tc.getIdentifier().toString())) {
//don't show included tab field in grid
if (mField.getIncluded_Tab_ID() > 0) {
TableCellNone tcn = new TableCellNone(mField.getColumnName());
tc.setCellRenderer(tcn);
tc.setCellEditor(tcn);
tc.setHeaderValue(null);
tc.setMinWidth(0);
tc.setMaxWidth(0);
tc.setPreferredWidth(0);
table.setColumnVisibility(tc, false);
} else if (mField.getDisplayType() == DisplayType.RowID) {
tc.setCellRenderer(new VRowIDRenderer(false));
tc.setCellEditor(new VRowIDEditor(false));
tc.setHeaderValue("");
tc.setMaxWidth(2);
} else {
// need to set CellEditor explicitly as default editor based on class causes problem (YesNo-> Boolean)
if (mField.isDisplayed() && mField.isDisplayedGrid()) {
tc.setCellRenderer(new VCellRenderer(mField));
VCellEditor ce = new VCellEditor(mField);
tc.setCellEditor(ce);
//
tc.setHeaderValue(mField.getHeader());
tc.setPreferredWidth(Math.max(mField.getDisplayLength(), 30));
tc.setHeaderRenderer(new VHeaderRenderer(mField));
// Enable Button actions in grid
if (mField.getDisplayType() == DisplayType.Button) {
ce.setActionListener(aPanel);
}
} else // column not displayed
{
TableCellNone tcn = new TableCellNone(mField.getColumnName());
tc.setCellRenderer(tcn);
tc.setCellEditor(tcn);
tc.setHeaderValue(null);
tc.setMinWidth(0);
tc.setMaxWidth(0);
tc.setPreferredWidth(0);
table.setColumnVisibility(tc, false);
}
}
} else
// found field
log.log(Level.SEVERE, "TableColumn " + tc.getIdentifier() + " <> MField " + mField.getColumnName() + mField.getHeader());
}
// for all fields
return size;
}
Aggregations