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.admininterface.trees;
35
36 import info.magnolia.module.templating.Template;
37 import info.magnolia.module.templating.TemplateManager;
38 import info.magnolia.cms.core.Content;
39 import info.magnolia.cms.gui.control.Select;
40 import info.magnolia.cms.gui.control.TreeColumn;
41 import info.magnolia.cms.i18n.MessagesUtil;
42 import org.apache.commons.lang.StringUtils;
43
44 import javax.servlet.http.HttpServletRequest;
45 import java.util.Iterator;
46
47
48
49
50
51
52 public class TemplateColumn extends TreeColumn {
53 private final TemplateManager templateManager;
54 Select templateSelect;
55
56 public TemplateColumn(String javascriptTree, HttpServletRequest request) {
57 super(javascriptTree, request);
58 this.templateManager = TemplateManager.getInstance();
59
60 templateSelect = new Select();
61 templateSelect.setName(javascriptTree + TreeColumn.EDIT_NAMEADDITION);
62 templateSelect.setSaveInfo(false);
63 templateSelect.setCssClass(TreeColumn.EDIT_CSSCLASS_SELECT);
64
65
66
67
68 templateSelect.setEvent("onblur", javascriptTree
69 + ".saveNodeData(this.value,this.options[this.selectedIndex].text)");
70 templateSelect.setEvent("onchange", javascriptTree
71 + ".saveNodeData(this.value,this.options[this.selectedIndex].text)");
72
73 }
74
75 public String getHtml() {
76 Content content = this.getWebsiteNode();
77 String templateName = content.getMetaData().getTemplate();
78 Template template = templateManager.getTemplateDefinition(templateName);
79 return template != null ? template.getI18NTitle() : StringUtils.defaultString(templateName);
80
81 }
82
83 public String getHtmlEdit() {
84 Iterator<Template> templates = templateManager.getAvailableTemplates(this.getWebsiteNode());
85
86 templateSelect.getOptions().clear();
87
88 while (templates.hasNext()) {
89 Template template = templates.next();
90 String title = MessagesUtil.javaScriptString(template.getI18NTitle());
91 templateSelect.setOptions(title, template.getName());
92 }
93 return templateSelect.getHtml();
94 }
95 }