KickJava   Java API By Example, From Geeks To Geeks.

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


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.gui.control.Button;
16 import info.magnolia.cms.gui.control.ButtonSet;
17 import info.magnolia.cms.gui.control.ControlSuper;
18 import info.magnolia.cms.gui.control.Hidden;
19 import info.magnolia.cms.gui.misc.CssConstants;
20 import info.magnolia.cms.gui.misc.Sources;
21 import info.magnolia.cms.i18n.Messages;
22 import info.magnolia.cms.i18n.MessagesManager;
23
24 import java.io.IOException JavaDoc;
25 import java.io.Writer JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
29
30 import org.apache.commons.lang.StringUtils;
31
32
33 /**
34  * @author Vinzenz Wyser
35  * @version 2.0
36  */

37 public class DialogDialog extends DialogSuper {
38
39     public static final String JavaDoc DIALOGSIZE_NORMAL_WIDTH = "800"; //$NON-NLS-1$
40

41     public static final String JavaDoc DIALOGSIZE_NORMAL_HEIGHT = "650"; //$NON-NLS-1$
42

43     public static final String JavaDoc DIALOGSIZE_SLIM_WIDTH = "500"; //$NON-NLS-1$
44

45     public static final String JavaDoc DIALOGSIZE_SLIM_HEIGHT = "600"; //$NON-NLS-1$
46

47     private String JavaDoc callbackJavascript = "opener.document.location.reload();window.close();"; //$NON-NLS-1$
48

49     private List JavaDoc javascriptSources = new ArrayList JavaDoc();
50
51     private List JavaDoc cssSources = new ArrayList JavaDoc();
52
53     private String JavaDoc action;
54
55     /**
56      * Empty constructor should only be used by DialogFactory.
57      */

58     protected DialogDialog() {
59     }
60
61     public void setCallbackJavascript(String JavaDoc s) {
62         this.callbackJavascript = s;
63     }
64
65     public String JavaDoc getCallbackJavascript() {
66         return this.callbackJavascript;
67     }
68
69     public void setAction(String JavaDoc s) {
70         this.action = s;
71     }
72
73     public String JavaDoc getAction() {
74         if (this.action == null) {
75             return this.getRequest().getRequestURI();
76         }
77
78         return this.action;
79     }
80
81     public void setJavascriptSources(String JavaDoc s) {
82         this.getJavascriptSources().add(s);
83     }
84
85     public List JavaDoc getJavascriptSources() {
86         return this.javascriptSources;
87     }
88
89     public void drawJavascriptSources(Writer JavaDoc out) throws IOException JavaDoc {
90         Iterator JavaDoc it = this.getJavascriptSources().iterator();
91         while (it.hasNext()) {
92             out.write("<script type=\"text/javascript\" SRC=\"" + it.next() + "\"></script>"); //$NON-NLS-1$ //$NON-NLS-2$
93
}
94     }
95
96     public void setCssSources(String JavaDoc s) {
97         this.getCssSources().add(s);
98     }
99
100     public List JavaDoc getCssSources() {
101         return this.cssSources;
102     }
103
104     public void drawCssSources(Writer JavaDoc out) throws IOException JavaDoc {
105         Iterator JavaDoc it = this.getCssSources().iterator();
106         while (it.hasNext()) {
107             out.write("<link rel=\"stylesheet\" type=\"text/css\" HREF=\"" + it.next() + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
108
}
109     }
110
111     public DialogTab addTab() {
112         return this.addTab(StringUtils.EMPTY);
113     }
114
115     public DialogTab addTab(String JavaDoc label) {
116         DialogTab tab = new DialogTab();
117         tab.setLabel(label);
118         this.getSubs().add(tab);
119         return tab;
120     }
121
122     public DialogTab getTab(int i) {
123         return (DialogTab) this.getSubs().get(i);
124     }
125
126     public void drawHtmlPreSubs(Writer JavaDoc out) throws IOException JavaDoc {
127
128         // @todo fix html and add a good doctype. At the moment dialogs don't work in standard compliant mode
129
// out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" ");
130
// out.write(" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
131

132         out.write("<html>"); //$NON-NLS-1$
133
this.drawHtmlPreSubsHead(out);
134         out.write("<body class=\"mgnlDialogBody\" onload=\"mgnlDialogInit();\">"); //$NON-NLS-1$
135
this.drawHtmlPreSubsForm(out);
136         this.drawHtmlPreSubsTabSet(out);
137     }
138
139     protected void drawHtmlPreSubsHead(Writer JavaDoc out) throws IOException JavaDoc {
140         out.write("<head>"); //$NON-NLS-1$
141
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"/>"); // kupu //$NON-NLS-1$
142
out.write("<script type=\"text/javascript\">"); //$NON-NLS-1$
143
out.write("window.resizeTo(" //$NON-NLS-1$
144
+ this.getConfigValue("width", DIALOGSIZE_NORMAL_WIDTH) //$NON-NLS-1$
145
+ "," //$NON-NLS-1$
146
+ this.getConfigValue("height", DIALOGSIZE_NORMAL_HEIGHT) //$NON-NLS-1$
147
+ ");"); //$NON-NLS-1$
148
out.write("</script>"); //$NON-NLS-1$
149
out.write("<title>" //$NON-NLS-1$
150
+ this.getConfigValue("label", MessagesManager.get(getRequest(), "dialog.editTitle")) //$NON-NLS-1$ //$NON-NLS-2$
151
+ "</title>"); //$NON-NLS-1$
152
out.write(new Sources(this.getRequest().getContextPath()).getHtmlJs());
153         out.write(new Sources(this.getRequest().getContextPath()).getHtmlCss());
154         out.write(new Sources(this.getRequest().getContextPath()).getHtmlRichEdit());
155         out.write("<script type=\"text/javascript\">"); //$NON-NLS-1$
156
out.write("var mgnlRichEditors=new Array();"); // will be extended at each richEdit control //$NON-NLS-1$
157
out.write("var kupu = null;"); //$NON-NLS-1$
158
out.write("var kupuui = null;"); //$NON-NLS-1$
159
out.write("</script>"); //$NON-NLS-1$
160
this.drawJavascriptSources(out);
161         this.drawCssSources(out);
162         out.write("</head>"); //$NON-NLS-1$
163
}
164
165     protected void drawHtmlPreSubsForm(Writer JavaDoc out) throws IOException JavaDoc {
166         out.write("<form action=\"" //$NON-NLS-1$
167
+ this.getAction() + "\" name=\"mgnlFormMain\" method=\"post\" enctype=\"multipart/form-data\">"); //$NON-NLS-1$
168
out.write(new Hidden("mgnlDialog", this.getConfigValue("dialog"), false).getHtml()); //$NON-NLS-1$ //$NON-NLS-2$
169
out.write(new Hidden("mgnlRepository", this.getConfigValue("repository"), false).getHtml()); //$NON-NLS-1$ //$NON-NLS-2$
170
out.write(new Hidden("mgnlPath", this.getConfigValue("path"), false).getHtml()); //$NON-NLS-1$ //$NON-NLS-2$
171
out.write(new Hidden("mgnlNodeCollection", this.getConfigValue("nodeCollection"), false).getHtml()); //$NON-NLS-1$ //$NON-NLS-2$
172
out.write(new Hidden("mgnlNode", this.getConfigValue("node"), false).getHtml()); //$NON-NLS-1$ //$NON-NLS-2$
173
out.write(new Hidden("mgnlJsCallback", this.getCallbackJavascript(), false).getHtml()); //$NON-NLS-1$
174
out.write(new Hidden("mgnlRichE", this.getConfigValue("richE"), false).getHtml()); //$NON-NLS-1$ //$NON-NLS-2$
175
out.write(new Hidden("mgnlRichEPaste", this.getConfigValue("richEPaste"), false).getHtml()); //$NON-NLS-1$ //$NON-NLS-2$
176
if (this.getConfigValue("paragraph").indexOf(",") == -1) { //$NON-NLS-1$ //$NON-NLS-2$
177
out.write(new Hidden("mgnlParagraph", this.getConfigValue("paragraph"), false).getHtml()); //$NON-NLS-1$ //$NON-NLS-2$
178
} // else multiple paragraph selection -> radios for selection
179
}
180
181     protected void drawHtmlPreSubsTabSet(Writer JavaDoc out) throws IOException JavaDoc {
182         String JavaDoc id = this.getId();
183         out.write("<script type=\"text/javascript\">"); //$NON-NLS-1$
184
out.write("mgnlControlSets['" + id + "']=new Object();"); //$NON-NLS-1$ //$NON-NLS-2$
185
out.write("mgnlControlSets['" + id + "'].items=new Array();"); //$NON-NLS-1$ //$NON-NLS-2$
186
out.write("mgnlControlSets['" + id + "'].resize=true;"); //$NON-NLS-1$ //$NON-NLS-2$
187
out.write("</script>"); //$NON-NLS-1$
188
}
189
190     public void drawHtmlPostSubs(Writer JavaDoc out) throws IOException JavaDoc {
191         this.drawHtmlPostSubsTabSet(out);
192         this.drawHtmlPostSubsButtons(out);
193
194         out.write("</form></body></html>"); //$NON-NLS-1$
195
}
196
197     protected void drawHtmlPostSubsTabSet(Writer JavaDoc out) throws IOException JavaDoc {
198         // TabSet stuff
199
String JavaDoc id = this.getId();
200         out.write("<div class=\"" + CssConstants.CSSCLASS_TABSETBUTTONBAR + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
201
out.write("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\"><tr><td class=\"" //$NON-NLS-1$
202
+ CssConstants.CSSCLASS_TABSETBUTTONBAR + "\">"); //$NON-NLS-1$
203
if (this.getOptions().size() != 0) {
204             ButtonSet control = new ButtonSet();
205             ((Button) this.getOptions().get(0)).setState(ControlSuper.BUTTONSTATE_PUSHED);
206             control.setButtons(this.getOptions());
207             control.setName(this.getId());
208             control.setSaveInfo(false);
209             control.setButtonType(ControlSuper.BUTTONTYPE_PUSHBUTTON);
210             out.write(control.getHtml());
211         }
212         out.write("</td></tr></table></div>"); //$NON-NLS-1$
213
out.write("<script type=\"text/javascript\">"); //$NON-NLS-1$
214
out.write("mgnlDialogResizeTabs('" + id + "');"); //$NON-NLS-1$ //$NON-NLS-2$
215
out.write("mgnlDialogShiftTab('" + id + "',false,0)"); //$NON-NLS-1$ //$NON-NLS-2$
216
out.write("</script>"); //$NON-NLS-1$
217
// end TabSet stuff
218
}
219
220     protected void drawHtmlPostSubsButtons(Writer JavaDoc out) throws IOException JavaDoc {
221         Messages msgs = MessagesManager.getMessages(getRequest());
222
223         out.write("<div class=\"" + CssConstants.CSSCLASS_TABSETSAVEBAR + "\">"); //$NON-NLS-1$ //$NON-NLS-2$
224

225         Button save = new Button();
226         save.setOnclick(this.getConfigValue("saveOnclick", "mgnlDialogFormSubmit();")); //$NON-NLS-1$ //$NON-NLS-2$
227
save.setLabel(this.getConfigValue("saveLabel", msgs.get("buttons.save"))); //$NON-NLS-1$ //$NON-NLS-2$
228
out.write(save.getHtml());
229         Button cancel = new Button();
230         cancel.setOnclick(this.getConfigValue("cancelOnclick", "window.close();")); //$NON-NLS-1$ //$NON-NLS-2$
231
cancel.setLabel(this.getConfigValue("cancelLabel", msgs.get("buttons.cancel"))); //$NON-NLS-1$ //$NON-NLS-2$
232
out.write(cancel.getHtml());
233
234         out.write("</div>"); //$NON-NLS-1$
235
}
236 }
237
Popular Tags