01: /*
02: * Copyright 2000,2006 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13:
14: package org.wingx.plaf.css;
15:
16: import java.io.IOException;
17: import java.util.ArrayList;
18: import java.util.List;
19: import org.wings.SComponent;
20: import org.wings.event.SParentFrameEvent;
21: import org.wings.event.SParentFrameListener;
22: import org.wings.header.SessionHeaders;
23: import org.wings.io.Device;
24: import org.wings.plaf.css.AbstractComponentCG;
25: import org.wings.plaf.css.Utils;
26: import org.wings.plaf.css.dwr.CallableManager;
27: import org.wings.plaf.css.script.OnHeadersLoadedScript;
28: import org.apache.commons.logging.Log;
29: import org.apache.commons.logging.LogFactory;
30: import org.wings.session.ScriptManager;
31: import org.wings.util.SStringBuilder;
32: import org.wingx.XPopupFrame;
33:
34: public class PopupFrameCG extends AbstractComponentCG implements
35: org.wingx.plaf.PopupFrameCG, SParentFrameListener {
36:
37: private final transient static Log log = LogFactory
38: .getLog(PopupFrameCG.class);
39:
40: protected final List headers = new ArrayList();
41:
42: public PopupFrameCG() {
43: headers
44: .add(Utils
45: .createExternalizedJSHeader("org/wingx/popupframe/popupframe.js"));
46: }
47:
48: public void writeInternal(Device device, SComponent component)
49: throws IOException {
50:
51: device.print("<div id='").print(component.getName()).print(
52: "' />");
53:
54: XPopupFrame popup = (XPopupFrame) component;
55:
56: SStringBuilder code = new SStringBuilder("function() {");
57: code.append("popupFrame = new wingS.PopupFrame('").append(
58: popup.getName()).append("',").append(popup.getWidth())
59: .append(",").append(popup.getHeight()).append(");")
60: .append("}");
61:
62: ScriptManager.getInstance().addScriptListener(
63: new OnHeadersLoadedScript(code.toString(), false));
64: }
65:
66: public void installCG(final SComponent comp) {
67: super .installCG(comp);
68: comp.addParentFrameListener(this );
69: }
70:
71: public void parentFrameAdded(SParentFrameEvent e) {
72: SessionHeaders.getInstance().registerHeaders(headers);
73:
74: // expose data source to java script by using DWR
75: CallableManager.getInstance().registerCallable("test",
76: e.getComponent(), SPopupFrameInterface.class);
77: }
78:
79: public void parentFrameRemoved(SParentFrameEvent e) {
80: SessionHeaders.getInstance().deregisterHeaders(headers);
81: CallableManager.getInstance().unregisterCallable("test");
82: }
83:
84: interface SPopupFrameInterface {
85: public String getFrameUrl();
86: }
87:
88: }
|