Search in sources :

Example 11 with IRuntimeComponent

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

the class AbstractRuntimeField method setVisible.

@Override
public void setVisible(boolean b) {
    if (isVisible() != b) {
        if (getComponent().isViewable()) {
            List<ILabel> labels = getComponent().getLabelsFor();
            if (labels != null) {
                for (int i = 0; i < labels.size(); i++) {
                    ILabel label = labels.get(i);
                    IScriptable scriptable = label.getScriptObject();
                    if (scriptable instanceof IRuntimeComponent) {
                        ((IRuntimeComponent) scriptable).setVisible(b);
                    } else {
                        label.setComponentVisible(b);
                    }
                }
            }
        }
        super.setVisible(b);
    }
}
Also used : ILabel(com.servoy.j2db.ui.ILabel) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 12 with IRuntimeComponent

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

the class CellAdapter method getBgColor.

private Color getBgColor(JTable jtable, boolean isSelected, int row, boolean isEdited) {
    Color bgColor = null;
    IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
    boolean specialStateCase = (state instanceof PrototypeState || state instanceof FindState || state == null || state.getRawData() == null);
    if (/* !(renderer instanceof JButton) && */
    !specialStateCase) {
        ISwingFoundSet foundset = (ISwingFoundSet) jtable.getModel();
        bgColor = (Color) getStyleAttributeForRow(jtable, isSelected, row, ISupportRowStyling.ATTRIBUTE.BGCOLOR);
        String strRowBGColorProvider = null;
        List<Object> rowBGColorArgs = null;
        if (jtable instanceof IView) {
            strRowBGColorProvider = ((IView) jtable).getRowBGColorScript();
            rowBGColorArgs = ((IView) jtable).getRowBGColorArgs();
        }
        // $NON-NLS-1$
        if (strRowBGColorProvider == null)
            strRowBGColorProvider = "servoy_row_bgcolor";
        boolean isRowBGColorCalculation = state.getRawData().containsCalculation(strRowBGColorProvider);
        if (// $NON-NLS-1$
        !isRowBGColorCalculation && strRowBGColorProvider.equals("servoy_row_bgcolor")) {
            // $NON-NLS-1$
            strRowBGColorProvider = "";
        }
        if (// $NON-NLS-1$
        strRowBGColorProvider != null && !"".equals(strRowBGColorProvider)) {
            Object bg_color = null;
            // TODO this should be done better....
            Record.VALIDATE_CALCS.set(Boolean.FALSE);
            try {
                String type = (editor instanceof IScriptableProvider && ((IScriptableProvider) editor).getScriptObject() instanceof IRuntimeComponent) ? ((IRuntimeComponent) ((IScriptableProvider) editor).getScriptObject()).getElementType() : null;
                String nm = (editor instanceof IDisplayData) ? ((IDisplayData) editor).getDataProviderID() : null;
                if (isRowBGColorCalculation) {
                    bg_color = foundset.getCalculationValue(state, strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(row), new Boolean(isSelected), type, nm, new Boolean(isEdited) }), Utils.parseJSExpressions(rowBGColorArgs)), null);
                } else {
                    try {
                        FormController currentForm = dal.getFormController();
                        bg_color = currentForm.executeFunction(strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(row), new Boolean(isSelected), type, nm, currentForm.getName(), state, new Boolean(isEdited) }), Utils.parseJSExpressions(rowBGColorArgs)), false, null, true, null);
                    } catch (Exception ex) {
                        Debug.error(ex);
                    }
                }
            } finally {
                Record.VALIDATE_CALCS.set(null);
            }
            if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
                bgColor = PersistHelper.createColor(bg_color.toString());
            }
        }
    }
    return bgColor;
}
Also used : FormController(com.servoy.j2db.FormController) Undefined(org.mozilla.javascript.Undefined) IView(com.servoy.j2db.IView) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Color(java.awt.Color) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) ServoyException(com.servoy.j2db.util.ServoyException) ParseException(java.text.ParseException) ApplicationException(com.servoy.j2db.ApplicationException) FindState(com.servoy.j2db.dataprocessing.FindState) EventObject(java.util.EventObject) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 13 with IRuntimeComponent

use of com.servoy.j2db.ui.runtime.IRuntimeComponent 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 14 with IRuntimeComponent

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

the class WebEventExecutor method setRightClickCmd.

