KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > gui > dialog > DialogEditWithButton


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.gui.dialog;
14
15 import info.magnolia.cms.core.Content;
16 import info.magnolia.cms.gui.control.Button;
17 import info.magnolia.cms.gui.control.Edit;
18 import info.magnolia.cms.gui.misc.CssConstants;
19 import info.magnolia.cms.i18n.TemplateMessagesUtil;
20
21 import java.io.IOException JavaDoc;
22 import java.io.Writer JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.List JavaDoc;
25
26 import javax.jcr.PropertyType;
27 import javax.jcr.RepositoryException;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30
31
32 /**
33  * @author Vinzenz Wyser
34  * @version 2.0
35  */

36 public class DialogEditWithButton extends DialogBox {
37
38     private List JavaDoc buttons = new ArrayList JavaDoc();
39
40     /**
41      * Empty constructor should only be used by DialogFactory.
42      */

43     protected DialogEditWithButton() {
44     }
45
46     /**
47      * @see info.magnolia.cms.gui.dialog.DialogInterface#init(HttpServletRequest, HttpServletResponse, Content, Content)
48      */

49     public void init(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Content websiteNode, Content configNode)
50         throws RepositoryException {
51         super.init(request, response, websiteNode, configNode);
52         buttons.add(new Button());
53     }
54
55     public Button getButton() {
56         return this.getButton(0);
57     }
58
59     public Button getButton(int index) {
60         return (Button) this.getButtons().get(index);
61     }
62
63     public void setButtons(List JavaDoc l) {
64         this.buttons = l;
65     }
66
67     public List JavaDoc getButtons() {
68         return this.buttons;
69     }
70
71     /**
72      * @see info.magnolia.cms.gui.dialog.DialogInterface#drawHtml(Writer)
73      */

74     public void drawHtml(Writer JavaDoc out) throws IOException JavaDoc {
75         Edit control = new Edit(this.getName(), this.getValue());
76         control.setType(this.getConfigValue("type", PropertyType.TYPENAME_STRING)); //$NON-NLS-1$
77
if (this.getConfigValue("saveInfo").equals("false")) { //$NON-NLS-1$ //$NON-NLS-2$
78
control.setSaveInfo(false);
79         }
80         control.setCssClass(CssConstants.CSSCLASS_EDIT);
81         control.setRows(this.getConfigValue("rows", "1")); //$NON-NLS-1$ //$NON-NLS-2$
82
control.setCssStyles("width", "100%"); //$NON-NLS-1$ //$NON-NLS-2$
83
if (this.getConfigValue("onchange", null) != null) { //$NON-NLS-1$
84
control.setEvent("onchange", this.getConfigValue("onchange")); //$NON-NLS-1$ //$NON-NLS-2$
85
}
86         this.drawHtmlPre(out);
87         String JavaDoc width = this.getConfigValue("width", "100%"); //$NON-NLS-1$ //$NON-NLS-2$
88
out.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"" + width + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
89
out.write("<tr><td width=\"100%\" class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
90
out.write(control.getHtml());
91         if (this.getConfigValue("buttonLabel", null) != null) { //$NON-NLS-1$
92
String JavaDoc label = this.getConfigValue("buttonLabel"); //$NON-NLS-1$
93
label = TemplateMessagesUtil.get(this.getRequest(), label);
94             this.getButton().setLabel(label);
95         }
96         for (int i = 0; i < this.getButtons().size(); i++) {
97             out.write("</td><td></td><td class=\"" + CssConstants.CSSCLASS_EDITWITHBUTTON + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
98
out.write(this.getButton(i).getHtml());
99         }
100         out.write("</td></tr></table>"); //$NON-NLS-1$
101

102         this.drawHtmlPost(out);
103     }
104 }
Popular Tags