001 // Copyright Oct 16, 2006 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 package org.apache.tapestry.dojo.html; 015 016 import org.apache.tapestry.IMarkupWriter; 017 import org.apache.tapestry.IRequestCycle; 018 import org.apache.tapestry.IScript; 019 import org.apache.tapestry.TapestryUtils; 020 import org.apache.tapestry.dojo.AbstractWidget; 021 import org.apache.tapestry.json.JSONObject; 022 023 import java.util.HashMap; 024 import java.util.Map; 025 026 027 /** 028 * Implementation of dojo Dialog widget. 029 * 030 */ 031 public abstract class Dialog extends AbstractWidget 032 { 033 public abstract boolean isHidden(); 034 public abstract void setHidden(boolean hidden); 035 036 public abstract String getBackgroundColor(); 037 038 public abstract float getOpacity(); 039 040 public abstract boolean getFollowScroll(); 041 042 public abstract boolean getCloseOnBackgroundClick(); 043 044 public abstract int getBlockDuration(); 045 046 public abstract int getLifeTime(); 047 048 public abstract String getToggle(); 049 050 public abstract int getToggleDuration(); 051 052 public void show() 053 { 054 setHidden(false); 055 } 056 057 public void hide() 058 { 059 setHidden(true); 060 } 061 062 /** 063 * {@inheritDoc} 064 */ 065 public void renderWidget(IMarkupWriter writer, IRequestCycle cycle) 066 { 067 if (!cycle.isRewinding()) 068 { 069 writer.begin(getTemplateTagName()); // use element specified 070 renderIdAttribute(writer, cycle); // render id="" client id 071 renderInformalParameters(writer, cycle); 072 } 073 074 renderBody(writer, cycle); 075 076 if (!cycle.isRewinding()) 077 writer.end(); 078 079 if (!cycle.isRewinding()) 080 { 081 JSONObject json = new JSONObject(); 082 json.put("bgColor", getBackgroundColor()); 083 json.put("bgOpacity", getOpacity()); 084 json.put("followScroll", getFollowScroll()); 085 json.put("closeOnBackgroundClick", getCloseOnBackgroundClick()); 086 json.put("blockDuration", getBlockDuration()); 087 json.put("lifeTime", getLifeTime()); 088 json.put("toggle", getToggle()); 089 json.put("toggleDuration", getToggleDuration()); 090 091 Map parms = new HashMap(); 092 parms.put("component", this); 093 parms.put("props", json.toString()); 094 095 getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms); 096 } 097 } 098 099 /** injected. */ 100 public abstract IScript getScript(); 101 }