Search in sources :

Example 1 with OgnlTextFormat

use of com.manydesigns.elements.text.OgnlTextFormat in project Portofino by ManyDesigns.

the class ShortNameUtils method getName.

public static String getName(ClassAccessor classAccessor, Object object) {
    ShortName annotation = classAccessor.getAnnotation(ShortName.class);
    String formatString;
    if (annotation == null) {
        StringBuilder sb = new StringBuilder();
        boolean first = true;
        // sintetizziamo una stringa a partire dalla chiave primaria
        for (PropertyAccessor propertyAccessor : classAccessor.getKeyProperties()) {
            if (first) {
                first = false;
            } else {
                sb.append(PK_ELEMENT_SEPARATOR);
            }
            sb.append(String.format("%%{%s}", propertyAccessor.getName()));
        }
        formatString = sb.toString();
    } else {
        formatString = annotation.value();
    }
    OgnlTextFormat ognlTextFormat = OgnlTextFormat.create(formatString);
    return ognlTextFormat.format(object);
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) ShortName(com.manydesigns.elements.annotations.ShortName) OgnlTextFormat(com.manydesigns.elements.text.OgnlTextFormat)

Example 2 with OgnlTextFormat

use of com.manydesigns.elements.text.OgnlTextFormat in project Portofino by ManyDesigns.

the class AbstractCrudAction method configureSortLinks.

protected void configureSortLinks(TableFormBuilder tableFormBuilder) {
    for (PropertyAccessor propertyAccessor : classAccessor.getProperties()) {
        String propName = propertyAccessor.getName();
        String sortDirection;
        if (propName.equals(sortProperty) && "asc".equals(this.sortDirection)) {
            sortDirection = "desc";
        } else {
            sortDirection = "asc";
        }
        Map<String, Object> parameters = new HashMap<>();
        parameters.put("sortProperty", propName);
        parameters.put("sortDirection", sortDirection);
        parameters.put(SEARCH_STRING_PARAM, searchString);
        Charset charset = Charset.forName(context.getRequest().getCharacterEncoding());
        UrlBuilder urlBuilder = new UrlBuilder(charset, Util.getAbsoluteUrl(context.getActionPath()), false).addParameters(parameters);
        XhtmlBuffer xb = new XhtmlBuffer();
        xb.openElement("a");
        xb.addAttribute("class", "sort-link");
        xb.addAttribute("href", urlBuilder.toString());
        xb.writeNoHtmlEscape("%{label}");
        if (propName.equals(sortProperty)) {
            xb.openElement("em");
            xb.addAttribute("class", "pull-right glyphicon glyphicon-chevron-" + ("desc".equals(sortDirection) ? "up" : "down"));
            xb.closeElement("em");
        }
        xb.closeElement("a");
        OgnlTextFormat hrefFormat = OgnlTextFormat.create(xb.toString());
        String encoding = getUrlEncoding();
        hrefFormat.setEncoding(encoding);
        tableFormBuilder.configHeaderTextFormat(propName, hrefFormat);
    }
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) XhtmlBuffer(com.manydesigns.elements.xml.XhtmlBuffer) Charset(java.nio.charset.Charset) JSONObject(org.json.JSONObject) UrlBuilder(com.manydesigns.elements.servlet.UrlBuilder) OgnlTextFormat(com.manydesigns.elements.text.OgnlTextFormat)

Example 3 with OgnlTextFormat

use of com.manydesigns.elements.text.OgnlTextFormat in project Portofino by ManyDesigns.

the class ModelSelectionProviderSupport method createSelectionProvider.

