1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.jcrbrowser.app.column;
35
36 import info.magnolia.ui.contentapp.configuration.column.ColumnType;
37 import info.magnolia.ui.contentapp.configuration.column.ConfiguredColumnDefinition;
38
39 import javax.jcr.Item;
40 import javax.jcr.Node;
41 import javax.jcr.Property;
42 import javax.jcr.PropertyType;
43 import javax.jcr.nodetype.NodeType;
44
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47
48 import com.machinezoo.noexception.Exceptions;
49 import com.vaadin.data.ValueProvider;
50 import com.vaadin.ui.renderers.TextRenderer;
51
52
53
54
55 @ColumnType("jcrTypeColumn")
56 public class JcrTypeColumnDefinition extends ConfiguredColumnDefinition<Item> {
57
58 private static final Logger log = LoggerFactory.getLogger(JcrTypeColumnDefinition.class);
59
60 public JcrTypeColumnDefinition() {
61 setName("jcrType");
62 setRenderer(TextRenderer.class);
63 setValueProvider(JcrTypeProvider.class);
64 }
65
66
67
68
69 public static class JcrTypeProvider implements ValueProvider<Item, String> {
70
71 @Override
72 public String apply(Item item) {
73 if (item.isNode()) {
74 Node node = (Node) item;
75 NodeType nodeType = Exceptions.wrap().get(node::getPrimaryNodeType);
76 return nodeType.getName();
77 }
78
79 Property property = (Property) item;
80 int type = Exceptions.wrap().get(property::getType);
81 return PropertyType.nameFromValue(type);
82 }
83 }
84 }