Skip to content

Instantly share code, notes, and snippets.

@gjoseph
Last active September 9, 2015 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gjoseph/4abaa7aca7fdd5c7bd81 to your computer and use it in GitHub Desktop.
Save gjoseph/4abaa7aca7fdd5c7bd81 to your computer and use it in GitHub Desktop.
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..f392d7c 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,12 @@ public class ListViewImpl implements ListView {
table.setColumnReorderingAllowed(false);
table.setSortEnabled(true);
- table.setCellStyleGenerator(new 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;
- }
- });
+ table.setCellStyleGenerator(new AggregateCellStyleGenerator(
+ // Default style generators
+ new DeletedRowStyleGenerator(),
+ // Custom style generators (i.e. could 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 +256,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<String> 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;
+ }
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment