Search in sources :

Example 6 with IStyleSheet

use of com.servoy.j2db.util.IStyleSheet in project servoy-client by Servoy.

the class ComponentFactory method createGraphicalComponent.

private static IComponent createGraphicalComponent(IApplication application, Form form, GraphicalComponent label, IScriptExecuter el, IDataProviderLookup dataProviderLookup) {
    int style_halign = -1;
    int style_valign = -1;
    int textTransform = 0;
    int mediaid = 0;
    Pair<IStyleSheet, IStyleRule> styleInfo = getStyleForBasicComponent(application, label, form);
    if (styleInfo != null) {
        IStyleSheet ss = styleInfo.getLeft();
        IStyleRule s = styleInfo.getRight();
        if (ss != null && s != null) {
            style_valign = ss.getVAlign(s);
            style_halign = ss.getHAlign(s);
            boolean parseMedia = true;
            // anything else then then the css through the templategenerator is used. (See TemplateGenerator.createGraphicalComponentHTML)
            if (application.getApplicationType() == IApplication.WEB_CLIENT) {
                parseMedia = s.getValue(CSS.Attribute.BACKGROUND_REPEAT.toString()) == null && s.getValue(CSS.Attribute.BACKGROUND_POSITION.toString()) == null;
            }
            if (parseMedia) {
                Object mediaUrl = s.getValue(CSS.Attribute.BACKGROUND_IMAGE.toString());
                if (mediaUrl != null && mediaUrl.toString() != null) {
                    String mediaUrlString = mediaUrl.toString();
                    int start = mediaUrlString.indexOf(MediaURLStreamHandler.MEDIA_URL_DEF);
                    if (start != -1) {
                        String name = mediaUrlString.substring(start + MediaURLStreamHandler.MEDIA_URL_DEF.length());
                        if (name.endsWith("')") || name.endsWith("\")"))
                            name = name.substring(0, name.length() - 2);
                        if (name.endsWith(")"))
                            name = name.substring(0, name.length() - 1);
                        Media media = application.getFlattenedSolution().getMedia(name);
                        if (media != null) {
                            mediaid = media.getID();
                        }
                    }
                }
            }
            String transform = s.getValue(CSS.Attribute.TEXT_TRANSFORM.toString());
            if (transform != null) {
                if ("uppercase".equals(transform)) {
                    textTransform = ILabel.UPPERCASE;
                } else if ("lowercase".equals(transform)) {
                    textTransform = ILabel.LOWERCASE;
                } else if ("capitalize".equals(transform)) {
                    textTransform = ILabel.CAPITALIZE;
                }
            }
        }
    }
    ILabel l;
    AbstractRuntimeLabel<? extends ILabel> scriptable;
    IStylePropertyChangesRecorder jsChangeRecorder = application.getItemFactory().createChangesRecorder();
    if (ComponentFactory.isButton(label)) {
        IButton button;
        if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
            scriptable = new RuntimeScriptButton(jsChangeRecorder, application);
            button = application.getItemFactory().createScriptButton((RuntimeScriptButton) scriptable, getWebID(form, label));
        } else {
            scriptable = new RuntimeDataButton(jsChangeRecorder, application);
            button = application.getItemFactory().createDataButton((RuntimeDataButton) scriptable, getWebID(form, label));
            IDataProvider dp = null;
            try {
                dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
            } catch (RepositoryException e) {
                Debug.error(e);
            }
            ((IDisplayData) button).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
            ((IDisplayTagText) button).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
            ((IDisplayData) button).setNeedEntireState(label.getDisplaysTags());
        }
        ((AbstractRuntimeButton<IButton>) scriptable).setComponent(button, label);
        button.setMediaOption(label.getMediaOptions());
        if (label.getRolloverImageMediaID() > 0) {
            try {
                button.setRolloverIcon(label.getRolloverImageMediaID());
                button.setRolloverEnabled(true);
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
        l = button;
    } else {
        if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
            scriptable = new RuntimeScriptLabel(jsChangeRecorder, application);
            l = application.getItemFactory().createScriptLabel((RuntimeScriptLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
        } else {
            scriptable = new RuntimeDataLabel(jsChangeRecorder, application);
            l = application.getItemFactory().createDataLabel((RuntimeDataLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
            IDataProvider dp = null;
            try {
                dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
            } catch (RepositoryException e) {
                Debug.error(e);
            }
            ((IDisplayData) l).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
            ((IDisplayTagText) l).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
            ((IDisplayData) l).setNeedEntireState(label.getDisplaysTags());
        }
        ((AbstractHTMLSubmitRuntimeLabel<ILabel>) scriptable).setComponent(l, label);
        l.setMediaOption(label.getMediaOptions());
        if (label.getRolloverImageMediaID() > 0) {
            try {
                l.setRolloverIcon(label.getRolloverImageMediaID());
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
    }
    String mnemonic = application.getI18NMessageIfPrefixed(label.getMnemonic());
    if (mnemonic != null && mnemonic.length() > 0) {
        l.setDisplayedMnemonic(mnemonic.charAt(0));
    }
    l.setTextTransform(textTransform);
    if (el != null && (label.getOnActionMethodID() > 0 || label.getOnDoubleClickMethodID() > 0 || label.getOnRightClickMethodID() > 0)) {
        l.addScriptExecuter(el);
        if (label.getOnActionMethodID() > 0)
            l.setActionCommand(Integer.toString(label.getOnActionMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onActionMethodID")));
        if (label.getOnDoubleClickMethodID() > 0)
            l.setDoubleClickCommand(Integer.toString(label.getOnDoubleClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onDoubleClickMethodID")));
        if (label.getOnRightClickMethodID() > 0)
            l.setRightClickCommand(Integer.toString(label.getOnRightClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onRightClickMethodID")));
    }
    if (label.getLabelFor() == null || (form.getView() != FormController.TABLE_VIEW && form.getView() != FormController.LOCKED_TABLE_VIEW)) {
        int onRenderMethodID = label.getOnRenderMethodID();
        AbstractBase onRenderPersist = label;
        if (onRenderMethodID <= 0) {
            onRenderMethodID = form.getOnRenderMethodID();
            onRenderPersist = form;
        }
        if (onRenderMethodID > 0) {
            RenderEventExecutor renderEventExecutor = scriptable.getRenderEventExecutor();
            renderEventExecutor.setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(onRenderPersist.getFlattenedMethodArguments("onRenderMethodID")));
            IForm rendererForm = application.getFormManager().getForm(form.getName());
            IScriptExecuter rendererScriptExecuter = rendererForm instanceof FormController ? ((FormController) rendererForm).getScriptExecuter() : null;
            renderEventExecutor.setRenderScriptExecuter(rendererScriptExecuter);
        }
    }
    l.setRotation(label.getRotation());
    l.setFocusPainted(label.getShowFocus());
    l.setCursor(Cursor.getPredefinedCursor(label.getRolloverCursor()));
    try {
        int halign = label.getHorizontalAlignment();
        if (halign != -1) {
            l.setHorizontalAlignment(halign);
        } else if (style_halign != -1) {
            l.setHorizontalAlignment(style_halign);
        }
    } catch (RuntimeException e) {
    // just ignore...Debug.error(e);
    }
    int valign = label.getVerticalAlignment();
    if (valign != -1) {
        l.setVerticalAlignment(valign);
    } else if (style_valign != -1) {
        l.setVerticalAlignment(style_valign);
    }
    try {
        if (!label.getDisplaysTags()) {
            l.setText(application.getI18NMessageIfPrefixed(label.getText()));
        }
    } catch (RuntimeException e1) {
    // ignore
    }
    l.setToolTipText(application.getI18NMessageIfPrefixed(label.getToolTipText()));
    if (label.getImageMediaID() > 0) {
        try {
            l.setMediaIcon(label.getImageMediaID());
        } catch (Exception e) {
            Debug.error(e);
        }
    } else if (mediaid > 0) {
        try {
            l.setMediaIcon(mediaid);
        } catch (Exception e) {
            Debug.error(e);
        }
    }
    if (label.getDataProviderID() != null) {
        scriptable.setComponentFormat(ComponentFormat.getComponentFormat(label.getFormat(), label.getDataProviderID(), dataProviderLookup, application));
    }
    applyBasicComponentProperties(application, l, label, styleInfo);
    Border border = null;
    Insets insets = null;
    if (label.getBorderType() != null) {
        border = ComponentFactoryHelper.createBorder(label.getBorderType());
    }
    if (label.getMargin() != null) {
        insets = label.getMargin();
    }
    if (styleInfo != null && (border == null || insets == null)) {
        IStyleSheet ss = styleInfo.getLeft();
        IStyleRule s = styleInfo.getRight();
        if (ss != null && s != null) {
            if (border == null && ss.hasBorder(s)) {
                border = ss.getBorder(s);
            }
            if (insets == null && ss.hasMargin(s)) {
                insets = ss.getMargin(s);
            }
        }
    }
    if (border != null && insets != null) {
        l.setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)));
    } else if (border == null && insets != null && l instanceof IButton) {
        ((IButton) l).setMargin(insets);
    } else // supports setMargin, then fake the margins through empty border. (issue 166391)
    if (border == null && insets != null) {
        l.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
    }
    if (l instanceof IAnchoredComponent) {
        ((IAnchoredComponent) l).setAnchors(label.getAnchors());
    }
    return l;
}
Also used : Insets(java.awt.Insets) ILabel(com.servoy.j2db.ui.ILabel) RuntimeDataLabel(com.servoy.j2db.ui.scripting.RuntimeDataLabel) IForm(com.servoy.j2db.IForm) IDataProvider(com.servoy.j2db.persistence.IDataProvider) RuntimeScriptButton(com.servoy.j2db.ui.scripting.RuntimeScriptButton) FormController(com.servoy.j2db.FormController) IStyleSheet(com.servoy.j2db.util.IStyleSheet) IScriptExecuter(com.servoy.j2db.IScriptExecuter) AbstractHTMLSubmitRuntimeLabel(com.servoy.j2db.ui.scripting.AbstractHTMLSubmitRuntimeLabel) RuntimeDataButton(com.servoy.j2db.ui.scripting.RuntimeDataButton) Media(com.servoy.j2db.persistence.Media) AbstractBase(com.servoy.j2db.persistence.AbstractBase) RuntimeScriptLabel(com.servoy.j2db.ui.scripting.RuntimeScriptLabel) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSONException(org.json.JSONException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IAnchoredComponent(com.servoy.j2db.ui.IAnchoredComponent) IButton(com.servoy.j2db.ui.IButton) IStyleRule(com.servoy.j2db.util.IStyleRule) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) AbstractRuntimeButton(com.servoy.j2db.ui.scripting.AbstractRuntimeButton) IStylePropertyChangesRecorder(com.servoy.j2db.ui.IStylePropertyChangesRecorder) Border(javax.swing.border.Border) TitledBorder(javax.swing.border.TitledBorder) IDisplayTagText(com.servoy.j2db.ui.IDisplayTagText)

Example 7 with IStyleSheet

use of com.servoy.j2db.util.IStyleSheet in project servoy-client by Servoy.

the class ComponentFactory method createPortal.

private static IComponent createPortal(IApplication application, Form form, Portal meta, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
    RuntimePortal scriptable = new RuntimePortal(application.getItemFactory().createChangesRecorder(), application);
    IPortalComponent portalComponent = application.getItemFactory().createPortalComponent(scriptable, meta, form, dataProviderLookup, el, printing);
    scriptable.setComponent(portalComponent, meta);
    IStyleSheet ss = ComponentFactory.getCSSStyleForForm(application, form);
    if (ss != null) {
        String lookupname = "portal";
        if (meta.getStyleClass() != null && !"".equals(meta.getStyleClass())) {
            lookupname += '.' + meta.getStyleClass();
        }
        portalComponent.setRowStyles(ss, ss.getCSSRule(lookupname + " " + ISupportRowStyling.CLASS_ODD), ss.getCSSRule(lookupname + " " + ISupportRowStyling.CLASS_EVEN), ss.getCSSRule(lookupname + " " + ISupportRowStyling.CLASS_SELECTED), ss.getCSSRule(lookupname + " " + ISupportRowStyling.CLASS_HEADER));
    }
    return portalComponent;
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal) IPortalComponent(com.servoy.j2db.ui.IPortalComponent)

Example 8 with IStyleSheet

use of com.servoy.j2db.util.IStyleSheet in project servoy-client by Servoy.

the class FormController method createDataRenderers.

private void createDataRenderers(int viewType) throws Exception {
    int v = viewType;
    if (getDataSource() == null) {
        // form not based on any datasource
        v = LOCKED_RECORD_VIEW;
    }
    application.getDataRenderFactory().prepareRenderers(application, form);
    Part bodyPart = null;
    Map<Part, IDataRenderer> part_panels = new LinkedHashMap<Part, IDataRenderer>();
    Iterator<Part> e2 = form.getParts();
    while (e2.hasNext()) {
        Part part = e2.next();
        Color partColor = ComponentFactory.getPartBackground(application, part, form);
        // extract the body (bgcolor)
        if (part.getPartType() == Part.BODY) {
            bodyPart = part;
            bgColor = partColor;
            Pair<IStyleSheet, IStyleRule> partStyle = ComponentFactory.getStyleForBasicComponent(application, part, form);
            bodyRule = partStyle != null ? partStyle.getRight() : null;
        }
        if (part.getPartType() == Part.BODY && v == FormController.LOCKED_TABLE_VIEW) {
            // don't create part, view == part
            continue;
        }
        IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, part), part.toString(), application, (part.getPartType() == Part.BODY));
        dr.initDragNDrop(this, form.getPartStartYPos(part.getID()));
        dataRenderers[part.getPartType()] = dr;
        dr.setName(part.toString());
        part_panels.put(part, dr);
        if (part.getPartType() == Part.BODY) {
            int onRenderMethodID = form.getOnRenderMethodID();
            if (onRenderMethodID > 0) {
                dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
                dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
            }
        }
        dr.setBackground(partColor);
    }
    tabSequence.clear();
    application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), tabSequence);
    if (bodyPart != null && (v == FormController.LOCKED_LIST_VIEW || v == IForm.LIST_VIEW)) {
        IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, bodyPart), bodyPart.toString(), application, true);
        int onRenderMethodID = form.getOnRenderMethodID();
        if (onRenderMethodID > 0) {
            dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
            dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
        }
        // apply bgcolor to renderer
        if (bgColor != null) {
            dr.setBackground(bgColor);
        }
        dataRenderers[FORM_RENDERER] = dr;
        dr.setName(bodyPart.toString());
        part_panels = new LinkedHashMap<Part, IDataRenderer>();
        part_panels.put(bodyPart, dr);
        application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), null);
    }
    // apply security
    int access = application.getFlattenedSolution().getSecurityAccess(form.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
    if (access != -1) {
        boolean b_accessible = ((access & IRepository.ACCESSIBLE) != 0);
        if (!b_accessible) {
            for (IDataRenderer dataRenderer : dataRenderers) {
                if (dataRenderer != null) {
                    Iterator<? extends IComponent> componentIterator = dataRenderer.getComponentIterator();
                    while (componentIterator.hasNext()) {
                        IComponent c = componentIterator.next();
                        if (c instanceof ISupportSecuritySettings) {
                            if (!b_accessible)
                                ((ISupportSecuritySettings) c).setAccessible(b_accessible);
                        }
                    }
                }
            }
        }
    }
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) IComponent(com.servoy.j2db.ui.IComponent) Color(java.awt.Color) LinkedHashMap(java.util.LinkedHashMap) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) Part(com.servoy.j2db.persistence.Part) IStyleRule(com.servoy.j2db.util.IStyleRule) ISupportSecuritySettings(com.servoy.j2db.ui.ISupportSecuritySettings)

