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 java.util.HashMap;
20: import java.util.Map;
21: import org.apache.wicket.Component;
22: import org.apache.wicket.behavior.HeaderContributor;
23: import org.apache.wicket.markup.html.IHeaderContributor;
24: import org.apache.wicket.markup.html.IHeaderResponse;
25: import org.apache.wicket.markup.html.WebMarkupContainer;
26: import org.apache.wicket.markup.html.basic.Label;
27: import org.apache.wicket.markup.html.panel.Panel;
28:
29: /**
30: * custom wicketized yahoo ui panel widget
31: */
32: public class YuiPanel extends Panel {
33:
34: public static final String CONTENT_ID = "content";
35:
36: private WebMarkupContainer dialog;
37:
38: private Map<String, Object> getDefaultConfig() {
39: Map<String, Object> map = new HashMap<String, Object>();
40: map.put("constraintoviewport", true);
41: map.put("visible", false);
42: return map;
43: }
44:
45: public YuiPanel(String id, String heading, Component content,
46: Map<String, Object> customConfig) {
47: super (id);
48: final Map<String, Object> config = getDefaultConfig();
49: if (customConfig != null) {
50: config.putAll(customConfig);
51: }
52: add(HeaderContributor
53: .forJavaScript("resources/yui/yahoo/yahoo-min.js"));
54: add(HeaderContributor
55: .forJavaScript("resources/yui/event/event-min.js"));
56: add(HeaderContributor
57: .forJavaScript("resources/yui/dom/dom-min.js"));
58: add(HeaderContributor
59: .forJavaScript("resources/yui/dragdrop/dragdrop-min.js"));
60: add(HeaderContributor
61: .forJavaScript("resources/yui/container/container-min.js"));
62: add(HeaderContributor
63: .forCss("resources/yui/container/assets/container.css"));
64:
65: dialog = new WebMarkupContainer("dialog");
66: dialog.setOutputMarkupId(true);
67: add(dialog);
68: dialog.add(new Label("heading", heading));
69: dialog.add(content);
70: add(new HeaderContributor(new IHeaderContributor() {
71: public void renderHead(IHeaderResponse response) {
72: String markupId = dialog.getMarkupId();
73: response
74: .renderJavascript("var " + markupId + ";", null);
75: response.renderOnDomReadyJavascript(markupId
76: + " = new YAHOO.widget.Panel('" + markupId
77: + "'," + " " + YuiUtils.getJson(config) + "); "
78: + markupId + ".render()");
79: }
80: }));
81: }
82:
83: public String getShowScript() {
84: return dialog.getMarkupId() + ".show();";
85: }
86:
87: public String getHideScript() {
88: return dialog.getMarkupId() + ".hide();";
89: }
90:
91: }
|