001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings.plaf.css;
014:
015: import org.apache.commons.logging.Log;
016: import org.apache.commons.logging.LogFactory;
017: import org.wings.*;
018: import org.wings.dnd.DragAndDropManager;
019: import org.wings.io.Device;
020: import org.wings.plaf.css.script.OnPageRenderedScript;
021: import org.wings.resource.ResourceNotFoundException;
022: import org.wings.script.*;
023: import org.wings.session.*;
024:
025: import java.io.IOException;
026: import java.util.*;
027:
028: /**
029: * PLAF renderer for SFrames in Portlets.
030: *
031: * @author Marc Musch
032: */
033: public final class PortletFrameCG extends FrameCG {
034:
035: private final static Log log = LogFactory
036: .getLog(PortletFrameCG.class);
037:
038: @Override
039: public void write(Device device, SComponent component)
040: throws IOException {
041: final SFrame frame = (SFrame) component;
042:
043: String strokes = strokes(frame.getGlobalInputMapComponents());
044: if (strokes != null)
045: component
046: .getSession()
047: .getScriptManager()
048: .addScriptListener(
049: new JavaScriptListener(null, null, strokes));
050:
051: if (!frame.isVisible())
052: return;
053: else
054: frame.fireRenderEvent(SComponent.START_RENDERING);
055:
056: device.print("<div class=\"wingsbody\"");
057: Utils.writeEvents(device, frame, null);
058: Utils.writeAllAttributes(device, frame);
059: device.print(">\n");
060:
061: // Render all headers
062: for (Object next : frame.getHeaders()) {
063: if (next instanceof Renderable) {
064: try {
065: ((Renderable) next).write(device);
066: } catch (ResourceNotFoundException e) {
067: log
068: .error(
069: "Unable to deliver inlined renderable",
070: e);
071: }
072: } else {
073: Utils.write(device, next.toString());
074: }
075: device.print("\n");
076: }
077:
078: // Focus management. Put focus in selected object.
079: if (frame.getFocus() != null) {
080: String script = "wingS.util.requestFocus('"
081: + frame.getFocus().getName() + "');";
082: ScriptManager.getInstance().addScriptListener(
083: new OnPageRenderedScript(script));
084: }
085:
086: // Write contents of the frame
087: if (frame.isVisible()) {
088: Utils.createExternalizedJSHeaderFromProperty(
089: Utils.JS_ETC_WZ_TOOLTIP).write(device);
090: device.print("\n");
091:
092: // Write components
093: frame.getLayout().write(device);
094:
095: // Write menus
096: device.print("\n\n<div id=\"wings_menues\">\n");
097: Set menues = frame.getSession().getMenuManager().getMenues(
098: frame);
099: for (Iterator i = menues.iterator(); i.hasNext();) {
100: SComponent menuItem = (SComponent) i.next();
101: menuItem.putClientProperty("popup", Boolean.TRUE);
102: menuItem.write(device);
103: menuItem.putClientProperty("popup", null);
104: }
105: device.print("\n</div>\n\n");
106:
107: DragAndDropManager dndManager = frame.getSession()
108: .getDragAndDropManager();
109: dndManager.getCG().write(device, dndManager);
110:
111: handleScripts(device, frame);
112: }
113:
114: // override js method for portlet
115: device
116: .print("<script type=\"text/javascript\">\n"
117: + "wingS.util.getReloadResource = function() {\n"
118: + "var splits = new Array();\n"
119: + "splits = wingS.global.reloadResource.split(\"org.wings.portlet.resourceAsParam=\");\n"
120: + "if(splits.length==2) {\n"
121: + "return splits[0] + \"org.wings.portlet.resourceAsParam=\" + wingS.global.eventEpoch + \"-\" + splits[1];\n"
122: + "}\n"
123: + "else {\n"
124: + "return wingS.global.reloadResource\n"
125: + "}\n"
126: + "};)\n"
127: + "wingS.util.getUpdateResource = function() {\n"
128: + "var splits = new Array();\n"
129: + "splits = wingS.global.reloadResource.split(\"org.wings.portlet.resourceAsParam=\");\n"
130: + "if(splits.length==2) {\n"
131: + "return splits[0] + \"org.wings.portlet.resourceAsParam=\" + wingS.global.eventEpoch + \"-\" + splits[1];\n"
132: + "}\n" + "else {\n"
133: + "return wingS.global.reloadResource\n"
134: + "}\n" + "};)\n" + "</script>");
135:
136: device.print("</div>\n");
137:
138: component.fireRenderEvent(SComponent.DONE_RENDERING);
139:
140: }
141:
142: }
|