Search in sources :

Example 16 with Style

use of com.servoy.j2db.persistence.Style in project servoy-client by Servoy.

the class ComponentFactory method getStyleForBasicComponentInternal.

private static Pair<IStyleSheet, IStyleRule> getStyleForBasicComponentInternal(IServiceProvider sp, AbstractBase bc, Form form, Set<Integer> visited) {
    if (bc == null || sp == null)
        return null;
    // Protection agains cycle in form inheritance hierarchy.
    if (!visited.add(new Integer(form.getID())))
        return null;
    Style repos_style = getStyleForForm(sp, form);
    Pair<IStyleSheet, IStyleRule> pair = null;
    if (repos_style != null) {
        IStyleSheet ss = getCSSStyle(sp, repos_style);
        String lookupName = getLookupName(bc);
        if (lookupName != null) {
            String formLookup = "";
            ISupportChilds parent = bc.getParent();
            if (parent instanceof Form) {
                String styleClass = ((Form) parent).getStyleClass();
                if (styleClass != null && styleClass.length() != 0) {
                    formLookup = "form." + styleClass;
                } else {
                    formLookup = "form";
                }
            } else if (parent instanceof Portal) {
                String styleClass = ((Portal) parent).getStyleClass();
                if (styleClass != null && styleClass.length() != 0) {
                    formLookup = "portal." + styleClass;
                } else {
                    formLookup = "portal";
                }
                parent = ((Portal) parent).getParent();
                if (parent instanceof Form) {
                    styleClass = ((Form) parent).getStyleClass();
                    if (styleClass != null && styleClass.length() != 0) {
                        formLookup = "form." + styleClass + ' ' + formLookup;
                    } else {
                        formLookup = "form " + formLookup;
                    }
                }
            }
            IStyleRule s = null;
            String styleClass = (bc instanceof BaseComponent) ? ((BaseComponent) bc).getStyleClass() : null;
            if (bc instanceof Part) {
                styleClass = ((Part) bc).getStyleClass();
            }
            if (lookupName.equals("check") || lookupName.equals("combobox") || "radio".equals(lookupName)) {
                if (styleClass != null && styleClass.length() != 0) {
                    lookupName += '.' + styleClass;
                }
                lookupName = formLookup + ' ' + lookupName;
                s = ss.getCSSRule(lookupName);
                if (s.getAttributeCount() > 0)
                    return new Pair<IStyleSheet, IStyleRule>(ss, s);
                else
                    lookupName = "field";
            }
            if (styleClass != null && styleClass.length() != 0) {
                lookupName += '.' + styleClass;
            }
            lookupName = formLookup + ' ' + lookupName;
            s = ss.getCSSRule(lookupName);
            pair = new Pair<IStyleSheet, IStyleRule>(ss, s);
        // see BoxPainter for getBorder/getInsets/getLength examples
        }
    }
    if ((pair == null || pair.getRight() == null || (pair.getRight()).getAttributeCount() == 0)) {
        if (sp.getFlattenedSolution() != null) {
            List<Form> formHierarchy = sp.getFlattenedSolution().getFormHierarchy(form);
            for (int i = 1; i < formHierarchy.size(); i++) {
                pair = getStyleForBasicComponentInternal(sp, bc, formHierarchy.get(i), visited);
                if (pair != null && pair.getRight() != null && (pair.getRight()).getAttributeCount() != 0) {
                    break;
                }
            }
        }
    }
    return pair;
}
Also used : BaseComponent(com.servoy.j2db.persistence.BaseComponent) IStyleSheet(com.servoy.j2db.util.IStyleSheet) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) IForm(com.servoy.j2db.IForm) Form(com.servoy.j2db.persistence.Form) Part(com.servoy.j2db.persistence.Part) Style(com.servoy.j2db.persistence.Style) IStyleRule(com.servoy.j2db.util.IStyleRule) Portal(com.servoy.j2db.persistence.Portal) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal)

Example 17 with Style

use of com.servoy.j2db.persistence.Style in project servoy-client by Servoy.

the class ComponentFactory method getCSSStyle.

public static IStyleSheet getCSSStyle(IServiceProvider sp, Style s) {
    if (s == null)
        return null;
    Map<Style, IStyleSheet> parsedStylesMap;
    if (sp != null && Boolean.TRUE.equals(s.getRuntimeProperty(MODIFIED_BY_CLIENT))) {
        // style changed by client, cache parsed style per client.
        parsedStylesMap = (ConcurrentMap<Style, IStyleSheet>) sp.getRuntimeProperties().get(PARSED_STYLES);
        if (parsedStylesMap == null) {
            parsedStylesMap = new ConcurrentHashMap<Style, IStyleSheet>();
            sp.getRuntimeProperties().put(PARSED_STYLES, parsedStylesMap);
        }
    } else {
        // static style, cache globally.
        parsedStylesMap = parsedStyles;
    }
    IStyleSheet ss = parsedStylesMap.get(s);
    if (ss == null) {
        ss = new ServoyStyleSheet(s.getCSSText(), s.getName());
        parsedStylesMap.put(s, ss);
    }
    return ss;
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) Style(com.servoy.j2db.persistence.Style) ServoyStyleSheet(com.servoy.j2db.util.ServoyStyleSheet)

Aggregations

Style (com.servoy.j2db.persistence.Style)17 RepositoryException (com.servoy.j2db.persistence.RepositoryException)6 Form (com.servoy.j2db.persistence.Form)4 RemoteException (java.rmi.RemoteException)4 HashMap (java.util.HashMap)4 FlattenedSolution (com.servoy.j2db.FlattenedSolution)3 Solution (com.servoy.j2db.persistence.Solution)3 IStyleSheet (com.servoy.j2db.util.IStyleSheet)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)2 ServoyException (com.servoy.j2db.util.ServoyException)2 HashSet (java.util.HashSet)2 IBaseSMForm (com.servoy.base.solutionmodel.IBaseSMForm)1 ApplicationException (com.servoy.j2db.ApplicationException)1 IForm (com.servoy.j2db.IForm)1 IFormController (com.servoy.j2db.IFormController)1 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)1 DebugSwingFormMananger (com.servoy.j2db.debug.DebugJ2DBClient.DebugSwingFormMananger)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 Field (com.servoy.j2db.persistence.Field)1