1 15 package org.apache.tapestry.contrib.inspector; 16 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import org.apache.hivemind.Resource; 21 import org.apache.tapestry.BaseComponent; 22 import org.apache.tapestry.IDirect; 23 import org.apache.tapestry.IEngine; 24 import org.apache.tapestry.IMarkupWriter; 25 import org.apache.tapestry.IRequestCycle; 26 import org.apache.tapestry.IScript; 27 import org.apache.tapestry.PageRenderSupport; 28 import org.apache.tapestry.Tapestry; 29 import org.apache.tapestry.TapestryUtils; 30 import org.apache.tapestry.engine.DirectServiceParameter; 31 import org.apache.tapestry.engine.IEngineService; 32 import org.apache.tapestry.engine.ILink; 33 import org.apache.tapestry.engine.IScriptSource; 34 import org.apache.tapestry.html.Body; 35 36 47 48 public abstract class InspectorButton extends BaseComponent implements IDirect 49 { 50 private boolean _disabled = false; 51 52 57 58 public void trigger(IRequestCycle cycle) 59 { 60 String name = getNamespace().constructQualifiedName("Inspector"); 61 62 Inspector inspector = (Inspector) cycle.getPage(name); 63 64 inspector.inspect(getPage().getPageName(), cycle); 65 } 66 67 72 73 protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) 74 { 75 if (_disabled || cycle.isRewinding()) 76 return; 77 78 IEngine engine = getPage().getEngine(); 79 IScriptSource source = engine.getScriptSource(); 80 81 Resource scriptLocation = getSpecification().getSpecificationLocation() 82 .getRelativeResource("InspectorButton.script"); 83 84 IScript script = source.getScript(scriptLocation); 85 86 Map symbols = new HashMap (); 87 88 IEngineService service = engine.getService(Tapestry.DIRECT_SERVICE); 89 ILink link = service.getLink(cycle, new DirectServiceParameter(this)); 90 91 symbols.put("URL", link.getURL()); 92 93 PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle, this); 94 95 script.execute(cycle, pageRenderSupport, symbols); 96 97 99 super.renderComponent(writer, cycle); 100 } 101 102 public boolean isDisabled() 103 { 104 return _disabled; 105 } 106 107 public void setDisabled(boolean disabled) 108 { 109 _disabled = disabled; 110 } 111 112 117 118 public boolean isStateful() 119 { 120 return false; 121 } 122 123 } | Popular Tags |