001 /*
002 * Apache License
003 * Version 2.0, January 2004
004 * http://www.apache.org/licenses/
005 *
006 * Copyright 2008-2010 by chenillekit.org
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 */
014
015 package org.chenillekit.tapestry.core.components;
016
017 import org.apache.tapestry5.MarkupWriter;
018 import org.apache.tapestry5.annotations.AfterRender;
019 import org.apache.tapestry5.annotations.AfterRenderBody;
020 import org.apache.tapestry5.annotations.BeforeRenderBody;
021 import org.apache.tapestry5.annotations.Environmental;
022 import org.apache.tapestry5.json.JSONObject;
023 import org.apache.tapestry5.services.javascript.JavaScriptSupport;
024 import org.chenillekit.tapestry.core.base.AbstractWindow;
025
026 /**
027 * creates a window based on jvascript <a href="http://prototype-window.xilinus.com/">window</a> library.
028 *
029 * @version $Id: Window.java 684 2010-08-03 13:35:50Z homburgs $
030 */
031 public class Window extends AbstractWindow
032 {
033 @Environmental
034 private JavaScriptSupport javascriptSupport;
035
036 private boolean hasBody = false;
037
038 /**
039 * Tapestry render phase method.
040 * Called before component body is rendered.
041 *
042 * @param writer the markup writer
043 */
044
045 private String contentDivId;
046
047 @BeforeRenderBody
048 void beforeRenderBody(MarkupWriter writer)
049 {
050 contentDivId = javascriptSupport.allocateClientId(getClientId() + "Content");
051 hasBody = true;
052 writer.element("div",
053 "id", contentDivId,
054 "style", "display:none;");
055 }
056
057 /**
058 * Tapestry render phase method.
059 * Called after component body is rendered.
060 * return false to render body again.
061 *
062 * @param writer the markup writer
063 */
064 @AfterRenderBody
065 void afterRenderBody(MarkupWriter writer)
066 {
067 writer.end();
068 }
069
070
071 /**
072 * Tapestry render phase method. End a tag here.
073 *
074 * @param writer the markup writer
075 */
076 @AfterRender
077 void afterRender(MarkupWriter writer)
078 {
079 JSONObject options = new JSONObject();
080
081 options.put("className", getClassName());
082 options.put("width", getWidth());
083 options.put("height", getHeight());
084 options.put("id", getClientId());
085 options.put("title", getTitle());
086
087 //
088 // Let subclasses do more.
089 //
090 configure(options);
091
092 JSONObject ckOptions = new JSONObject();
093 ckOptions.put("windowoptions", options);
094 ckOptions.put("hasbody", hasBody);
095 ckOptions.put("show", isShow());
096 ckOptions.put("center", isCenter());
097 ckOptions.put("modal", isModal());
098 ckOptions.put("clientid", getClientId());
099 ckOptions.put("contentid", contentDivId);
100
101 javascriptSupport.addInitializerCall("ckwindow", ckOptions);
102 }
103 }