Search in sources :

Example 1 with IScriptRenderMethods

use of com.servoy.j2db.ui.IScriptRenderMethods in project servoy-client by Servoy.

the class AbstractRuntimeRendersupportComponent method clearRenderableWrapperProperty.

public void clearRenderableWrapperProperty(String property) {
    RenderEventExecutor renderEventExecutor = getRenderEventExecutor();
    IScriptRenderMethods renderable = getRenderable();
    if (renderEventExecutor != null && !renderEventExecutor.isOnRenderExecuting() && renderable instanceof RenderableWrapper) {
        ((RenderableWrapper) renderable).clearProperty(property);
    }
}
Also used : IScriptRenderMethods(com.servoy.j2db.ui.IScriptRenderMethods) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) RenderableWrapper(com.servoy.j2db.ui.RenderableWrapper)

Example 2 with IScriptRenderMethods

use of com.servoy.j2db.ui.IScriptRenderMethods in project servoy-client by Servoy.

the class RuntimeDataCalendar method setFormat.

public void setFormat(String formatString) {
    if (!Utils.safeEquals(formatString, getFormat())) {
        setComponentFormat(new ComponentFormat(FormatParser.parseFormatProperty(application.getI18NMessageIfPrefixed(formatString)), componentFormat == null ? IColumnTypes.TEXT : componentFormat.dpType, componentFormat == null ? IColumnTypes.TEXT : componentFormat.uiType));
        getChangesRecorder().setChanged();
        RenderEventExecutor renderEventExecutor = getRenderEventExecutor();
        IScriptRenderMethods renderable = getRenderable();
        if (renderEventExecutor != null && !renderEventExecutor.isOnRenderExecuting() && renderable instanceof RenderableWrapper) {
            ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FORMAT);
        }
        fireOnRender();
    }
}
Also used : IScriptRenderMethods(com.servoy.j2db.ui.IScriptRenderMethods) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) RenderableWrapper(com.servoy.j2db.ui.RenderableWrapper) ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Example 3 with IScriptRenderMethods

use of com.servoy.j2db.ui.IScriptRenderMethods in project servoy-client by Servoy.

the class CellAdapter method getTableCellRendererComponent.

/*
	 * @see TableCellRenderer#getTableCellRendererComponent(JTable, Object, boolean, boolean, int, int)
	 */
