Search in sources :

Example 1 with AbstractRuntimeBaseComponent

use of com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent 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)

Example 2 with AbstractRuntimeBaseComponent

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

the class CellNativeJavaObject method get.

@Override
public Object get(String name, Scriptable start) {
    Object val = super.get(name, start);
    if (val instanceof Function) {
        if ("requestFocus".equals(name)) {
            // must remember to request focus for the according cell in the cell view...
            // when that cell's component is created
            view.setColumnThatRequestsFocus(uiComponent);
            val = new BaseFunction();
        } else if ("putClientProperty".equals(name) && javaObject instanceof AbstractRuntimeBaseComponent) {
            // put client properties for all elements in table view
            val = new WebCellBasedViewPutClientPropertyFunction(view, ((AbstractRuntimeBaseComponent<?>) javaObject).getPersist(), (Function) val);
        } else if ("getClientProperty".equals(name) && javaObject instanceof AbstractRuntimeBaseComponent) {
            // put client properties for all elements in table view
            val = new WebCellBasedViewGetClientPropertyFunction(view, ((AbstractRuntimeBaseComponent<?>) javaObject).getPersist(), (Function) val);
        }
    }
    return val;
}
Also used : BaseFunction(org.mozilla.javascript.BaseFunction) Function(org.mozilla.javascript.Function) BaseFunction(org.mozilla.javascript.BaseFunction) AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ITwoNativeJavaObject(com.servoy.j2db.scripting.ITwoNativeJavaObject)

Aggregations

AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)2 IScriptable (com.servoy.j2db.scripting.IScriptable)1 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)1 ITwoNativeJavaObject (com.servoy.j2db.scripting.ITwoNativeJavaObject)1 IProviderStylePropertyChanges (com.servoy.j2db.ui.IProviderStylePropertyChanges)1 IScriptRenderMethods (com.servoy.j2db.ui.IScriptRenderMethods)1 IStylePropertyChangesRecorder (com.servoy.j2db.ui.IStylePropertyChangesRecorder)1 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)1 RenderableWrapper (com.servoy.j2db.ui.RenderableWrapper)1 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)1 Border (javax.swing.border.Border)1 CompoundBorder (javax.swing.border.CompoundBorder)1 EmptyBorder (javax.swing.border.EmptyBorder)1 TitledBorder (javax.swing.border.TitledBorder)1 BaseFunction (org.mozilla.javascript.BaseFunction)1 Function (org.mozilla.javascript.Function)1 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)1