diff --git a/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/list/ListViewImpl.java b/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/list/ListViewImpl.java index e2356a7..c856ce6 100644 --- a/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/list/ListViewImpl.java +++ b/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/list/ListViewImpl.java @@ -29,11 +29,12 @@ * * Any modifications to this file must keep this entire header * intact. - * */ package info.magnolia.ui.workbench.list; import info.magnolia.ui.vaadin.grid.MagnoliaTable; +import info.magnolia.ui.vaadin.integration.jcr.AbstractJcrNodeAdapter; +import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter; import info.magnolia.ui.workbench.ContentView; import info.magnolia.ui.workbench.column.definition.ColumnFormatter; @@ -44,6 +45,10 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,23 +92,13 @@ public class ListViewImpl implements ListView { table.setColumnReorderingAllowed(false); table.setSortEnabled(true); - table.setCellStyleGenerator(new Table.CellStyleGenerator() { + table.setCellStyleGenerator(new AggregateCellStyleGenerator( + // Default style generators + new DeletedRowStyleGenerator(), - - @Override - public String getStyle(Table source, Object itemId, Object propertyId) { - // icon style is expected on the whole table row, not on a column matching a specific propertyId - if (propertyId == null && itemId != null) { - final Item item = source.getContainerDataSource().getItem(itemId); - if (item == null) { - return DELETED_ROW_STYLENAME; - } else { - return listener.getIcon(item); - } - } - return null; - } - }); + // Custom style generators (should be configured) + new DummyCellStyleGenerator() + )); // this one was re-added since the check-all worked for tree only but nor for list- and search-view, see MGNLUI-1958 // TODO fgrilli: a workaround for MGNLUI-1651 @@ -262,4 +257,62 @@ public class ListViewImpl implements ListView { } } + private static class AggregateCellStyleGenerator implements Table.CellStyleGenerator { + private final Table.CellStyleGenerator[] styleGenerators; + + public AggregateCellStyleGenerator(Table.CellStyleGenerator... styleGenerators) { + this.styleGenerators = styleGenerators; + } + + @Override + public String getStyle(Table source, Object itemId, Object propertyId) { + final List result = new ArrayList<>(); + for (Table.CellStyleGenerator styleGenerator : styleGenerators) { + final String style = styleGenerator.getStyle(source, itemId, propertyId); + if (style != null && !style.equals("")) { + result.add(style); + } + } + return StringUtils.join(result, ' '); + } + } + + private class DeletedRowStyleGenerator implements Table.CellStyleGenerator { + + @Override + public String getStyle(Table source, Object itemId, Object propertyId) { + // icon style is expected on the whole table row, not on a column matching a specific propertyId + if (propertyId == null && itemId != null) { + final Item item = source.getContainerDataSource().getItem(itemId); + if (item == null) { + return DELETED_ROW_STYLENAME; + } else { + return listener.getIcon(item); + } + } + return null; + } + } + + private static class DummyCellStyleGenerator implements Table.CellStyleGenerator { + @Override + public String getStyle(Table source, Object itemId, Object propertyId) { + // if propertyId is null, we're generating style for a row + if (propertyId != null) { + return null; + } + final Item item = source.getContainerDataSource().getItem(itemId); + if (item instanceof JcrNodeAdapter) { + Node node = ((AbstractJcrNodeAdapter) item).getJcrItem(); + try { + if (node.getName().contains("hello")) { + return "icon-pulse icon-favorites"; + } + } catch (RepositoryException e) { + throw new RuntimeException(e); // TODO + } + } + return null; + } + } }