Search in sources :

Example 16 with IScriptable

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

the class ScrollResponseHeaderContainer method getRowSelectionScript.

public String getRowSelectionScript(List<Integer> indexToUpdate) {
    if (currentData == null)
        return null;
    if (!hasOnRender() && (bgColorScript != null || hasOddEvenSelected()) && indexToUpdate != null) {
        int firstRow = table.isPageableMode() ? table.getCurrentPage() * table.getRowsPerPage() : table.getStartIndex();
        int lastRow = firstRow + table.getViewSize() - 1;
        int[] newSelectedIndexes = getSelectedIndexes();
        AppendingStringBuffer sab = new AppendingStringBuffer();
        for (int rowIdx : indexToUpdate) {
            ArrayList<String> bgRuntimeColorjsArray = new ArrayList<String>();
            ArrayList<String> fgRuntimeColorjsArray = new ArrayList<String>();
            ArrayList<String> fstyleJsAray = new ArrayList<String>();
            ArrayList<String> fweightJsAray = new ArrayList<String>();
            ArrayList<String> fsizeJsAray = new ArrayList<String>();
            ArrayList<String> ffamilyJsAray = new ArrayList<String>();
            ArrayList<String> bstyleJsAray = new ArrayList<String>();
            ArrayList<String> bwidthJsAray = new ArrayList<String>();
            ArrayList<String> bcolorJsAray = new ArrayList<String>();
            if (rowIdx >= firstRow && rowIdx <= lastRow) {
                ListItem<IRecordInternal> selectedListItem = (ListItem<IRecordInternal>) table.get(Integer.toString(rowIdx));
                if (selectedListItem != null) {
                    String selectedId = selectedListItem.getMarkupId();
                    boolean isSelected = Arrays.binarySearch(newSelectedIndexes, rowIdx) >= 0;
                    // IF ONLY SELCTED STYLE RULE is defined then apply runtimeComonent style properties
                    if (bgColorScript == null && !isSelected && (getRowOddStyle().getAttributeCount() == 0) && (getRowEvenStyle().getAttributeCount() == 0)) {
                        Iterable<? extends Component> it = Utils.iterate(selectedListItem.iterator());
                        Component cellContents;
                        for (Component c : it) {
                            if (c instanceof CellContainer) {
                                CellContainer cell = (CellContainer) c;
                                cellContents = cell.iterator().next();
                            } else {
                                cellContents = c;
                            }
                            if (cellContents instanceof IScriptableProvider) {
                                IScriptable scriptableComponent = ((IScriptableProvider) cellContents).getScriptObject();
                                if (scriptableComponent instanceof IRuntimeComponent) {
                                    IRuntimeComponent runtimeComponent = (IRuntimeComponent) scriptableComponent;
                                    // bgcolor
                                    bgRuntimeColorjsArray.add(runtimeComponent.getBgcolor());
                                    // fgcolor
                                    fgRuntimeColorjsArray.add(runtimeComponent.getFgcolor());
                                    // font style
                                    String fontStyle = runtimeComponent.getFont();
                                    StringBuilder // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                                    fstyle = new StringBuilder(""), // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                                    fweight = new StringBuilder(""), // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                                    fsize = new StringBuilder(""), // $NON-NLS-1$
                                    ffamily = new StringBuilder("");
                                    splitFontStyle(fontStyle, fstyle, fweight, fsize, ffamily);
                                    fstyleJsAray.add(fstyle.toString());
                                    fweightJsAray.add(fweight.toString());
                                    fsizeJsAray.add(fsize.toString());
                                    ffamilyJsAray.add(ffamily.toString());
                                    // border style
                                    String borderStyle = runtimeComponent.getBorder();
                                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                                    StringBuilder bstyle = new StringBuilder(""), bwidth = new StringBuilder(""), bcolor = new StringBuilder("");
                                    splitBorderStyle(borderStyle, bstyle, bwidth, bcolor);
                                    bstyleJsAray.add(bstyle.toString());
                                    bwidthJsAray.add(bwidth.toString());
                                    bcolorJsAray.add(bcolor.toString());
                                }
                            }
                        }
                    }
                    String selectedColor = null, selectedFgColor = null, selectedFont = null, selectedBorder = null;
                    selectedColor = getListItemBgColor(selectedListItem, isSelected, true);
                    if (!isListViewMode()) {
                        selectedFgColor = getListItemFgColor(selectedListItem, isSelected, true);
                        selectedFont = getListItemFont(selectedListItem, isSelected);
                        selectedBorder = getListItemBorder(selectedListItem, isSelected);
                    }
                    // $NON-NLS-1$
                    selectedColor = (selectedColor == null ? "" : selectedColor.toString());
                    // $NON-NLS-1$
                    selectedFgColor = (selectedFgColor == null) ? "" : selectedFgColor.toString();
                    // font styles
                    StringBuilder // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                    fstyle = new StringBuilder(""), // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                    fweight = new StringBuilder(""), // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                    fsize = new StringBuilder(""), // $NON-NLS-1$
                    ffamily = new StringBuilder("");
                    splitFontStyle(selectedFont, fstyle, fweight, fsize, ffamily);
                    // border styles
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    StringBuilder bstyle = new StringBuilder(""), bwidth = new StringBuilder(""), bcolor = new StringBuilder("");
                    splitBorderStyle(selectedBorder, bstyle, bwidth, bcolor);
                    if (bgColorScript == null && !isSelected && (getRowOddStyle().getAttributeCount() == 0) && (getRowEvenStyle().getAttributeCount() == 0) && !isListViewMode()) {
                        // backgroundcolor and color are sent as final inline string
                        // $NON-NLS-1$
                        sab.append("Servoy.TableView.setRowStyle('").append(selectedId).append(// $NON-NLS-1$
                        "', ").append(toJsArrayString(bgRuntimeColorjsArray, "background-color:")).append(// $NON-NLS-1$
                        ",").append(toJsArrayString(fgRuntimeColorjsArray, "color:")).append(// $NON-NLS-1$
                        ",").append(toJsArrayString(fstyleJsAray, "")).append(// $NON-NLS-1$
                        ", ").append(toJsArrayString(fweightJsAray, "")).append(// $NON-NLS-1$
                        ", ").append(toJsArrayString(fsizeJsAray, "")).append(// $NON-NLS-1$
                        ", ").append(toJsArrayString(ffamilyJsAray, "")).append(// $NON-NLS-1$
                        ", ").append(toJsArrayString(bstyleJsAray, "")).append(// $NON-NLS-1$
                        ", ").append(toJsArrayString(bwidthJsAray, "")).append(// $NON-NLS-1$
                        ",").append(toJsArrayString(bcolorJsAray, "")).append(// $NON-NLS-1$
                        ",").append(isListViewMode()).append(// $NON-NLS-1$
                        ");\n");
                    } else {
                        // $NON-NLS-1$
                        sab.append("Servoy.TableView.setRowStyle('").append(selectedId).append(// $NON-NLS-1$
                        "', '").append(selectedColor).append(// $NON-NLS-1$
                        "', '").append(selectedFgColor).append(// $NON-NLS-1$
                        "', '").append(fstyle).append(// $NON-NLS-1$
                        "', '").append(fweight).append(// $NON-NLS-1$
                        "', '").append(fsize).append(// $NON-NLS-1$
                        "', '").append(ffamily).append(// $NON-NLS-1$
                        "', '").append(bstyle).append(// $NON-NLS-1$
                        "', '").append(bwidth).append(// $NON-NLS-1$
                        "', '").append(bcolor).append(// $NON-NLS-1$
                        "', ").append(isListViewMode()).append(// $NON-NLS-1$
                        ");\n");
                    }
                }
            }
        }
        String rowSelectionScript = sab.toString();
        if (rowSelectionScript.length() > 0)
            return rowSelectionScript;
    }
    return null;
}
Also used : AppendingStringBuffer(org.apache.wicket.util.string.AppendingStringBuffer) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ArrayList(java.util.ArrayList) Point(java.awt.Point) IScriptable(com.servoy.j2db.scripting.IScriptable) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) ListItem(org.apache.wicket.markup.html.list.ListItem) IComponent(com.servoy.j2db.ui.IComponent) AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 17 with IScriptable

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

