Package hapax

Examples of hapax.TemplateDataDictionary


        final Map<GwtType, String> xmlTemplates = new LinkedHashMap<GwtType, String>();
        for (final GwtType gwtType : GwtType.getMirrorTypes()) {
            if (gwtType.getTemplate() == null) {
                continue;
            }
            TemplateDataDictionary dataDictionary = buildMirrorDataDictionary(
                    gwtType, mirroredType, proxy, mirrorTypeMap,
                    clientSideTypeMap, moduleName);
            gwtType.dynamicallyResolveFieldsToWatch(clientSideTypeMap);
            gwtType.dynamicallyResolveMethodsToWatch(mirroredType.getName(),
                    clientSideTypeMap, topLevelPackage);
            templateTypeDetailsMap.put(
                    gwtType,
                    getTemplateDetails(dataDictionary, gwtType.getTemplate(),
                            mirrorTypeMap.get(gwtType), moduleName));

            if (gwtType.isCreateUiXml()) {
                dataDictionary = buildMirrorDataDictionary(gwtType,
                        mirroredType, proxy, mirrorTypeMap, clientSideTypeMap,
                        moduleName);
                final String contents = getTemplateContents(
                        gwtType.getTemplate() + "UiXml", dataDictionary);
                xmlTemplates.put(gwtType, contents);
            }
        }

        final Map<String, String> xmlMap = new LinkedHashMap<String, String>();
        final List<ClassOrInterfaceTypeDetails> typeDetails = new ArrayList<ClassOrInterfaceTypeDetails>();
        for (final GwtProxyProperty proxyProperty : clientSideTypeMap.values()) {
            if (!proxyProperty.isCollection()
                    || proxyProperty.isCollectionOfProxy()) {
                continue;
            }

            TemplateDataDictionary dataDictionary = TemplateDictionary.create();
            dataDictionary.setVariable("packageName",
                    GwtPath.MANAGED_UI_EDITOR.packageName(topLevelPackage));
            dataDictionary.setVariable("scaffoldUiPackage",
                    GwtPath.SCAFFOLD_UI.packageName(topLevelPackage));
            final JavaType collectionTypeImpl = getCollectionImplementation(proxyProperty
                    .getPropertyType());
            addImport(dataDictionary, collectionTypeImpl);
            addImport(dataDictionary, proxyProperty.getPropertyType());

            final String collectionType = proxyProperty.getPropertyType()
                    .getSimpleTypeName();
            final String boundCollectionType = proxyProperty.getPropertyType()
                    .getParameters().get(0).getSimpleTypeName();

            dataDictionary.setVariable("collectionType", collectionType);
            dataDictionary.setVariable("collectionTypeImpl",
                    collectionTypeImpl.getSimpleTypeName());
            dataDictionary.setVariable("boundCollectionType",
                    boundCollectionType);

            final JavaType collectionEditorType = new JavaType(
                    GwtPath.MANAGED_UI_EDITOR.packageName(topLevelPackage)
                            + "." + boundCollectionType + collectionType
                            + "Editor");
            typeDetails.add(getTemplateDetails(dataDictionary,
                    "CollectionEditor", collectionEditorType, moduleName));

            dataDictionary = TemplateDictionary.create();
            dataDictionary.setVariable("packageName",
                    GwtPath.MANAGED_UI_EDITOR.packageName(topLevelPackage));
            dataDictionary.setVariable("scaffoldUiPackage",
                    GwtPath.SCAFFOLD_UI.packageName(topLevelPackage));
            dataDictionary.setVariable("collectionType", collectionType);
            dataDictionary.setVariable("collectionTypeImpl",
                    collectionTypeImpl.getSimpleTypeName());
            dataDictionary.setVariable("boundCollectionType",
                    boundCollectionType);
            addImport(dataDictionary, proxyProperty.getPropertyType());

            String inputType;
            boolean isSimpleType = false;
            // If collection is a simple type, e.g. String, Double, Float, a
            // ValueListBox will not work
            if (boundCollectionType.equals("String")) {
                inputType = "TextBox";
                isSimpleType = true;
            }
            else if (boundCollectionType.equals("Double")) {
                inputType = "DoubleBox";
                isSimpleType = true;
            }
            else if (boundCollectionType.equals("Float")) {
                inputType = "DoubleBox";
                isSimpleType = true;
            }
            else if (boundCollectionType.equals("Integer")) {
                inputType = "IntegerBox";
                isSimpleType = true;
            }
            else if (boundCollectionType.equals("Long")) {
                inputType = "LongBox";
            }
            else {
                inputType = "ValueListBox";
            }

            dataDictionary.setVariable("inputType", inputType);

            // Different templates for simple and complex editors
            String editorType = isSimpleType ? "SimpleCollectionEditor"
                    : "CollectionEditor";
View Full Code Here


    @Override
    public List<ClassOrInterfaceTypeDetails> getStaticTemplateTypeDetails(
            final GwtType type, final String moduleName) {
        final List<ClassOrInterfaceTypeDetails> templateTypeDetails = new ArrayList<ClassOrInterfaceTypeDetails>();
        final TemplateDataDictionary dataDictionary = buildDictionary(type,
                moduleName);
        templateTypeDetails.add(getTemplateDetails(dataDictionary,
                type.getTemplate(), getDestinationJavaType(type, moduleName),
                moduleName));
        return templateTypeDetails;
View Full Code Here

    private TemplateDataDictionary buildDictionary(final GwtType type,
            final String moduleName) {
        final Set<ClassOrInterfaceTypeDetails> proxies = typeLocationService
                .findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_GWT_PROXY);
        final TemplateDataDictionary dataDictionary = buildStandardDataDictionary(
                type, moduleName);
        switch (type) {
        case APP_ENTITY_TYPES_PROCESSOR:
            for (final ClassOrInterfaceTypeDetails proxy : proxies) {
                if (!GwtUtils.scaffoldProxy(proxy)) {
                    continue;
                }
                final String proxySimpleName = proxy.getName()
                        .getSimpleTypeName();
                final ClassOrInterfaceTypeDetails entity = gwtTypeService
                        .lookupEntityFromProxy(proxy);
                if (entity != null) {
                    final String entitySimpleName = entity.getName()
                            .getSimpleTypeName();

                    dataDictionary.addSection("proxys").setVariable("proxy",
                            proxySimpleName);

                    final String entity1 = new StringBuilder("\t\tif (")
                            .append(proxySimpleName)
                            .append(".class.equals(clazz)) {\n\t\t\tprocessor.handle")
                            .append(entitySimpleName).append("((")
                            .append(proxySimpleName)
                            .append(") null);\n\t\t\treturn;\n\t\t}")
                            .toString();
                    dataDictionary.addSection("entities1").setVariable(
                            "entity", entity1);

                    final String entity2 = new StringBuilder(
                            "\t\tif (proxy instanceof ")
                            .append(proxySimpleName)
                            .append(") {\n\t\t\tprocessor.handle")
                            .append(entitySimpleName).append("((")
                            .append(proxySimpleName)
                            .append(") proxy);\n\t\t\treturn;\n\t\t}")
                            .toString();
                    dataDictionary.addSection("entities2").setVariable(
                            "entity", entity2);

                    final String entity3 = new StringBuilder(
                            "\tpublic abstract void handle")
                            .append(entitySimpleName).append("(")
                            .append(proxySimpleName).append(" proxy);")
                            .toString();
                    dataDictionary.addSection("entities3").setVariable(
                            "entity", entity3);
                    addImport(dataDictionary, proxy.getName()
                            .getFullyQualifiedTypeName());
                }
            }
            break;
        case MASTER_ACTIVITIES:
            for (final ClassOrInterfaceTypeDetails proxy : proxies) {
                if (!GwtUtils.scaffoldProxy(proxy)) {
                    continue;
                }
                final String proxySimpleName = proxy.getName()
                        .getSimpleTypeName();
                final ClassOrInterfaceTypeDetails entity = gwtTypeService
                        .lookupEntityFromProxy(proxy);
                if (entity != null
                        && !Modifier.isAbstract(entity.getModifier())) {
                    final String entitySimpleName = entity.getName()
                            .getSimpleTypeName();
                    final TemplateDataDictionary section = dataDictionary
                            .addSection("entities");
                    section.setVariable("entitySimpleName", entitySimpleName);
                    section.setVariable("entityFullPath", proxySimpleName);
                    addImport(dataDictionary, entitySimpleName,
                            GwtType.LIST_ACTIVITY, moduleName);
                    addImport(dataDictionary, proxy.getName()
                            .getFullyQualifiedTypeName());
                    addImport(dataDictionary, entitySimpleName,
                            GwtType.DESKTOP_LIST_VIEW, moduleName);
                    addImport(dataDictionary, entitySimpleName,
                            GwtType.MOBILE_LIST_VIEW, moduleName);
                }
            }
            break;
        case APP_REQUEST_FACTORY:
            for (final ClassOrInterfaceTypeDetails proxy : proxies) {
                if (!GwtUtils.scaffoldProxy(proxy)) {
                    continue;
                }
                final ClassOrInterfaceTypeDetails entity = gwtTypeService
                        .lookupEntityFromProxy(proxy);
                if (entity != null
                        && !Modifier.isAbstract(entity.getModifier())) {
                    final String entitySimpleName = entity.getName()
                            .getSimpleTypeName();
                    ClassOrInterfaceTypeDetails request = gwtTypeService
                            .lookupUnmanagedRequestFromProxy(proxy);
                    if (request == null) {
                        request = gwtTypeService.lookupRequestFromProxy(proxy);
                    }
                    if (request != null) {
                        final String requestExpression = new StringBuilder("\t")
                                .append(request.getName().getSimpleTypeName())
                                .append(" ")
                                .append(StringUtils
                                        .uncapitalize(entitySimpleName))
                                .append("Request();").toString();
                        dataDictionary.addSection("entities").setVariable(
                                "entity", requestExpression);
                        addImport(dataDictionary, request.getName()
                                .getFullyQualifiedTypeName());
                    }
                }
                dataDictionary.setVariable("sharedScaffoldPackage",
                        GwtPath.SHARED_SCAFFOLD.packageName(projectOperations
                                .getTopLevelPackage(moduleName)));
            }

            if (projectOperations
                    .isFeatureInstalledInFocusedModule(FeatureNames.GAE)) {
                dataDictionary.showSection("gae");
            }
            break;
        case LIST_PLACE_RENDERER:
            for (final ClassOrInterfaceTypeDetails proxy : proxies) {
                if (!GwtUtils.scaffoldProxy(proxy)) {
                    continue;
                }
                final ClassOrInterfaceTypeDetails entity = gwtTypeService
                        .lookupEntityFromProxy(proxy);
                if (entity != null) {
                    final String entitySimpleName = entity.getName()
                            .getSimpleTypeName();
                    final String proxySimpleName = proxy.getName()
                            .getSimpleTypeName();
                    final TemplateDataDictionary section = dataDictionary
                            .addSection("entities");
                    section.setVariable("entitySimpleName", entitySimpleName);
                    section.setVariable("entityFullPath", proxySimpleName);
                    addImport(dataDictionary, proxy.getName()
                            .getFullyQualifiedTypeName());
                }
            }
            break;
View Full Code Here

            final String moduleName) {

        final JavaType proxyType = proxy.getName();
        final JavaType javaType = mirrorTypeMap.get(type);

        final TemplateDataDictionary dataDictionary = TemplateDictionary
                .create();

        // Get my locator and
        final JavaType entity = mirroredType.getName();
        final String entityName = entity.getFullyQualifiedTypeName();
        final String metadataIdentificationString = mirroredType
                .getDeclaredByMetadataId();
        final JavaType idType = persistenceMemberLocator
                .getIdentifierType(entity);
        Validate.notNull(idType,
                "Identifier type is not available for entity '%s'", entityName);

        final MethodParameter entityParameter = new MethodParameter(entity,
                "proxy");
        final ClassOrInterfaceTypeDetails request = gwtTypeService
                .lookupRequestFromProxy(proxy);

        final MemberTypeAdditions persistMethodAdditions = layerService
                .getMemberTypeAdditions(metadataIdentificationString,
                        CustomDataKeys.PERSIST_METHOD.name(), entity, idType,
                        LAYER_POSITION, entityParameter);
        Validate.notNull(persistMethodAdditions,
                "Persist method is not available for entity '%s'", entityName);
        final String persistMethodSignature = getRequestMethodCall(request,
                persistMethodAdditions);
        dataDictionary.setVariable("persistMethodSignature",
                persistMethodSignature);

        final MemberTypeAdditions removeMethodAdditions = layerService
                .getMemberTypeAdditions(metadataIdentificationString,
                        CustomDataKeys.REMOVE_METHOD.name(), entity, idType,
                        LAYER_POSITION, entityParameter);
        Validate.notNull(removeMethodAdditions,
                "Remove method is not available for entity '%s'", entityName);
        final String removeMethodSignature = getRequestMethodCall(request,
                removeMethodAdditions);
        dataDictionary.setVariable("removeMethodSignature",
                removeMethodSignature);

        final MemberTypeAdditions countMethodAdditions = layerService
                .getMemberTypeAdditions(metadataIdentificationString,
                        CustomDataKeys.COUNT_ALL_METHOD.name(), entity, idType,
                        LAYER_POSITION);
        Validate.notNull(countMethodAdditions,
                "Count method is not available for entity '%s'", entityName);
        dataDictionary.setVariable("countEntitiesMethod",
                countMethodAdditions.getMethodName());

        for (final GwtType reference : type.getReferences()) {
            addReference(dataDictionary, reference, mirrorTypeMap);
        }

        addImport(dataDictionary, proxyType.getFullyQualifiedTypeName());

        final String pluralMetadataKey = PluralMetadata.createIdentifier(
                mirroredType.getName(), PhysicalTypeIdentifier
                        .getPath(mirroredType.getDeclaredByMetadataId()));
        final PluralMetadata pluralMetadata = (PluralMetadata) metadataService
                .get(pluralMetadataKey);
        final String plural = pluralMetadata.getPlural();

        final String simpleTypeName = mirroredType.getName()
                .getSimpleTypeName();
        final JavaPackage topLevelPackage = projectOperations
                .getTopLevelPackage(moduleName);
        dataDictionary.setVariable("className", javaType.getSimpleTypeName());
        dataDictionary.setVariable("packageName", javaType.getPackage()
                .getFullyQualifiedPackageName());
        dataDictionary.setVariable("placePackage",
                GwtPath.SCAFFOLD_PLACE.packageName(topLevelPackage));
        dataDictionary.setVariable("scaffoldUiPackage",
                GwtPath.SCAFFOLD_UI.packageName(topLevelPackage));
        dataDictionary.setVariable("sharedScaffoldPackage",
                GwtPath.SHARED_SCAFFOLD.packageName(topLevelPackage));
        dataDictionary.setVariable("uiPackage",
                GwtPath.MANAGED_UI.packageName(topLevelPackage));
        dataDictionary.setVariable("uiEditorPackage",
                GwtPath.MANAGED_UI_EDITOR.packageName(topLevelPackage));
        dataDictionary.setVariable("name", simpleTypeName);
        dataDictionary.setVariable("pluralName", plural);
        dataDictionary.setVariable("nameUncapitalized",
                StringUtils.uncapitalize(simpleTypeName));
        dataDictionary.setVariable("proxy", proxyType.getSimpleTypeName());
        dataDictionary.setVariable("pluralName", plural);
        dataDictionary.setVariable("proxyRenderer", GwtProxyProperty
                .getProxyRendererType(topLevelPackage, proxyType));

        String proxyFields = null;
        GwtProxyProperty primaryProperty = null;
        GwtProxyProperty secondaryProperty = null;
        GwtProxyProperty dateProperty = null;
        final Set<String> importSet = new HashSet<String>();

        // cleanUpLegacyProjects(type, topLevelPackage, simpleTypeName);

        List<String> existingEditViewFields = new ArrayList<String>();

        List<String> existingDetailsViewFields = new ArrayList<String>();

        List<String> fieldsInBothDesktopAndMobileEditView = new ArrayList<String>();

        if (type == GwtType.EDIT_ACTIVITY_WRAPPER
                || type == GwtType.MOBILE_EDIT_VIEW
                || type == GwtType.DESKTOP_EDIT_VIEW) {
            List<String> existingDesktopFields = new ArrayList<String>();
            List<String> existingMobileFields = new ArrayList<String>();

            try {
                String className = GwtPath.MANAGED_UI_DESKTOP
                        .packageName(topLevelPackage)
                        + "."
                        + simpleTypeName
                        + GwtType.DESKTOP_EDIT_VIEW.getTemplate();

                ClassOrInterfaceTypeDetails details = typeLocationService
                        .getTypeDetails(new JavaType(className));

                if (details != null) {
                    for (final FieldMetadata field : details
                            .getDeclaredFields()) {
                        final JavaSymbolName fieldName = field.getFieldName();
                        final String name = fieldName.toString();
                        // Adds names of fields in DesktopEditView to
                        // existingDesktopFields list. These fields should not
                        // be added to the *MobileDetailsView_Roo_Gwt class
                        existingDesktopFields.add(name);
                    }
                }

                className = GwtPath.MANAGED_UI_MOBILE
                        .packageName(topLevelPackage)
                        + "."
                        + simpleTypeName
                        + GwtType.MOBILE_EDIT_VIEW.getTemplate();

                details = typeLocationService.getTypeDetails(new JavaType(
                        className));

                if (details != null) {
                    for (FieldMetadata field : details.getDeclaredFields()) {
                        JavaSymbolName fieldName = field.getFieldName();
                        String name = fieldName.toString();
                        // Adds names of fields in MobileEditView to
                        // existingMobileFields list. These fields should not be
                        // added to the *MobileDetailsView_Roo_Gwt class
                        existingMobileFields.add(name);
                    }
                }

                if (type == GwtType.MOBILE_EDIT_VIEW)
                    existingEditViewFields = existingMobileFields;

                if (type == GwtType.DESKTOP_EDIT_VIEW)
                    existingEditViewFields = existingDesktopFields;

            }
            catch (final Exception e) {
                throw new IllegalArgumentException(e);
            }

            for (String mobileViewField : existingMobileFields) {
                for (String viewField : existingDesktopFields) {
                    if (viewField.equals(mobileViewField)) {
                        fieldsInBothDesktopAndMobileEditView.add(viewField);
                        break;
                    }
                }
            }
        }

        if (type == GwtType.MOBILE_DETAILS_VIEW
                || type == GwtType.DESKTOP_DETAILS_VIEW) {
            List<String> existingDesktopFields = new ArrayList<String>();
            List<String> existingMobileFields = new ArrayList<String>();

            try {
                String className = GwtPath.MANAGED_UI_DESKTOP
                        .packageName(topLevelPackage)
                        + "."
                        + simpleTypeName
                        + GwtType.DESKTOP_DETAILS_VIEW.getTemplate();

                ClassOrInterfaceTypeDetails details = typeLocationService
                        .getTypeDetails(new JavaType(className));

                if (details != null) {
                    for (final FieldMetadata field : details
                            .getDeclaredFields()) {
                        final JavaSymbolName fieldName = field.getFieldName();
                        final String name = fieldName.toString();
                        existingDesktopFields.add(name);
                    }
                }

                className = GwtPath.MANAGED_UI_MOBILE
                        .packageName(topLevelPackage)
                        + "."
                        + simpleTypeName
                        + GwtType.MOBILE_DETAILS_VIEW.getTemplate();

                details = typeLocationService.getTypeDetails(new JavaType(
                        className));

                if (details != null) {
                    for (FieldMetadata field : details.getDeclaredFields()) {
                        JavaSymbolName fieldName = field.getFieldName();
                        String name = fieldName.toString();
                        existingMobileFields.add(name);
                    }
                }

                // Adds names of fields in MobileDetailsView to existingFields
                // list
                if (type == GwtType.MOBILE_DETAILS_VIEW)
                    existingDetailsViewFields = existingMobileFields;

                // Adds names of fields in DesktopDetailsView to existingFields
                // list
                if (type == GwtType.DESKTOP_DETAILS_VIEW)
                    existingDetailsViewFields = existingDesktopFields;

            }
            catch (final Exception e) {
                throw new IllegalArgumentException(e);
            }
        }

        for (final GwtProxyProperty gwtProxyProperty : clientSideTypeMap
                .values()) {
            // Determine if this is the primary property.
            if (primaryProperty == null) {
                // Choose the first available field.
                primaryProperty = gwtProxyProperty;
            }
            else if (gwtProxyProperty.isString() && !primaryProperty.isString()) {
                // Favor String properties over other types.
                secondaryProperty = primaryProperty;
                primaryProperty = gwtProxyProperty;
            }
            else if (secondaryProperty == null) {
                // Choose the next available property.
                secondaryProperty = gwtProxyProperty;
            }
            else if (gwtProxyProperty.isString()
                    && !secondaryProperty.isString()) {
                // Favor String properties over other types.
                secondaryProperty = gwtProxyProperty;
            }

            // Determine if this is the first date property.
            if (dateProperty == null && gwtProxyProperty.isDate()) {
                dateProperty = gwtProxyProperty;
            }

            if (gwtProxyProperty.isProxy()
                    || gwtProxyProperty.isCollectionOfProxy()) {
                if (proxyFields != null) {
                    proxyFields += ", ";
                }
                else {
                    proxyFields = "";
                }
                proxyFields += "\"" + gwtProxyProperty.getName() + "\"";
            }

            // if the property is in the existingFields list, do not add it
            if (!existingDetailsViewFields.contains(gwtProxyProperty.getName())) {
                dataDictionary.addSection("fields").setVariable("field",
                        gwtProxyProperty.getName());

                final TemplateDataDictionary managedPropertiesSection = dataDictionary
                        .addSection("managedProperties");
                managedPropertiesSection.setVariable("prop",
                        gwtProxyProperty.getName());
                managedPropertiesSection.setVariable(
                        "propId",
                        proxyType.getSimpleTypeName() + "_"
                                + gwtProxyProperty.getName());
                managedPropertiesSection.setVariable("propGetter",
                        gwtProxyProperty.getGetter());
                managedPropertiesSection.setVariable("propType",
                        gwtProxyProperty.getType());
                managedPropertiesSection.setVariable("propFormatter",
                        gwtProxyProperty.getFormatter());
                managedPropertiesSection.setVariable("propRenderer",
                        gwtProxyProperty.getRenderer());
                managedPropertiesSection.setVariable("propReadable",
                        gwtProxyProperty.getReadableName());
            }

            final TemplateDataDictionary propertiesSection = dataDictionary
                    .addSection("properties");
            propertiesSection.setVariable("prop", gwtProxyProperty.getName());
            propertiesSection.setVariable(
                    "propId",
                    proxyType.getSimpleTypeName() + "_"
                            + gwtProxyProperty.getName());
            propertiesSection.setVariable("propGetter",
                    gwtProxyProperty.getGetter());
            propertiesSection.setVariable("propType",
                    gwtProxyProperty.getType());
            propertiesSection.setVariable("propFormatter",
                    gwtProxyProperty.getFormatter());
            propertiesSection.setVariable("propRenderer",
                    gwtProxyProperty.getRenderer());
            propertiesSection.setVariable("propReadable",
                    gwtProxyProperty.getReadableName());

            if (!isReadOnly(gwtProxyProperty.getName(), mirroredType)) {
                // if the property is in the existingFields list, do not add it
                if (!existingEditViewFields
                        .contains(gwtProxyProperty.getName()))
                    dataDictionary.addSection("editViewProps").setVariable(
                            "prop", gwtProxyProperty.forEditView());

                final TemplateDataDictionary editableSection = dataDictionary
                        .addSection("editableProperties");
                editableSection.setVariable("prop", gwtProxyProperty.getName());
                editableSection.setVariable(
                        "propId",
                        proxyType.getSimpleTypeName() + "_"
                                + gwtProxyProperty.getName());
                editableSection.setVariable("propGetter",
                        gwtProxyProperty.getGetter());
                editableSection.setVariable("propType",
                        gwtProxyProperty.getType());
                editableSection.setVariable("propFormatter",
                        gwtProxyProperty.getFormatter());
                editableSection.setVariable("propRenderer",
                        gwtProxyProperty.getRenderer());
                editableSection.setVariable("propBinder",
                        gwtProxyProperty.getBinder());
                editableSection.setVariable("propReadable",
                        gwtProxyProperty.getReadableName());
            }

            dataDictionary.setVariable("proxyRendererType",
                    proxyType.getSimpleTypeName() + "Renderer");

            // Adds import statements for primitive list editors
            if (gwtProxyProperty.isCollection()
                    && !gwtProxyProperty.isCollectionOfProxy()) {
                maybeAddImport(dataDictionary, importSet,
                        gwtProxyProperty.getSetEditorType());
            }

            // If the field is not added to the managed MobileEditView and the
            // managed EditView then it there is no reason to add it to the
            // interface nor the start method in the EditActivityWrapper
            if (!fieldsInBothDesktopAndMobileEditView.contains(gwtProxyProperty
                    .getName())
                    && !isReadOnly(gwtProxyProperty.getName(), mirroredType)) {
                if (gwtProxyProperty.isProxy() || gwtProxyProperty.isEnum()
                        || gwtProxyProperty.isCollectionOfProxy()) {
                    final TemplateDataDictionary section = dataDictionary
                            .addSection(gwtProxyProperty.isEnum() ? "setEnumValuePickers"
                                    : "setProxyValuePickers");
                    // The methods is required to satisfy the interface.
                    // However, if the field is in the existingFields lists, the
                    // method must be empty because the field will not be added
                    // to the managed view.
                    section.setVariable(
                            "setValuePicker",
                            existingEditViewFields.contains(gwtProxyProperty
                                    .getName()) ? gwtProxyProperty
                                    .getSetEmptyValuePickerMethod()
                                    : gwtProxyProperty
                                            .getSetValuePickerMethod());
                    section.setVariable("setValuePickerName",
                            gwtProxyProperty.getSetValuePickerMethodName());
                    section.setVariable("valueType", gwtProxyProperty
                            .getValueType().getSimpleTypeName());
                    section.setVariable("rendererType",
                            gwtProxyProperty.getProxyRendererType());
                    if (gwtProxyProperty.isProxy()
                            || gwtProxyProperty.isCollectionOfProxy()) {
                        String propTypeName = StringUtils
                                .uncapitalize(gwtProxyProperty
                                        .isCollectionOfProxy() ? gwtProxyProperty
                                        .getPropertyType().getParameters()
                                        .get(0).getSimpleTypeName()
                                        : gwtProxyProperty.getPropertyType()
                                                .getSimpleTypeName());
                        propTypeName = propTypeName.substring(0,
                                propTypeName.indexOf("Proxy"));
                        section.setVariable("requestInterface", propTypeName
                                + "Request");
                        section.setVariable("findMethod",
                                "find" + StringUtils.capitalize(propTypeName)
                                        + "Entries(0, 50)");
                    }
                    maybeAddImport(dataDictionary, importSet,
                            gwtProxyProperty.getPropertyType());
                    maybeAddImport(dataDictionary, importSet,
                            gwtProxyProperty.getValueType());
                    if (gwtProxyProperty.isCollectionOfProxy()) {
                        maybeAddImport(dataDictionary, importSet,
                                gwtProxyProperty.getPropertyType()
                                        .getParameters().get(0));
                        maybeAddImport(dataDictionary, importSet,
                                gwtProxyProperty.getSetEditorType());
                    }
                }
            }
        }

        dataDictionary.setVariable("proxyFields", proxyFields);

        // Add a section for the mobile properties.
        if (primaryProperty != null) {
            dataDictionary
                    .setVariable("primaryProp", primaryProperty.getName());
            dataDictionary.setVariable("primaryPropGetter",
                    primaryProperty.getGetter());
            String primaryPropBuilder = new StringBuilder(
                    "if (value != null) {\n\t\t\t\tsb.appendEscaped(")
                    .append("primaryRenderer")
                    .append(".render(value));\n\t\t\t}").toString();
            dataDictionary
                    .setVariable("primaryPropBuilder", primaryPropBuilder);

            // dataDictionary.setVariable("primaryPropBuilder",
            // primaryProperty.forMobileListView("primaryRenderer"));
            // final TemplateDataDictionary section = dataDictionary
            // .addSection("mobileProperties");
            // section.setVariable("prop", primaryProperty.getName());
            // section.setVariable("propGetter", primaryProperty.getGetter());
            // section.setVariable("propType", primaryProperty.getType());
            // section.setVariable("propRenderer",
            // primaryProperty.getRenderer());
            // section.setVariable("propRendererName", "primaryRenderer");
        }
        else {
            dataDictionary.setVariable("primaryProp", "id");
            dataDictionary.setVariable("primaryPropGetter", "getId");
            dataDictionary.setVariable("primaryPropBuilder", "");
        }
        if (secondaryProperty != null) {
            dataDictionary.setVariable("secondaryPropBuilder",
                    secondaryProperty.forMobileListView("secondaryRenderer"));
            final TemplateDataDictionary section = dataDictionary
                    .addSection("mobileProperties");
            section.setVariable("prop", secondaryProperty.getName());
            section.setVariable("propGetter", secondaryProperty.getGetter());
            section.setVariable("propType", secondaryProperty.getType());
            section.setVariable("propRenderer", secondaryProperty.getRenderer());
            section.setVariable("propRendererName", "secondaryRenderer");
        }
        else {
            dataDictionary.setVariable("secondaryPropBuilder", "");
        }
        if (dateProperty != null) {
            dataDictionary.setVariable("datePropBuilder",
                    dateProperty.forMobileListView("dateRenderer"));
            final TemplateDataDictionary section = dataDictionary
                    .addSection("mobileProperties");
            section.setVariable("prop", dateProperty.getName());
            section.setVariable("propGetter", dateProperty.getGetter());
            section.setVariable("propType", dateProperty.getType());
            section.setVariable("propRenderer", dateProperty.getRenderer());
            section.setVariable("propRendererName", "dateRenderer");
        }
        else {
            dataDictionary.setVariable("datePropBuilder", "");
        }
        return dataDictionary;
View Full Code Here

    private TemplateDataDictionary buildStandardDataDictionary(
            final GwtType type, final String moduleName) {
        final JavaType javaType = new JavaType(getFullyQualifiedTypeName(type,
                moduleName));
        final TemplateDataDictionary dataDictionary = TemplateDictionary
                .create();
        for (final GwtType reference : type.getReferences()) {
            addReference(dataDictionary, reference, moduleName);
        }
        dataDictionary.setVariable("className", javaType.getSimpleTypeName());
        dataDictionary.setVariable("packageName", javaType.getPackage()
                .getFullyQualifiedPackageName());
        dataDictionary.setVariable("placePackage", GwtPath.SCAFFOLD_PLACE
                .packageName(projectOperations.getTopLevelPackage(moduleName)));
        dataDictionary.setVariable("sharedScaffoldPackage",
                GwtPath.SHARED_SCAFFOLD.packageName(projectOperations
                        .getTopLevelPackage(moduleName)));
        dataDictionary.setVariable("sharedGaePackage", GwtPath.SHARED_GAE
                .packageName(projectOperations.getTopLevelPackage(moduleName)));
        return dataDictionary;
    }
View Full Code Here

TOP

Related Classes of hapax.TemplateDataDictionary

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.