Search in sources :

Example 1 with ContentSpec

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

the class SpecGenerator method readModelAndHandlers.

private void readModelAndHandlers(List<SpecTemplateModel> specTemplateList) {
    MethodTemplatesLoader.loadMethodTemplatesFromXML();
    ContentSpec spec = StaticContentSpecLoader.getContentSpec();
    for (SpecTemplateModel componentSpec : specTemplateList) {
        List<Element> props = Utils.asList(spec.getPropertiesForObjectType(componentSpec.getRepositoryType()));
        List<Element> model = new ArrayList<Element>();
        List<ApiMethod> handlers = new ArrayList<ApiMethod>();
        for (Element element : props) {
            if (isAllowedProperty(componentSpec.getName(), element.getName())) {
                if (BaseComponent.isEventProperty(element.getName())) {
                    if (element.getDeprecatedMoveContentID() == 0) {
                        MethodTemplate template = MethodTemplate.getTemplate(ScriptMethod.class, element.getName());
                        List<String> parametersNames = new ArrayList<String>();
                        List<String> parameterTypes = new ArrayList<String>();
                        List<String> optionalParameters = new ArrayList<String>();
                        if (template.getArguments() != null) {
                            for (MethodArgument arg : template.getArguments()) {
                                parametersNames.add(arg.getName());
                                parameterTypes.add(arg.getType().getName());
                                if (arg.isOptional())
                                    optionalParameters.add(arg.getName());
                            }
                        }
                        String returnType = template.getReturnType() != null ? template.getReturnType().getName() : null;
                        handlers.add(new ApiMethod(element.getName(), returnType, parametersNames, parameterTypes, optionalParameters, metaDataForApi.get(template.getName())));
                    }
                } else if (getSpecTypeFromRepoType(componentSpec.getName(), element) != null) {
                    model.add(element);
                }
            }
        }
        if ("listbox".equals(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            model.add(cs.new Element(-1, IRepository.FIELDS, "multiselectListbox", IRepository.BOOLEAN, Boolean.FALSE));
        }
        if ("splitpane".equals(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            model.add(cs.new Element(-1, IRepository.FIELDS, "divLocation", IRepository.INTEGER, Integer.valueOf(-1)));
            model.add(cs.new Element(-1, IRepository.FIELDS, "divSize", IRepository.INTEGER, Integer.valueOf(5)));
            model.add(cs.new Element(-1, IRepository.FIELDS, "resizeWeight", IRepository.INTEGER, Integer.valueOf(-1)));
            model.add(cs.new Element(-1, IRepository.FIELDS, "pane1MinSize", IRepository.INTEGER, Integer.valueOf(-1)));
            model.add(cs.new Element(-1, IRepository.FIELDS, "pane2MinSize", IRepository.INTEGER, Integer.valueOf(-1)));
        }
        if ("portal".equals(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            model.add(cs.new Element(-1, IRepository.FIELDS, "relatedFoundset", -1, null));
            model.add(cs.new Element(-1, IRepository.FIELDS, "childElements", -1, null));
            model.add(cs.new Element(-1, IRepository.FIELDS, "columnHeaders", -1, null));
            model.add(cs.new Element(-1, IRepository.FIELDS, "headersClasses", -1, null));
            model.add(cs.new Element(-1, IRepository.INTEGER, "headerHeight", IRepository.INTEGER, 32));
        }
        if (componentSpec.getRepositoryType() == IRepository.TABPANELS) {
            ContentSpec cs = new ContentSpec();
            Element el = cs.new Element(-1, IRepository.FIELDS, "tabIndex", IRepository.SERVERS, "");
            if (isAllowedProperty(componentSpec.getName(), el.getName()) && getSpecTypeFromRepoType(componentSpec.getName(), el) != null) {
                model.add(el);
            }
            el = cs.new Element(-1, IRepository.TABPANELS, "tabs", IRepository.SERVERS, null);
            model.add(el);
            el = cs.new Element(-1, IRepository.TABPANELS, "readOnly", IRepository.BOOLEAN, Boolean.FALSE);
            model.add(el);
        }
        if (addFindmodeModelEntries.contains(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            Element el = cs.new Element(-1, IRepository.FIELDS, "findmode", IRepository.STRING, null);
            model.add(el);
        }
        if (addReadOnlyModelEntries.contains(componentSpec.getName())) {
            ContentSpec cs = new ContentSpec();
            Element el = cs.new Element(-1, IRepository.FIELDS, "readOnly", IRepository.STRING, null);
            model.add(el);
        }
        componentSpec.setModel(model);
        componentSpec.setHandlers(handlers);
    }
}
Also used : ContentSpec(com.servoy.j2db.persistence.ContentSpec) MethodArgument(com.servoy.j2db.persistence.MethodArgument) Element(com.servoy.j2db.persistence.ContentSpec.Element) ArrayList(java.util.ArrayList) MethodTemplate(com.servoy.j2db.persistence.MethodTemplate)

Aggregations

ContentSpec (com.servoy.j2db.persistence.ContentSpec)1 Element (com.servoy.j2db.persistence.ContentSpec.Element)1 MethodArgument (com.servoy.j2db.persistence.MethodArgument)1 MethodTemplate (com.servoy.j2db.persistence.MethodTemplate)1 ArrayList (java.util.ArrayList)1