the class ScrollResponseHeaderContainer method hasOnRender.

private boolean hasOnRender() {
    if (hasOnRender == null) {
        hasOnRender = new Boolean(false);
        if (dataRendererOnRenderWrapper.getRenderEventExecutor().hasRenderCallback()) {
            hasOnRender = new Boolean(true);
        } else {
            Iterator<Component> compIte = elementToColumnIdentifierComponent.values().iterator();
            Component comp;
            while (compIte.hasNext()) {
                comp = compIte.next();
                if (comp instanceof IScriptableProvider) {
                    IScriptable s = ((IScriptableProvider) comp).getScriptObject();
                    if (s instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) s).getRenderEventExecutor().hasRenderCallback()) {
                        hasOnRender = new Boolean(true);
                        break;
                    }
                }
            }
        }
    }
    return hasOnRender.booleanValue();
}
Also used : ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IComponent(com.servoy.j2db.ui.IComponent) AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 18 with IScriptable

use of com.servoy.j2db.scripting.IScriptable 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 19 with IScriptable

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

the class JSDatabaseManager method js_executeStoredProcedure.

/**
 * @deprecated As of release 3.5, replaced by {@link plugins.rawSQL#executeStoredProcedure(String, String, Object[], int[], int)}.
 */
@Deprecated
public Object js_executeStoredProcedure(String serverName, String procedureDeclaration, Object[] args, int[] inOutType, int maxNumberOfRowsToRetrieve) throws ServoyException {
    checkAuthorized();
    // $NON-NLS-1$
    IClientPlugin cp = application.getPluginManager().getPlugin(IClientPlugin.class, "rawSQL");
    if (cp != null) {
        IScriptable so = cp.getScriptObject();
        if (so != null) {
            try {
                Method m = // $NON-NLS-1$
                so.getClass().getMethod(// $NON-NLS-1$
                "js_executeStoredProcedure", new Class[] { String.class, String.class, Object[].class, int[].class, int.class });
                return m.invoke(so, new Object[] { serverName, procedureDeclaration, args, inOutType, new Integer(maxNumberOfRowsToRetrieve) });
            } catch (Exception e) {
                Debug.error(e);
            }
        }
    }
    // $NON-NLS-1$
    application.reportError(// $NON-NLS-1$
    "Writing to file failed", // $NON-NLS-1$
    "For this operation the file plugin is needed\nNote this method is deprecated, use the plugin directly in your code");
    return null;
}
Also used : IClientPlugin(com.servoy.j2db.plugins.IClientPlugin) NativeObject(org.mozilla.javascript.NativeObject) Method(java.lang.reflect.Method) IScriptable(com.servoy.j2db.scripting.IScriptable) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) SQLException(java.sql.SQLException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Aggregations

IScriptable (com.servoy.j2db.scripting.IScriptable)19 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)17 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)11 IComponent (com.servoy.j2db.ui.IComponent)9 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)9 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)6 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)6 RenderEventExecutor (com.servoy.j2db.ui.RenderEventExecutor)6 Component (org.apache.wicket.Component)6 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)5 JComponent (javax.swing.JComponent)5 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)4 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)4 BaseComponent (com.servoy.j2db.persistence.BaseComponent)4 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)4 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)4 Point (java.awt.Point)4 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)3 ISupportOnRender (com.servoy.j2db.ui.ISupportOnRender)3 EventObject (java.util.EventObject)3