@Override
public void setRightClickCmd(String id, Object[] args) {
    if (id != null && useAJAX) {
        if (component instanceof ILabel || component instanceof IFieldComponent || component instanceof SortableCellViewHeader) {
            String sharedName = "Cmd";
            if (component instanceof SortableCellViewHeader) {
                sharedName = null;
            }
            component.add(new // $NON-NLS-1$
            ServoyAjaxEventBehavior(// $NON-NLS-1$
            "oncontextmenu", // $NON-NLS-1$
            sharedName, // $NON-NLS-1$
            true) {

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    WebEventExecutor.this.onEvent(JSEvent.EventType.rightClick, target, component, Utils.getAsInteger(RequestCycle.get().getRequest().getParameter(IEventExecutor.MODIFIERS_PARAMETER)), new // $NON-NLS-1$
                    Point(// $NON-NLS-1$
                    Utils.getAsInteger(RequestCycle.get().getRequest().getParameter("mx")), // $NON-NLS-1$
                    Utils.getAsInteger(RequestCycle.get().getRequest().getParameter("my"))), new Point(Utils.getAsInteger(RequestCycle.get().getRequest().getParameter("glx")), // $NON-NLS-1$
                    Utils.getAsInteger(RequestCycle.get().getRequest().getParameter("gly"))));
                }

                @Override
                protected CharSequence generateCallbackScript(final CharSequence partialCall) {
                    return super.generateCallbackScript(// $NON-NLS-1$
                    partialCall + "+Servoy.Utils.getActionParams(event," + ((component instanceof SortableCellViewHeader) ? "true" : "false") + ")");
                }

                @Override
                public boolean isEnabled(Component comp) {
                    if (super.isEnabled(comp)) {
                        if (comp instanceof IScriptableProvider && ((IScriptableProvider) comp).getScriptObject() instanceof IRuntimeComponent) {
                            // $NON-NLS-1$
                            Object oe = ((IRuntimeComponent) ((IScriptableProvider) comp).getScriptObject()).getClientProperty("ajax.enabled");
                            if (oe != null)
                                return Utils.getAsBoolean(oe);
                        }
                        return true;
                    }
                    return false;
                }

                // We need to return false, otherwise the context menu of the browser is displayed.
                @Override
                protected IAjaxCallDecorator getAjaxCallDecorator() {
                    return new AjaxCallDecorator() {

                        @Override
                        public CharSequence decorateScript(CharSequence script) {
                            // $NON-NLS-1$
                            return script + " return false;";
                        }
                    };
                }
            });
        }
    }
    super.setRightClickCmd(id, args);
}
Also used : IAjaxCallDecorator(org.apache.wicket.ajax.IAjaxCallDecorator) AjaxCallDecorator(org.apache.wicket.ajax.calldecorator.AjaxCallDecorator) IAjaxCallDecorator(org.apache.wicket.ajax.IAjaxCallDecorator) ILabel(com.servoy.j2db.ui.ILabel) Point(java.awt.Point) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CloseableAjaxRequestTarget(com.servoy.j2db.server.headlessclient.CloseableAjaxRequestTarget) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) IComponent(com.servoy.j2db.ui.IComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 15 with IRuntimeComponent

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

the class ScrollResponseHeaderContainer method distributeExtraSpace.

/**
 * Distributes an amount of horizontal free space to some or the columns of the table.
 *
 * Can be called in two situations:
 *
 * 1. When the browser windows is resized.
 *
 * In this case the positive/negative extra space gets distributed to those columns that are
 * anchored left + right.
 *
 * 2. When a column is resized
 *
 * In this case the positive/negative extra space gets distributed to all other columns,
 * regardless of their anchoring.
 *
 * In both scenarios the extra space is distributed proportionally to the sizes of the
 * involved columns.
 */
private void distributeExtraSpace(int delta, int totalWidthToStretch, IPersist dontTouchThis, boolean onlyAnchoredColumns) {
    if (totalWidthToStretch == 0)
        return;
    int consumedDelta = 0;
    IRuntimeComponent lastStretched = null;
    for (IPersist element : elementToColumnIdentifierComponent.keySet()) {
        boolean distributeToThisColumn = true;
        if (dontTouchThis != null && element.equals(dontTouchThis))
            distributeToThisColumn = false;
        if (distributeToThisColumn && onlyAnchoredColumns) {
            if (element instanceof ISupportAnchors) {
                int anchors = ((ISupportAnchors) element).getAnchors();
                if (((anchors & IAnchorConstants.EAST) == 0) || ((anchors & IAnchorConstants.WEST) == 0))
                    distributeToThisColumn = false;
            } else
                distributeToThisColumn = false;
        }
        if (distributeToThisColumn) {
            Component c = elementToColumnIdentifierComponent.get(element);
            if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeComponent && c.isVisible()) {
                IRuntimeComponent ic = (IRuntimeComponent) ((IScriptableProvider) c).getScriptObject();
                int thisDelta = delta * ic.getWidth() / totalWidthToStretch;
                consumedDelta += thisDelta;
                int newWidth = ic.getWidth() + thisDelta;
                int height = ic.getHeight();
                Iterator<Component> alreadyAddedComponents = cellToElement.keySet().iterator();
                if (alreadyAddedComponents.hasNext()) {
                    Component firstAddedComponent = alreadyAddedComponents.next();
                    if ((firstAddedComponent instanceof IComponent))
                        height = ((IComponent) firstAddedComponent).getSize().height;
                }
                ic.setSize(newWidth, height);
                lastStretched = ic;
            }
        }
    }
    // we can have some leftover due to rounding errors, just put it into the last stretched column.
    if ((delta - consumedDelta != 0) && (lastStretched != null)) {
        lastStretched.setSize(lastStretched.getWidth() + delta - consumedDelta, lastStretched.getHeight());
    }
    updateXLocationForColumns(getOrderedHeaders());
}
Also used : ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IPersist(com.servoy.j2db.persistence.IPersist) IComponent(com.servoy.j2db.ui.IComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) 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) Point(java.awt.Point)

Aggregations

IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)20 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)15 IComponent (com.servoy.j2db.ui.IComponent)10 Point (java.awt.Point)10 Component (org.apache.wicket.Component)9 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)6 BaseComponent (com.servoy.j2db.persistence.BaseComponent)5 IScriptable (com.servoy.j2db.scripting.IScriptable)5 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)5 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)4 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)4 IPersist (com.servoy.j2db.persistence.IPersist)3 IProviderStylePropertyChanges (com.servoy.j2db.ui.IProviderStylePropertyChanges)3 IRuntimeInputComponent (com.servoy.j2db.ui.runtime.IRuntimeInputComponent)3 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)2 RuntimeGroup (com.servoy.j2db.scripting.RuntimeGroup)2 ILabel (com.servoy.j2db.ui.ILabel)2 ISupportWebBounds (com.servoy.j2db.ui.ISupportWebBounds)2