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 void show() 041 { 042 setHidden(false); 043 } 044 045 public void hide() 046 { 047 setHidden(true); 048 } 049 050 /** 051 * {@inheritDoc} 052 */ 053 public void renderWidget(IMarkupWriter writer, IRequestCycle cycle) 054 { 055 if (!cycle.isRewinding()) 056 { 057 writer.begin(getTemplateTagName()); // use element specified 058 renderIdAttribute(writer, cycle); // render id="" client id 059 renderInformalParameters(writer, cycle); 060 } 061 062 renderBody(writer, cycle); 063 064 if (!cycle.isRewinding()) 065 writer.end(); 066 067 if (!cycle.isRewinding()) 068 { 069 JSONObject json = new JSONObject(); 070 json.put("bgColor", getBackgroundColor()); 071 json.put("bgOpacity", getOpacity()); 072 073 Map parms = new HashMap(); 074 parms.put("component", this); 075 parms.put("props", json.toString()); 076 077 getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms); 078 } 079 } 080 081 /** injected. */ 082 public abstract IScript getScript(); 083 }