use of com.servoy.j2db.ui.ISupportsDoubleBackground in project servoy-client by Servoy.
the class CellAdapter method getTableCellEditorComponent.
/*
* @see TableCellEditor#getTableCellEditorComponent(JTable, Object, boolean, int, int)
*/
public Component getTableCellEditorComponent(JTable jtable, Object value, boolean isSelected, int row, int column) {
if (editor == null || !isVisible(editor) || !(jtable.getModel() instanceof IFoundSetInternal)) {
return empty;
}
IRecordInternal newRec = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
if (isSelected) {
Color bgColor = getBgColor(jtable, isSelected, row, true);
if (bgColor != null && editor instanceof JComponent)
((JComponent) editor).setOpaque(true);
if (bgColor == null) {
// unselected background is the default background color of the editor.
bgColor = unselectedBackground;
}
lastEditorBgColor = bgColor;
if (editor instanceof ISupportsDoubleBackground) {
((ISupportsDoubleBackground) editor).setBackground(bgColor, unselectedBackground);
} else {
editor.setBackground(bgColor);
}
Color fgColor = getFgColor(jtable, isSelected, row);
if (fgColor == null) {
// unselected foreground is the default foreground color of the editor.
fgColor = unselectedForeground;
}
lastEditorFgColor = fgColor;
if (editor instanceof ISupportsDoubleBackground) {
((ISupportsDoubleBackground) editor).setForeground(fgColor, unselectedForeground);
} else {
editor.setForeground(fgColor);
}
Font font = getFont(jtable, isSelected, row);
if (font == null) {
// unselected font is the default font of the editor.
font = unselectedFont;
}
lastEditorFont = font;
editor.setFont(font);
Border styleBorder = getBorder(jtable, isSelected, row);
if (styleBorder != null && editor instanceof JComponent) {
if (editor instanceof AbstractButton && !((AbstractButton) editor).isBorderPainted()) {
((AbstractButton) editor).setBorderPainted(true);
}
Border marginBorder = null;
if (noFocusBorder instanceof EmptyBorder) {
marginBorder = noFocusBorder;
} else if (noFocusBorder instanceof CompoundBorder && ((CompoundBorder) noFocusBorder).getInsideBorder() instanceof EmptyBorder) {
marginBorder = ((CompoundBorder) noFocusBorder).getInsideBorder();
}
// if we have margin set on the component, keep it along with the style border
if (marginBorder != null) {
styleBorder = new CompoundBorder(styleBorder, marginBorder);
}
((JComponent) editor).setBorder(styleBorder);
}
}
// try
// {
// if (currentEditingState != null && newRec != currentEditingState && currentEditingState.isEditing())
// {
// currentEditingState.stopEditing();
// }
// }
// catch (Exception e)
// {
// Debug.error(e);
// }
currentEditingState = newRec;
if (currentEditingState != null) {
if (editor instanceof IScriptableProvider) {
IScriptable scriptable = ((IScriptableProvider) editor).getScriptObject();
if (scriptable instanceof ISupportOnRenderCallback) {
RenderEventExecutor renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
if (renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
renderEventExecutor.setRenderState(currentEditingState, row, isSelected, true);
}
}
}
// if not enabled or not editable do not start the edit
if (editor instanceof IDisplay && ((IDisplay) editor).isEnabled() && !((IDisplay) editor).isReadOnly()) {
DisplaysAdapter.startEdit(dal, (IDisplay) editor, currentEditingState);
}
if (editor instanceof IDisplayRelatedData) {
IDisplayRelatedData drd = (IDisplayRelatedData) editor;
IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
if (state != null) {
drd.setRecord(state, true);
}
}
if (// && dataProviderID != null)
editor instanceof IDisplayData) {
try {
Object data = dal.getValueObject(currentEditingState, dataProviderID);
if (data instanceof DbIdentValue) {
data = ((DbIdentValue) data).getPkValue();
}
convertAndSetValue(((IDisplayData) editor), data);
} catch (IllegalArgumentException iae) {
Debug.error(iae);
}
}
if (editor instanceof IServoyAwareBean) {
((IServoyAwareBean) editor).setSelectedRecord(new ServoyBeanState(currentEditingState, dal.getFormScope()));
}
if (editor instanceof IScriptableProvider && !(editor instanceof IDisplayData) && !(editor instanceof IDisplayRelatedData)) {
IScriptable scriptable = ((IScriptableProvider) editor).getScriptObject();
if (scriptable instanceof ISupportOnRenderCallback) {
RenderEventExecutor renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
if (renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
renderEventExecutor.fireOnRender(editor instanceof JTextComponent ? ((JTextComponent) editor).isEditable() : false);
}
}
}
}
return editor.isVisible() ? editor : empty;
}
Aggregations