public Component getTableCellRendererComponent(JTable jtable, Object value, boolean isSelected, boolean hasFocus, final int row, final int column) {
    if (renderer == null || !isVisible(renderer) || !(jtable.getModel() instanceof IFoundSetInternal)) {
        return empty;
    }
    final ISwingFoundSet foundset = (ISwingFoundSet) jtable.getModel();
    if (foundset != tableViewFoundset) {
        // foundset changed
        this.tableViewFoundset = foundset;
        rowAndDataprovider.clear();
    }
    final IRecordInternal state;
    try {
        state = foundset.getRecord(row);
    } catch (RuntimeException re) {
        // $NON-NLS-1$
        Debug.error("Error getting row ", re);
        return empty;
    }
    RenderEventExecutor renderEventExecutor = null;
    IScriptRenderMethods renderable = null;
    if (renderer instanceof IScriptableProvider) {
        IScriptable scriptable = ((IScriptableProvider) renderer).getScriptObject();
        if (scriptable instanceof ISupportOnRenderCallback) {
            renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
            renderable = ((ISupportOnRenderCallback) scriptable).getRenderable();
        }
    }
    Color bgColor = getBgColor(jtable, isSelected, row, false);
    if (bgColor != null && renderer instanceof JComponent)
        ((JComponent) renderer).setOpaque(true);
    Color fgColor = getFgColor(jtable, isSelected, row);
    Font font = getFont(jtable, isSelected, row);
    // so that getLocation and getWidth in scripting on tableviews do work.
    if (editor != null && editor.getParent() == null) {
        Rectangle cellRect = jtable.getCellRect(row, column, false);
        editor.setLocation(cellRect.x, cellRect.y);
        editor.setSize(cellRect.width, cellRect.height);
    }
    boolean isRenderWithOnRender = renderEventExecutor != null && renderEventExecutor.hasRenderCallback() && renderable instanceof RenderableWrapper;
    Color renderBgColor = null;
    if (isSelected) {
        if (!isRenderWithOnRender || renderEventExecutor.isDifferentRenderState(state, row, isSelected)) {
            Color tableSelectionColor = jtable.getSelectionForeground();
            if (bgColor != null) {
                tableSelectionColor = adjustColorDifference(bgColor, tableSelectionColor);
            }
            ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
            renderer.setForeground(fgColor != null ? fgColor : tableSelectionColor);
            ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
            renderBgColor = (bgColor != null ? bgColor : jtable.getSelectionBackground());
            renderer.setBackground(renderBgColor);
            if (font != null) {
                ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FONT);
                renderer.setFont(font);
            }
        } else if (isRenderWithOnRender && foundset.getSize() == 1) {
            // if the foundset contains a single record, we need to force trigger onRender
            // because renderEventExecutor refers already to the changed render state
            renderEventExecutor.setRenderStateChanged();
        }
    } else {
        if (isRenderWithOnRender) {
            if (renderEventExecutor.isDifferentRenderState(state, row, isSelected)) {
                Color newBGColor = bgColor != null ? bgColor : componentBgColor;
                if (newBGColor != null) {
                    ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
                    renderBgColor = newBGColor;
                    renderer.setBackground(renderBgColor);
                }
                Color newFGColor = fgColor != null ? fgColor : componentFgColor;
                if (newFGColor != null) {
                    ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
                    renderer.setForeground(newFGColor);
                } else if (newBGColor != null) {
                    renderer.setForeground(adjustColorDifference(newBGColor, jtable.getForeground()));
                }
                Font newFont = font != null ? font : componentFont;
                if (newFont != null) {
                    ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FONT);
                    renderer.setFont(newFont);
                }
            }
        } else {
            // now get the editors background. if we don't do that then scripting doesn't show up
            Color background = editor.getBackground();
            if (background != null && !background.equals(lastEditorBgColor)) {
                unselectedBackground = background;
                lastEditorBgColor = background;
            }
            Font editorFont = editor.getFont();
            if (editorFont != null && !editorFont.equals(lastEditorFont)) {
                unselectedFont = editorFont;
            }
            if (editor instanceof IDisplayData && ((IDisplayData) editor).isValueValid() || !(editor instanceof IDisplayData)) {
                Color foreground = editor.getForeground();
                if (foreground != null && !foreground.equals(lastEditorFgColor)) {
                    unselectedForeground = foreground;
                }
                Color currentForeground = (fgColor != null ? fgColor : (unselectedForeground != null) ? unselectedForeground : jtable.getForeground());
                renderer.setForeground(currentForeground);
            }
            Color currentColor = (bgColor != null ? bgColor : (unselectedBackground != null) ? unselectedBackground : jtable.getBackground());
            renderer.setBackground(currentColor);
            Font currentFont = (font != null ? font : (unselectedFont != null) ? unselectedFont : jtable.getFont());
            renderer.setFont(currentFont);
        }
    }
    if (renderer instanceof JComponent) {
        applyRowBorder((JComponent) renderer, jtable, isSelected, row, hasFocus);
    }
    // $NON-NLS-1$
    boolean printing = Utils.getAsBoolean(application.getRuntimeProperties().get("isPrinting"));
    if (renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
        renderEventExecutor.setRenderState(state, row, isSelected, true);
    }
    if (renderer instanceof IDisplayRelatedData) {
        IDisplayRelatedData drd = (IDisplayRelatedData) renderer;
        String relationName = drd.getSelectedRelationName();
        if (state != null) {
            if (relationName != null) {
                if (!printing && !state.isRelatedFoundSetLoaded(relationName, null)) {
                    IApplication app = dal.getApplication();
                    ((IDisplayData) renderer).setValueObject(null);
                    // $NON-NLS-1$ //$NON-NLS-2$
                    String key = row + "_" + relationName + "_" + null;
                    if (!rowAndDataprovider.contains(key)) {
                        rowAndDataprovider.add(key);
                        Runnable r = new ASynchonizedCellLoad(app, jtable, foundset, row, jtable.convertColumnIndexToModel(column), relationName, drd.getDefaultSort(), null);
                        app.getScheduledExecutor().execute(r);
                    }
                    return renderer.isVisible() ? renderer : empty;
                }
            }
            drd.setRecord(state, true);
        }
    }
    if (renderer instanceof IDisplayData) {
        if (state != null) {
            Object data = null;
            if (dataProviderID != null) {
                int index = -1;
                if (!printing && (index = dataProviderID.indexOf('.')) > 0) {
                    if (!ScopesUtils.isVariableScope(dataProviderID)) {
                        String partName = dataProviderID.substring(0, index);
                        final String restName = dataProviderID.substring(index + 1);
                        String relationName = partName;
                        if (relationName != null && !state.isRelatedFoundSetLoaded(relationName, restName)) {
                            IApplication app = dal.getApplication();
                            ((IDisplayData) renderer).setValueObject(null);
                            // $NON-NLS-1$ //$NON-NLS-2$
                            String key = row + "_" + relationName + "_" + restName;
                            if (!rowAndDataprovider.contains(key)) {
                                rowAndDataprovider.add(key);
                                List<SortColumn> defaultPKSortColumns = null;
                                try {
                                    defaultPKSortColumns = app.getFoundSetManager().getDefaultPKSortColumns(app.getFlattenedSolution().getRelation(relationName).getForeignDataSource());
                                } catch (ServoyException e) {
                                    Debug.error(e);
                                }
                                Runnable r = new ASynchonizedCellLoad(app, jtable, foundset, row, jtable.convertColumnIndexToModel(column), relationName, defaultPKSortColumns, restName);
                                app.getScheduledExecutor().execute(r);
                            }
                            return renderer.isVisible() ? renderer : empty;
                        }
                        IFoundSetInternal rfs = state.getRelatedFoundSet(relationName);
                        if (rfs != null) {
                            int selected = rfs.getSelectedIndex();
                            // should still go through record 0
                            if (selected == -1 && rfs.getSize() > 0) {
                                selected = 0;
                            }
                            final IRecordInternal relState = rfs.getRecord(selected);
                            if (testCalc(restName, relState, row, jtable.convertColumnIndexToModel(column), foundset))
                                return renderer;
                        }
                    }
                }
                if (!((IDisplayData) renderer).needEntireState() && !printing && testCalc(dataProviderID, state, row, jtable.convertColumnIndexToModel(column), foundset)) {
                    return renderer;
                }
                try {
                    data = dal.getValueObject(state, dataProviderID);
                } catch (IllegalArgumentException iae) {
                    Debug.error(iae);
                    // $NON-NLS-1$
                    data = "<conversion error>";
                }
            }
            ((IDisplayData) renderer).setTagResolver(new ITagResolver() {

                public String getStringValue(String nm) {
                    return TagResolver.formatObject(dal.getValueObject(state, nm), dal.getApplication());
                }
            });
            if (data instanceof DbIdentValue) {
                data = ((DbIdentValue) data).getPkValue();
            }
            convertAndSetValue(((IDisplayData) renderer), data);
        }
    }
    if (renderer instanceof IServoyAwareBean && state != null) {
        ((IServoyAwareBean) renderer).setSelectedRecord(new ServoyBeanState(state, dal.getFormScope()));
    }
    if (!(renderer instanceof IDisplayData) && !(renderer instanceof IDisplayRelatedData) && renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
        renderEventExecutor.fireOnRender(false);
    }
    // if the bgcolor is not changed during onRender
    if (isRenderWithOnRender && renderBgColor != null && ((RenderableWrapper) renderable).getProperty(RenderableWrapper.PROPERTY_BGCOLOR) == null) {
        renderer.setBackground(renderBgColor);
    }
    return renderer.isVisible() ? renderer : empty;
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Rectangle(java.awt.Rectangle) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) Font(java.awt.Font) ServoyException(com.servoy.j2db.util.ServoyException) IScriptRenderMethods(com.servoy.j2db.ui.IScriptRenderMethods) IDisplayRelatedData(com.servoy.j2db.dataprocessing.IDisplayRelatedData) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) RenderableWrapper(com.servoy.j2db.ui.RenderableWrapper) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ITagResolver(com.servoy.base.util.ITagResolver) Color(java.awt.Color) JComponent(javax.swing.JComponent) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) IScriptable(com.servoy.j2db.scripting.IScriptable) Point(java.awt.Point) IApplication(com.servoy.j2db.IApplication) ServoyBeanState(com.servoy.j2db.component.ServoyBeanState) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) EventObject(java.util.EventObject)

