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.gui.control.Button;
38 import info.magnolia.cms.gui.control.Edit;
39 import info.magnolia.cms.gui.misc.CssConstants;
40
41 import java.io.IOException;
42 import java.io.Writer;
43 import java.util.ArrayList;
44 import java.util.List;
45
46 import javax.jcr.PropertyType;
47 import javax.jcr.RepositoryException;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
50
51
52
53
54
55
56 public class DialogEditWithButton extends DialogBox {
57
58 private List buttons = new ArrayList();
59
60
61
62
63 @Override
64 public void init(HttpServletRequest request, HttpServletResponse response, Content websiteNode, Content configNode)
65 throws RepositoryException {
66 super.init(request, response, websiteNode, configNode);
67 buttons.add(new Button());
68 }
69
70 public Button getButton() {
71 return this.getButton(0);
72 }
73
74 public Button getButton(int index) {
75 return (Button) this.getButtons().get(index);
76 }
77
78 public void setButtons(List l) {
79 this.buttons = l;
80 }
81
82 public List getButtons() {
83 return this.buttons;
84 }
85
86
87
88
89 @Override
90 public void drawHtml(Writer out) throws IOException {
91 doBeforeDrawHtml();
92
93 Edit control = new Edit(this.getName(), this.getValue());
94 control.setType(this.getConfigValue("type", PropertyType.TYPENAME_STRING));
95 if (this.getConfigValue("saveInfo").equals("false")) {
96 control.setSaveInfo(false);
97 }
98 control.setCssClass(CssConstants.CSSCLASS_EDIT);
99 control.setRows(this.getConfigValue("rows", "1"));
100 control.setCssStyles("width", "100%");
101 if (this.getConfigValue("onchange", null) != null) {
102 control.setEvent("onchange", this.getConfigValue("onchange"));
103 }
104 this.drawHtmlPre(out);
105 String width = this.getConfigValue("width", "95%");
106 out.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"" + width + "\">");
107 out.write("<tr><td style=\"width:100%\" class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">");
108 out.write(control.getHtml());
109 if (this.getConfigValue("buttonLabel", null) != null) {
110 String label = this.getConfigValue("buttonLabel");
111 label = this.getMessage(label);
112 this.getButton().setLabel(label);
113 }
114 for (int i = 0; i < this.getButtons().size(); i++) {
115 out.write("</td><td></td><td class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">");
116 out.write(this.getButton(i).getHtml());
117 }
118 out.write("</td></tr></table>");
119
120 this.drawHtmlPost(out);
121 }
122
123
124
125
126 protected void doBeforeDrawHtml() {
127 }
128 }