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.module.templatingcomponents.components;
35
36 import info.magnolia.cms.beans.config.ServerConfiguration;
37 import info.magnolia.cms.core.AggregationState;
38 import info.magnolia.cms.core.Content;
39 import info.magnolia.cms.gui.inline.BarNew;
40
41 import java.io.IOException;
42 import java.io.Writer;
43 import java.util.List;
44
45
46
47
48
49
50 public class NewBar extends AbstractAuthoringUiComponent {
51 private static final String DEFAULT_NEW_LABEL = "buttons.new";
52
53
54
55
56
57
58
59
60 public static NewBar make(ServerConfiguration serverCfg, AggregationState aggState, String containerName, List<String> allowedParagraphs, String newButtonLabel) {
61 final NewBar bar = new NewBar(serverCfg, aggState);
62
63
64
65
66
67 bar.setContainerName(containerName);
68
69 if (newButtonLabel != null) {
70 bar.setNewButtonLabel(newButtonLabel);
71 }
72
73 bar.setAllowedParagraphs(allowedParagraphs);
74 return bar;
75 }
76
77 private String containerName;
78 private String newButtonLabel = DEFAULT_NEW_LABEL;
79 private List<String> allowedParagraphs;
80
81 public NewBar(ServerConfiguration server, AggregationState aggregationState) {
82 super(server, aggregationState);
83 }
84
85 public void setContainerName(String containerName) {
86 this.containerName = containerName;
87 }
88
89 public void setNewButtonLabel(String newButtonLabel) {
90 this.newButtonLabel = newButtonLabel;
91 }
92
93 public void setAllowedParagraphs(List<String> allowedParagraphs) {
94 this.allowedParagraphs = allowedParagraphs;
95 }
96
97 @Override
98 protected void doRender(Appendable out) throws IOException {
99 final BarNew bar = new BarNew();
100
101 bar.setParagraph(asString(allowedParagraphs));
102
103 final Content content = currentContent();
104 final String targetPath = content.getHandle();
105 bar.setPath(targetPath);
106
107
108
109 bar.setNodeCollectionName(containerName);
110 bar.setNodeName("mgnlNew");
111
112
113 if (!allowedParagraphs.isEmpty()) {
114 bar.setDefaultButtons();
115
116 bar.getButtonNew().setLabel(getMessage(content, newButtonLabel));
117
118 bar.placeDefaultButtons();
119 }
120 bar.drawHtml((Writer) out);
121 }
122
123 }