protected SelectionProvider createSelectionProvider(DatabaseSelectionProvider current, String[] fieldNames, Class[] fieldTypes, DisplayMode dm, SearchDisplayMode sdm, String newHref, String newText) {
    DefaultSelectionProvider selectionProvider;
    boolean anyActiveProperty = false;
    for (String propertyName : fieldNames) {
        CrudProperty crudProperty = findProperty(propertyName, crudAction.getCrudConfiguration().getProperties());
        if (crudProperty != null && crudProperty.isEnabled()) {
            anyActiveProperty = true;
            break;
        }
    }
    if (!anyActiveProperty) {
        // Dummy
        selectionProvider = SelectionProviderLogic.createSelectionProvider(current.getName(), new Class[0], Collections.emptyList());
    } else {
        selectionProvider = createSelectionProvider(current, fieldNames, fieldTypes, dm, sdm);
    }
    if (selectionProvider != null) {
        if (newHref != null) {
            OgnlTextFormat tf = new OgnlTextFormat(newHref);
            newHref = tf.format(crudAction);
            String contextPath = ElementsThreadLocals.getHttpServletRequest().getContextPath();
            if (newHref.startsWith("/") && !newHref.startsWith(contextPath)) {
                newHref = contextPath + newHref;
            }
            tf = new OgnlTextFormat(newText);
            newText = tf.format(crudAction);
        }
        selectionProvider.setCreateNewValueHref(newHref);
        selectionProvider.setCreateNewValueText(newText);
    }
    return selectionProvider;
}
Also used : CrudProperty(com.manydesigns.portofino.resourceactions.crud.configuration.CrudProperty) OgnlTextFormat(com.manydesigns.elements.text.OgnlTextFormat)

Example 4 with OgnlTextFormat

use of com.manydesigns.elements.text.OgnlTextFormat in project Portofino by ManyDesigns.

the class AbstractCrudAction method configureDetailLink.

protected void configureDetailLink(TableFormBuilder tableFormBuilder) {
    boolean isShowingKey = false;
    for (PropertyAccessor property : classAccessor.getKeyProperties()) {
        if (tableFormBuilder.getPropertyAccessors().contains(property) && tableFormBuilder.isPropertyVisible(property)) {
            isShowingKey = true;
            break;
        }
    }
    OgnlTextFormat hrefFormat = getReadURLFormat();
    if (isShowingKey) {
        logger.debug("TableForm: configuring detail links for primary key properties");
        for (PropertyAccessor property : classAccessor.getKeyProperties()) {
            tableFormBuilder.configHrefTextFormat(property.getName(), hrefFormat);
        }
    } else {
        logger.debug("TableForm: configuring detail link for the first visible property");
        for (PropertyAccessor property : classAccessor.getProperties()) {
            if (tableFormBuilder.getPropertyAccessors().contains(property) && tableFormBuilder.isPropertyVisible(property)) {
                tableFormBuilder.configHrefTextFormat(property.getName(), hrefFormat);
                break;
            }
        }
    }
}
Also used : PropertyAccessor(com.manydesigns.elements.reflection.PropertyAccessor) OgnlTextFormat(com.manydesigns.elements.text.OgnlTextFormat)

Example 5 with OgnlTextFormat

use of com.manydesigns.elements.text.OgnlTextFormat in project Portofino by ManyDesigns.

the class AbstractCrudAction method refreshTableBlobDownloadHref.

protected void refreshTableBlobDownloadHref() {
    Iterator<?> objIterator = objects.iterator();
    for (TableForm.Row row : tableForm.getRows()) {
        Iterator<Field> fieldIterator = row.iterator();
        Object obj = objIterator.next();
        String baseUrl = null;
        while (fieldIterator.hasNext()) {
            Field field = fieldIterator.next();
            if (field instanceof AbstractBlobField) {
                if (baseUrl == null) {
                    OgnlTextFormat hrefFormat = getReadURLFormat();
                    baseUrl = hrefFormat.format(obj);
                }
                Blob blob = ((AbstractBlobField) field).getValue();
                if (blob != null) {
                    field.setHref(getBlobDownloadUrl(field, baseUrl));
                }
            }
        }
    }
}
Also used : Blob(com.manydesigns.elements.blobs.Blob) FileBlob(com.manydesigns.elements.annotations.FileBlob) JSONObject(org.json.JSONObject) OgnlTextFormat(com.manydesigns.elements.text.OgnlTextFormat)

Aggregations

OgnlTextFormat (com.manydesigns.elements.text.OgnlTextFormat)5 PropertyAccessor (com.manydesigns.elements.reflection.PropertyAccessor)3 JSONObject (org.json.JSONObject)2 FileBlob (com.manydesigns.elements.annotations.FileBlob)1 ShortName (com.manydesigns.elements.annotations.ShortName)1 Blob (com.manydesigns.elements.blobs.Blob)1 UrlBuilder (com.manydesigns.elements.servlet.UrlBuilder)1 XhtmlBuffer (com.manydesigns.elements.xml.XhtmlBuffer)1 CrudProperty (com.manydesigns.portofino.resourceactions.crud.configuration.CrudProperty)1 Charset (java.nio.charset.Charset)1