Search in sources :

Example 1 with ISupportsDoubleBackground

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;
}
Also used : AbstractButton(javax.swing.AbstractButton) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Color(java.awt.Color) JComponent(javax.swing.JComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) JTextComponent(javax.swing.text.JTextComponent) Font(java.awt.Font) IScriptable(com.servoy.j2db.scripting.IScriptable) IDisplayRelatedData(com.servoy.j2db.dataprocessing.IDisplayRelatedData) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) ServoyBeanState(com.servoy.j2db.component.ServoyBeanState) DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) CompoundBorder(javax.swing.border.CompoundBorder) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) EventObject(java.util.EventObject) EmptyBorder(javax.swing.border.EmptyBorder) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) Border(javax.swing.border.Border) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) SpecialMatteBorder(com.servoy.j2db.util.gui.SpecialMatteBorder) ISupportsDoubleBackground(com.servoy.j2db.ui.ISupportsDoubleBackground)

Aggregations

ServoyBeanState (com.servoy.j2db.component.ServoyBeanState)1 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)1 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)1 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 DbIdentValue (com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue)1 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)1 IScriptable (com.servoy.j2db.scripting.IScriptable)1 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)1 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)1 ISupportsDoubleBackground (com.servoy.j2db.ui.ISupportsDoubleBackground)1 RenderEventExecutor (com.servoy.j2db.ui.RenderEventExecutor)1 SpecialMatteBorder (com.servoy.j2db.util.gui.SpecialMatteBorder)1 Color (java.awt.Color)1 Font (java.awt.Font)1 EventObject (java.util.EventObject)1 AbstractButton (javax.swing.AbstractButton)1 JComponent (javax.swing.JComponent)1 Border (javax.swing.border.Border)1