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);
}
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);
}
}
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;
}
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;
}
}
}
}
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));
}
}
}
}
}
Aggregations