Example 4 with IScriptRenderMethods

use of com.servoy.j2db.ui.IScriptRenderMethods in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method applyStyleOnComponent.

private void applyStyleOnComponent(Component comp, Object bgColor, Object fgColor, Object compFont, Object listItemBorder) {
    if (comp instanceof IScriptableProvider) {
        IScriptable s = ((IScriptableProvider) comp).getScriptObject();
        if (s instanceof IRuntimeComponent) {
            IRuntimeComponent sbm = (IRuntimeComponent) s;
            RenderableWrapper sbmRW = null;
            if (s instanceof ISupportOnRenderCallback) {
                IScriptRenderMethods sr = ((ISupportOnRenderCallback) s).getRenderable();
                if (sr instanceof RenderableWrapper)
                    sbmRW = (RenderableWrapper) sr;
            }
            if (bgColor != null) {
                if (sbmRW != null)
                    sbmRW.clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
                String oldColor = sbm.getBgcolor();
                sbm.setBgcolor(bgColor.toString());
                if (sbm instanceof AbstractRuntimeBaseComponent && ((AbstractRuntimeBaseComponent) sbm).getComponent() instanceof WebDataLookupField) {
                    ((WebDataLookupField) ((AbstractRuntimeBaseComponent) sbm).getComponent()).setListColor(PersistHelper.createColor(oldColor));
                }
                if (sbm.isTransparent()) {
                    // apply the bg color even if transparent by clearing the transparent flag in the property changes map
                    if (comp instanceof IProviderStylePropertyChanges && ((IProviderStylePropertyChanges) comp).getStylePropertyChanges() instanceof IStylePropertyChangesRecorder) {
                        ((IStylePropertyChangesRecorder) (((IProviderStylePropertyChanges) comp).getStylePropertyChanges())).setTransparent(false);
                    }
                }
            } else {
                if (sbmRW != null && !Utils.equalObjects(sbmRW.getOnRenderSetProperties().get(RenderableWrapper.PROPERTY_BGCOLOR), sbm.getBgcolor()))
                    sbmRW.clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
                sbm.setBgcolor(sbm.getBgcolor());
                setParentBGcolor(comp, "");
            }
            if (fgColor != null) {
                if (sbmRW != null)
                    sbmRW.clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
                sbm.setFgcolor(fgColor.toString());
            } else {
                if (sbmRW != null && !Utils.equalObjects(sbmRW.getOnRenderSetProperties().get(RenderableWrapper.PROPERTY_FGCOLOR), sbm.getFgcolor())) {
                    sbmRW.clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
                }
                sbm.setFgcolor(sbm.getFgcolor());
            }
            if (compFont != null) {
                if (sbmRW != null && !Utils.equalObjects(sbmRW.getOnRenderSetProperties().get(RenderableWrapper.PROPERTY_FONT), sbm.getFont()))
                    sbmRW.clearProperty(RenderableWrapper.PROPERTY_FONT);
                sbm.setFont(compFont.toString());
            } else {
                if (sbmRW != null)
                    sbmRW.clearProperty(RenderableWrapper.PROPERTY_FONT);
                sbm.setFont(sbm.getFont());
            }
            if (listItemBorder != null) {
                // TODO left / right part of this list item border should only be applied on first / last components in the row (for table view)
                // like it is done in servoy.js when client side styling is used
                String newBorder = listItemBorder.toString();
                Border currentBorder = ComponentFactoryHelper.createBorder(sbm.getBorder());
                Border marginBorder = null;
                if (currentBorder instanceof EmptyBorder) {
                    marginBorder = currentBorder;
                } else if (currentBorder instanceof CompoundBorder && ((CompoundBorder) currentBorder).getInsideBorder() instanceof EmptyBorder) {
                    marginBorder = ((CompoundBorder) currentBorder).getInsideBorder();
                }
                if (marginBorder != null) {
                    newBorder = ComponentFactoryHelper.createBorderString(BorderFactory.createCompoundBorder(ComponentFactoryHelper.createBorder(newBorder), marginBorder));
                }
                if (sbmRW != null)
                    sbmRW.clearProperty(RenderableWrapper.PROPERTY_BORDER);
                sbm.setBorder(newBorder);
                // reset size so the web size will be recalculated based on the new border
                sbm.setSize(sbm.getWidth(), sbm.getHeight());
            } else {
                if (sbmRW != null && !Utils.equalObjects(sbmRW.getOnRenderSetProperties().get(RenderableWrapper.PROPERTY_BORDER), sbm.getBorder()))
                    sbmRW.clearProperty(RenderableWrapper.PROPERTY_BORDER);
                sbm.setBorder(sbm.getBorder());
            }
        }
    }
}
Also used : ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IScriptable(com.servoy.j2db.scripting.IScriptable) IScriptRenderMethods(com.servoy.j2db.ui.IScriptRenderMethods) AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) RenderableWrapper(com.servoy.j2db.ui.RenderableWrapper) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) CompoundBorder(javax.swing.border.CompoundBorder) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) EmptyBorder(javax.swing.border.EmptyBorder) IStylePropertyChangesRecorder(com.servoy.j2db.ui.IStylePropertyChangesRecorder) Border(javax.swing.border.Border) CompoundBorder(javax.swing.border.CompoundBorder) TitledBorder(javax.swing.border.TitledBorder) EmptyBorder(javax.swing.border.EmptyBorder)

Aggregations

IScriptRenderMethods (com.servoy.j2db.ui.IScriptRenderMethods)4 RenderableWrapper (com.servoy.j2db.ui.RenderableWrapper)4 RenderEventExecutor (com.servoy.j2db.ui.RenderEventExecutor)3 IScriptable (com.servoy.j2db.scripting.IScriptable)2 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)2 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)2 ITagResolver (com.servoy.base.util.ITagResolver)1 IApplication (com.servoy.j2db.IApplication)1 ComponentFormat (com.servoy.j2db.component.ComponentFormat)1 ServoyBeanState (com.servoy.j2db.component.ServoyBeanState)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 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)1 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)1 DbIdentValue (com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue)1 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)1 IProviderStylePropertyChanges (com.servoy.j2db.ui.IProviderStylePropertyChanges)1 IStylePropertyChangesRecorder (com.servoy.j2db.ui.IStylePropertyChangesRecorder)1