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.ui.field;
35
36 import info.magnolia.ui.editor.ByIndexedChildNodes;
37 import info.magnolia.ui.editor.CurrentItemProviderDefinition;
38 import info.magnolia.ui.editor.DefaultJcrNodeOrderHandler;
39 import info.magnolia.ui.editor.ItemProviderDefinition;
40 import info.magnolia.ui.editor.JcrChildNodeProviderDefinition;
41 import info.magnolia.ui.editor.MultiFieldEntryResolution;
42 import info.magnolia.ui.editor.MultiFormView;
43
44 import javax.jcr.Node;
45
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48
49
50
51
52 @FieldType("jcrMultiField")
53 public class JcrMultiFieldDefinition extends MultiFieldDefinition<Node> {
54
55 private static final Logger log = LoggerFactory.getLogger(JcrMultiFieldDefinition.class);
56
57 public JcrMultiFieldDefinition() {
58 setEntryResolution(new MultiFieldEntryResolution.Definition());
59 setOrderHandler(new DefaultJcrNodeOrderHandler.Definition());
60 setItemProvider(new JcrChildNodeProviderDefinition());
61 setCanRemoveItems(true);
62 }
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 @Deprecated
79 private void safeguardAgainstIncompatibleCombination(ItemProviderDefinition itemProvider, MultiFormView.EntryResolution.Definition<Node> entryResolution) {
80 if (entryResolution instanceof ByIndexedChildNodes.Definition) {
81 ByIndexedChildNodes.Definition def = (ByIndexedChildNodes.Definition) entryResolution;
82 if (itemProvider instanceof JcrChildNodeProviderDefinition) {
83 if (((JcrChildNodeProviderDefinition) itemProvider).isSupportI18N()) {
84 if (def.isStrict()) {
85 def.setStrict(false);
86 throw new IllegalStateException("Falling back to non-strict entry resolution. All nodes in its localized parent are resolved, regardless of their node names. Set strictness resolution to false to remove this problem.");
87 }
88 } else {
89 if (!def.isStrict()) {
90 def.setStrict(true);
91 throw new IllegalStateException("Falling back to strict mode entry resolution, to be able to distinguish multi field entries by locale. Reason: supporti18n is set to false which means entries of different locales share parent. Set entry resolution to strict manually to remove this problem.");
92 }
93 }
94 } else if (itemProvider instanceof CurrentItemProviderDefinition) {
95 if (!def.isStrict()) {
96 def.setStrict(true);
97 throw new IllegalStateException("Falling back to strict mode entry resolution, to be able to " +
98 "distinguish multi field entries. Reason: CurrentItemProvider is used in multi which means " +
99 "entries are stored without a parent adjacent to nodes that are not related to this multi " +
100 "field. Non-strict resolution could result in overwriting of non-multi field related nodes." +
101 "Set entry resolution definition to strict manually, to remove this problem.");
102 }
103 }
104 }
105 }
106
107 public void init() {
108 safeguardAgainstIncompatibleCombination(getItemProvider(), getEntryResolution());
109 }
110 }