01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package info.jtrac.wicket.yui;
18:
19: import org.apache.wicket.Component;
20: import org.apache.wicket.ajax.AjaxRequestTarget;
21: import org.apache.wicket.behavior.HeaderContributor;
22: import org.apache.wicket.markup.html.IHeaderContributor;
23: import org.apache.wicket.markup.html.IHeaderResponse;
24: import org.apache.wicket.markup.html.WebMarkupContainer;
25: import org.apache.wicket.markup.html.basic.Label;
26: import org.apache.wicket.markup.html.panel.Panel;
27: import org.apache.wicket.model.PropertyModel;
28:
29: /**
30: * custom wicketized yahoo ui dialog widget
31: */
32: public class YuiDialog extends Panel {
33:
34: public static final String CONTENT_ID = "content";
35: private WebMarkupContainer dialog;
36: private String heading;
37:
38: public String getHeading() {
39: return heading;
40: }
41:
42: public void setHeading(String heading) {
43: this .heading = heading;
44: }
45:
46: public YuiDialog(String id) {
47: super (id);
48:
49: add(HeaderContributor
50: .forJavaScript("resources/yui/yahoo/yahoo-min.js"));
51: add(HeaderContributor
52: .forJavaScript("resources/yui/event/event-min.js"));
53: add(HeaderContributor
54: .forJavaScript("resources/yui/dom/dom-min.js"));
55: add(HeaderContributor
56: .forJavaScript("resources/yui/dragdrop/dragdrop-min.js"));
57: add(HeaderContributor
58: .forJavaScript("resources/yui/container/container-min.js"));
59: add(HeaderContributor
60: .forJavaScript("resources/yui/container/resize-dialog.js"));
61: add(HeaderContributor
62: .forCss("resources/yui/container/assets/container.css"));
63:
64: setOutputMarkupId(true); // for Wicket Ajax
65: dialog = new WebMarkupContainer("dialog");
66: dialog.setOutputMarkupId(true); // for Yahoo Dialog
67: dialog.setVisible(false);
68: add(dialog);
69: dialog.add(new Label("heading", new PropertyModel(this ,
70: "heading")));
71: dialog.add(new WebMarkupContainer(CONTENT_ID));
72: }
73:
74: public void show(AjaxRequestTarget target, String h,
75: Component content) {
76: this .heading = h;
77: target.addComponent(this );
78: dialog.setVisible(true);
79: dialog.replace(content);
80: final String markupId = dialog.getMarkupId();
81: // using the contributor and the onDomReady Wicket helper handles the rare case that
82: // the dialog is visible and the user refreshes the backing page (possible as dialog is not modal!)
83: // so in that special case, this javascript is called at page load
84: // but in the usual Ajax request case, this behaves just like AjaxRequestTarget.appendJavascript()
85: add(new HeaderContributor(new IHeaderContributor() {
86: public void renderHead(IHeaderResponse response) {
87: response.renderOnDomReadyJavascript("var " + markupId
88: + " = new YAHOO.widget.ResizeDialog('"
89: + markupId + "', "
90: + " { constraintoviewport : true }); "
91: + markupId + ".render(); " + markupId
92: + ".show();");
93: }
94: }));
95: }
96:
97: }
|