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.cms.gui.dialog;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.cms.core.ItemType;
38 import info.magnolia.cms.gui.control.Button;
39 import info.magnolia.cms.gui.control.Edit;
40 import info.magnolia.cms.gui.misc.CssConstants;
41
42 import java.io.IOException;
43 import java.io.Writer;
44 import java.util.ArrayList;
45 import java.util.Iterator;
46 import java.util.List;
47
48 import javax.jcr.PropertyType;
49 import javax.jcr.RepositoryException;
50 import javax.servlet.http.HttpServletRequest;
51 import javax.servlet.http.HttpServletResponse;
52
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90 public class DialogEditWithCustomButtons extends DialogBox {
91
92
93
94
95 private static Logger log = LoggerFactory.getLogger(DialogEditWithCustomButtons.class);
96
97
98
99
100 private List buttons = new ArrayList();
101
102
103
104
105 public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode, Content configNode)
106 throws RepositoryException {
107 super.init(request, response, websiteNode, configNode);
108
109 try {
110 Iterator it = configNode.getContent("buttons").getChildren(ItemType.CONTENTNODE.getSystemName()).iterator();
111 while (it.hasNext()) {
112 Content n = (Content) it.next();
113
114 Button button = new Button();
115 button.setOnclick(n.getNodeData("onclick").getString());
116
117 String label = null;
118 if (n.getNodeData("label").isExist()) {
119 label = n.getNodeData("label").getString();
120 label = this.getMessage(label);
121 }
122 button.setLabel(label);
123
124 buttons.add(button);
125 }
126 }
127 catch (RepositoryException e) {
128 log.error("Exception caught: " + e.getMessage(), e);
129 }
130
131 }
132
133
134
135
136 public void drawHtml(Writer out) throws IOException {
137 Edit control = new Edit(this.getName(), this.getValue());
138 control.setType(this.getConfigValue("type", PropertyType.TYPENAME_STRING));
139 if (this.getConfigValue("saveInfo").equals("false")) {
140 control.setSaveInfo(false);
141 }
142 control.setCssClass(CssConstants.CSSCLASS_EDIT);
143 control.setRows(this.getConfigValue("rows", "1"));
144 control.setCssStyles("width", "100%");
145 if (this.getConfigValue("onchange", null) != null) {
146 control.setEvent("onchange", this.getConfigValue("onchange"));
147 }
148 this.drawHtmlPre(out);
149 String width = this.getConfigValue("width", "95%");
150 out.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"" + width + "\">");
151 out.write("<tr><td width=\"100%\" class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">");
152 out.write(control.getHtml());
153
154 for (Iterator iter = this.buttons.iterator(); iter.hasNext();) {
155 Button button = (Button) iter.next();
156 out.write("</td><td></td><td class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">");
157 out.write(button.getHtml());
158 }
159
160 out.write("</td></tr></table>");
161
162 this.drawHtmlPost(out);
163 }
164 }