Example 9 with IStyleSheet

use of com.servoy.j2db.util.IStyleSheet in project servoy-client by Servoy.

the class SwingForm method initView.

public IView initView(IApplication application, FormController fp, int viewType) {
    view = null;
    IDataRenderer[] dataRenderers = fp.getDataRenderers();
    setTitleHeader((JComponent) dataRenderers[Part.TITLE_HEADER]);
    setHeader((JComponent) dataRenderers[Part.HEADER]);
    setLeadingGrandSummary((JComponent) dataRenderers[Part.LEADING_GRAND_SUMMARY]);
    setTrailingGrandSummary((JComponent) dataRenderers[Part.TRAILING_GRAND_SUMMARY]);
    setFooter((JComponent) dataRenderers[Part.FOOTER]);
    // remove any left slider
    setWest(null);
    switch(viewType) {
        case FormController.LOCKED_LIST_VIEW:
        case IForm.LIST_VIEW:
            view = new ListView();
            PrototypeState proto = null;
            if (fp.getFoundSet() != null) {
                proto = fp.getFoundSet().getPrototypeState();
            } else {
                proto = new PrototypeState(null);
            }
            // this call is extreemly inportant, it prevent all rows retrieval
            ((ListView) view).setPrototypeCellValue(proto);
            FormBodyEditor editor = null;
            if (dataRenderers[FormController.FORM_RENDERER] != null) {
                Component[] rendererComponents = ((Container) dataRenderers[FormController.FORM_RENDERER]).getComponents();
                for (Component rendererComponent : rendererComponents) {
                    if (rendererComponent instanceof ISupportAsyncLoading) {
                        // in listview it is impossible to get lazy loaded images displaying correctly, due to needed repaintfire, which we cannot initiate
                        ((ISupportAsyncLoading) rendererComponent).setAsyncLoadingEnabled(false);
                    }
                    rendererComponent.setFocusable(false);
                }
                ((Component) dataRenderers[FormController.FORM_RENDERER]).setFocusable(false);
            }
            editor = new FormBodyEditor((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
            if (dataRenderers[FormController.FORM_RENDERER] != null) {
                DataRenderer dr = (DataRenderer) dataRenderers[FormController.FORM_RENDERER];
                dr.setRenderer(true);
                String bgcolorCalc = fp.getForm().getRowBGColorCalculation();
                if (bgcolorCalc != null) {
                    // dr.setRowBGColorProvider(bgcolorCalc);
                    dr.setShowSelection(false);
                    // $NON-NLS-1$
                    ((ListView) view).setRowBGColorScript(bgcolorCalc, fp.getForm().getFlattenedMethodArguments("rowBGColorCalculation"));
                    ((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
                }
                ((ListView) view).setCellRenderer(dr);
            } else {
                // form with no body part - used only for printing probably
                ((ListView) view).setCellRenderer(new ListCellRenderer() {

                    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                        // $NON-NLS-1$
                        return new JLabel("");
                    }
                });
            }
            ((ListView) view).setCellEditor(editor);
            ((ListView) view).setRendererSameAsEditor(false);
            ((ListView) view).setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            break;
        case FormController.LOCKED_TABLE_VIEW:
        case FormController.TABLE_VIEW:
            view = new TableView(application, fp, fp.getForm(), fp.getForm(), fp.getScriptExecuter(), dataRenderers[Part.HEADER], dataRenderers[Part.LEADING_GRAND_SUMMARY], false);
            if (dataRenderers[FormController.FORM_EDITOR] != null)
                dataRenderers[FormController.FORM_EDITOR].destroy();
            dataRenderers[FormController.FORM_EDITOR] = (IDataRenderer) view;
            if (formController.getBodyStyle() != null) {
                Pair<IStyleSheet, IStyleRule> pairStyle = ComponentFactory.getCSSPairStyleForForm(application, fp.getForm());
                if (pairStyle != null && pairStyle.getLeft() != null) {
                    Border border = pairStyle.getLeft().getBorder(formController.getBodyStyle());
                    if (border != null) {
                        innerPanel.setBorder(border);
                    }
                }
            }
            break;
        case IForm.LOCKED_RECORD_VIEW:
        case IForm.RECORD_VIEW:
        default:
            view = new RecordView(formController);
            if (dataRenderers[FormController.FORM_EDITOR] != null) {
                ((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
                ((RecordView) view).setCellRenderer((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
            }
            int form_id = fp.getForm().getNavigatorID();
            if (form_id == 0) {
                StyledEnablePanel slider = ((RecordView) view).getSliderComponent();
                if (bgColor != null)
                    slider.setBackground(bgColor);
                setWest(slider);
            }
    }
    getVerticalScrollBar().setValue(1);
    getVerticalScrollBar().setValue(0);
    setViewportView((JComponent) view);
    if (view instanceof TableView) {
        // the table view needs it's orientation set correctly
        OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
    }
    if (view instanceof ListView) {
        view.requestFocus();
    }
    OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
    if ((bgColor != null) && (view instanceof ListView))
        ((ListView) view).setBackground(bgColor);
    // except if it's a table view, that is always transparent
    if (!(view instanceof TableView)) {
        setOpaque(isOpaque());
    } else {
        for (int i = FormController.FORM_RENDERER + 1; i < dataRenderers.length; i++) {
            if (dataRenderers[i] != null && !(dataRenderers[i] instanceof TableView)) {
                dataRenderers[i].setOpaque(isOpaque());
            }
        }
    }
    return view;
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) DataRenderer(com.servoy.j2db.smart.dataui.DataRenderer) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) StyledEnablePanel(com.servoy.j2db.smart.dataui.StyledEnablePanel) JLabel(javax.swing.JLabel) ISupportAsyncLoading(com.servoy.j2db.component.ISupportAsyncLoading) Point(java.awt.Point) Container(java.awt.Container) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) FormBodyEditor(com.servoy.j2db.smart.dataui.FormBodyEditor) ListCellRenderer(javax.swing.ListCellRenderer) IStyleRule(com.servoy.j2db.util.IStyleRule) TwoNativeJavaObject(com.servoy.j2db.smart.scripting.TwoNativeJavaObject) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) PortalComponent(com.servoy.j2db.smart.dataui.PortalComponent) JComponent(javax.swing.JComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) Border(javax.swing.border.Border) JList(javax.swing.JList)

Example 10 with IStyleSheet

use of com.servoy.j2db.util.IStyleSheet in project servoy-client by Servoy.

the class DataRenderer method getListCellRendererComponent.

public Component getListCellRendererComponent(JComponent rendererParentCanBeNull, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    this.selected = isSelected;
    // if (isSelected)
    // {
    // setBorder(focusBorder);
    // }
    // else
    // {
    // setBorder(noFocusBorder);
    // }
    boolean bgRowColorSet = false;
    // if in Renderer mode for a the List then a renderer can't stop editing.
    if (value instanceof IRecordInternal) {
        IRecordInternal val = (IRecordInternal) value;
        // if in list view, we need to set the render state for each list item here
        if (rendererParentCanBeNull != null) {
            DataAdapterList.setDataRendererComponentsRenderState(this, val);
        }
        dataAdapterList.setRecord(val, !isRenderer);
        // setOpaque(true);
        if (index != -1) {
            boolean specialStateCase = (val instanceof PrototypeState || val instanceof FindState || val.getRawData() == null);
            if (strRowBGColorProvider == null && !specialStateCase) {
                if (rendererParentCanBeNull instanceof ISupportRowBGColorScript) {
                    strRowBGColorProvider = ((ISupportRowBGColorScript) rendererParentCanBeNull).getRowBGColorScript();
                    rowBGColorArgs = ((ISupportRowBGColorScript) rendererParentCanBeNull).getRowBGColorArgs();
                }
                // $NON-NLS-1$
                if (strRowBGColorProvider == null)
                    strRowBGColorProvider = "servoy_row_bgcolor";
                isRowBGColorCalculation = val.getRawData().containsCalculation(strRowBGColorProvider);
                if (!isRowBGColorCalculation && strRowBGColorProvider.equals("servoy_row_bgcolor")) {
                    // $NON-NLS-1$
                    strRowBGColorProvider = "";
                }
                defaultColor = getBackground();
            }
            if (// $NON-NLS-1$
            strRowBGColorProvider != null && !"".equals(strRowBGColorProvider)) {
                IFoundSetInternal parent = val.getParentFoundSet();
                if (parent != null && !specialStateCase) {
                    Object bg_color = null;
                    if (isRowBGColorCalculation) {
                        bg_color = parent.getCalculationValue(val, strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(index), new Boolean(isSelected), null, null, Boolean.FALSE }), Utils.parseJSExpressions(rowBGColorArgs)), null);
                    } else {
                        try {
                            FormController currentForm = dataAdapterList.getFormController();
                            bg_color = currentForm.executeFunction(strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(index), new Boolean(isSelected), null, null, currentForm.getName(), val, Boolean.FALSE }), Utils.parseJSExpressions(rowBGColorArgs)), false, null, true, null);
                        } catch (Exception ex) {
                            Debug.error(ex);
                        }
                    }
                    if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
                        bgRowColorSet = true;
                        setBackground(PersistHelper.createColor(bg_color.toString()));
                    } else {
                        setBackground(defaultColor);
                    }
                } else {
                    setBackground(defaultColor);
                }
            }
            if (rendererParentCanBeNull instanceof ISupportRowStyling && !specialStateCase && !bgRowColorSet) {
                ISupportRowStyling oddEvenStyling = (ISupportRowStyling) rendererParentCanBeNull;
                IStyleSheet ss = oddEvenStyling.getRowStyleSheet();
                IStyleRule style = isSelected ? oddEvenStyling.getRowSelectedStyle() : null;
                if (style != null && style.getAttributeCount() == 0)
                    style = null;
                if (style == null) {
                    // because index = 0 means record = 1
                    style = (index % 2 == 0) ? oddEvenStyling.getRowOddStyle() : oddEvenStyling.getRowEvenStyle();
                }
                if (ss != null && style != null) {
                    Color bgColor = ss.getBackground(style);
                    if (bgColor != null) {
                        showSelection = false;
                        bgRowColorSet = true;
                        setBackground(bgColor);
                    }
                }
            }
        }
    }
    if (rendererParentCanBeNull != null) {
        if (rendererParentCanBeNull.isEnabled() != isEnabled()) {
            // Debug.trace(donotusecanbenullifinrecondview.getName()+" "+donotusecanbenullifinrecondview.isEnabled());
            // needed for portals
            setEnabled(rendererParentCanBeNull.isEnabled());
        }
        if (bgRowColorSet && !isOpaque()) {
            setOpaque(true);
        }
        dataRendererOnRenderWrapper.getRenderEventExecutor().fireOnRender(hasFocus());
    }
    return this;
}
Also used : FormController(com.servoy.j2db.FormController) ISupportRowBGColorScript(com.servoy.j2db.ui.ISupportRowBGColorScript) Undefined(org.mozilla.javascript.Undefined) ISupportRowStyling(com.servoy.j2db.ui.ISupportRowStyling) IStyleSheet(com.servoy.j2db.util.IStyleSheet) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Color(java.awt.Color) FindState(com.servoy.j2db.dataprocessing.FindState) IStyleRule(com.servoy.j2db.util.IStyleRule) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Aggregations

IStyleSheet (com.servoy.j2db.util.IStyleSheet)22 IStyleRule (com.servoy.j2db.util.IStyleRule)17 Point (java.awt.Point)8 Border (javax.swing.border.Border)7 Part (com.servoy.j2db.persistence.Part)6 Color (java.awt.Color)6 Dimension (java.awt.Dimension)6 Insets (java.awt.Insets)6 FormController (com.servoy.j2db.FormController)4 IForm (com.servoy.j2db.IForm)4 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)4 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)4 TitledBorder (javax.swing.border.TitledBorder)4 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)3 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)3 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)3 AbstractBase (com.servoy.j2db.persistence.AbstractBase)3 RepositoryException (com.servoy.j2db.persistence.RepositoryException)3 Style (com.servoy.j2db.persistence.Style)3 ISupportRowStyling (com.servoy.j2db.ui.ISupportRowStyling)3