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 @Override
106 public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode, Content configNode)
107 throws RepositoryException {
108 super.init(request, response, websiteNode, configNode);
109
110 try {
111 Iterator it = configNode.getContent("buttons").getChildren(ItemType.CONTENTNODE.getSystemName()).iterator();
112 while (it.hasNext()) {
113 Content n = (Content) it.next();
114
115 Button button = new Button();
116 button.setOnclick(n.getNodeData("onclick").getString());
117
118 String label = null;
119 if (n.getNodeData("label").isExist()) {
120 label = n.getNodeData("label").getString();
121 label = this.getMessage(label);
122 }
123 button.setLabel(label);
124
125 buttons.add(button);
126 }
127 }
128 catch (RepositoryException e) {
129 log.error("Exception caught: " + e.getMessage(), e);
130 }
131
132 }
133
134
135
136
137 @Override
138 public void drawHtml(Writer out) throws IOException {
139 Edit control = new Edit(this.getName(), this.getValue());
140 control.setType(this.getConfigValue("type", PropertyType.TYPENAME_STRING));
141 if (this.getConfigValue("saveInfo").equals("false")) {
142 control.setSaveInfo(false);
143 }
144 control.setCssClass(CssConstants.CSSCLASS_EDIT);
145 control.setRows(this.getConfigValue("rows", "1"));
146 control.setCssStyles("width", "100%");
147 if (this.getConfigValue("onchange", null) != null) {
148 control.setEvent("onchange", this.getConfigValue("onchange"));
149 }
150 this.drawHtmlPre(out);
151 String width = this.getConfigValue("width", "95%");
152 out.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"" + width + "\">");
153 out.write("<tr><td width=\"100%\" class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">");
154 out.write(control.getHtml());
155
156 for (Iterator iter = this.buttons.iterator(); iter.hasNext();) {
157 Button button = (Button) iter.next();
158 out.write("</td><td></td><td class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">");
159 out.write(button.getHtml());
160 }
161
162 out.write("</td></tr></table>");
163
164 this.drawHtmlPost(out);
165 }
166 }