001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme.impl.render.dynamic;
023:
024: import org.jboss.portal.theme.render.AbstractObjectRenderer;
025: import org.jboss.portal.theme.render.RenderException;
026: import org.jboss.portal.theme.render.RendererContext;
027: import org.jboss.portal.theme.render.renderer.WindowRenderer;
028: import org.jboss.portal.theme.render.renderer.WindowRendererContext;
029:
030: import java.io.PrintWriter;
031:
032: /**
033: * Implementation of a drag and drop WindowRenderer.
034: *
035: * @author <a href="mailto:tomasz.szymanski@jboss.com">Tomasz Szymanski</a>
036: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
037: * @version $LastChangedRevision: 8784 $, $LastChangedDate: 2007-10-27 19:01:46 -0400 (Sat, 27 Oct 2007) $
038: * @see org.jboss.portal.theme.render.renderer.WindowRenderer
039: */
040: public class DynaWindowRenderer extends AbstractObjectRenderer
041: implements WindowRenderer {
042:
043: //
044: private WindowRenderer delegate;
045:
046: static final ThreadLocal handleProvided = new ThreadLocal();
047:
048: public DynaWindowRenderer(WindowRenderer windowRenderer)
049: throws InstantiationException, IllegalAccessException,
050: ClassNotFoundException {
051: super ();
052: delegate = windowRenderer;
053: }
054:
055: /** @see org.jboss.portal.theme.render.renderer.WindowRenderer#render */
056: public void render(RendererContext rendererContext,
057: WindowRendererContext wrc) throws RenderException {
058: // Get render options
059: DynaRenderOptions parentOptions = (DynaRenderOptions) rendererContext
060: .getAttribute(DynaConstants.RENDER_OPTIONS);
061:
062: // It could be null if the parent renderers are not dyna renderers
063: if (parentOptions == null) {
064: parentOptions = DynaRenderOptions.NO_AJAX;
065: }
066:
067: //
068: try {
069: String dndValue = wrc
070: .getProperty(DynaRenderOptions.DND_ENABLED);
071: String partialRefreshValue = wrc
072: .getProperty(DynaRenderOptions.PARTIAL_REFRESH_ENABLED);
073: DynaRenderOptions windowOptions = DynaRenderOptions
074: .getOptions(dndValue, partialRefreshValue);
075:
076: //
077: DynaRenderOptions options = DynaMergeBehavior
078: .mergeForWindow(parentOptions, windowOptions);
079: rendererContext.setAttribute(DynaConstants.RENDER_OPTIONS,
080: options);
081:
082: //
083: PrintWriter out = rendererContext.getWriter();
084:
085: //
086: if (!DynaRenderOptions.NO_AJAX.equals(parentOptions)) {
087: out.print("<div class=\"dyna-window\">");
088: out.print("<div id=\"");
089: out.print(wrc.getId());
090: if (options.isDnDEnabled()) {
091: if (options.isPartialRefreshEnabled()) {
092: out
093: .print("\" class=\"dnd-window partial-refresh-window\">\n");
094: } else {
095: out.print("\" class=\"dnd-window\">\n");
096: }
097: } else {
098: if (options.isPartialRefreshEnabled()) {
099: out
100: .print("\" class=\"partial-refresh-window\">\n");
101: } else {
102: out.print("\">\n");
103: }
104: }
105:
106: //
107: delegate.render(rendererContext, wrc);
108:
109: //
110: out.print("</div></div>\n");
111: } else {
112: delegate.render(rendererContext, wrc);
113: }
114:
115: //
116: handleProvided.set(null);
117: } finally {
118: rendererContext.setAttribute(DynaConstants.RENDER_OPTIONS,
119: parentOptions);
120: }
121: }
122: }
|