001 // Copyright May 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 net.sf.tacos.components.dojo; 015 016 import java.util.HashMap; 017 import java.util.Map; 018 import net.sf.tacos.util.JSONMarkupWriter; 019 import org.apache.tapestry.IMarkupWriter; 020 import org.apache.tapestry.IRequestCycle; 021 import org.apache.tapestry.IScript; 022 import org.apache.tapestry.TapestryUtils; 023 import org.apache.tapestry.json.JSONObject; 024 025 /** 026 * Implementation of dojo's TabContainer. 027 * 028 * @since 4.1.1 029 */ 030 public abstract class TabContainer extends GenericWidget 031 { 032 public abstract String getStyle(); 033 034 /** 035 * {@inheritDoc} 036 */ 037 public void renderWidget(IMarkupWriter writer, IRequestCycle cycle) 038 { 039 Object previous = null; 040 if (!cycle.isRewinding()) { 041 previous = cycle.getAttribute(TabContainer.class.getName()); 042 writer.begin(getTemplateTagName()); // use element specified 043 renderIdAttribute(writer, cycle); // render id="" client id 044 writer.attribute("style", getStyle()); 045 046 JSONMarkupWriter jsonWriter = new JSONMarkupWriter(); 047 renderInformalParameters(jsonWriter, cycle); 048 JSONObject json = jsonWriter.getAttributes(); 049 050 Map parms = new HashMap(); 051 parms.put("component", this); 052 parms.put("props", json.toString()); 053 054 getScript().execute(this, cycle, TapestryUtils.getPageRenderSupport(cycle, this), parms); 055 056 cycle.setAttribute(TabContainer.class.getName(), getClientId()); 057 } 058 059 renderBody(writer, cycle); 060 061 if (!cycle.isRewinding()) { 062 writer.end(); 063 cycle.setAttribute(TabContainer.class.getName(), previous); 064 } 065 } 066 067 /** Injected script. */ 068 public abstract IScript getScript(); 069 }