1 15 package org.apache.tapestry.contrib.inspector; 16 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 import org.apache.tapestry.IComponent; 21 import org.apache.tapestry.IPage; 22 import org.apache.tapestry.IRequestCycle; 23 import org.apache.tapestry.components.Block; 24 import org.apache.tapestry.html.BasePage; 25 26 31 32 public abstract class Inspector extends BasePage 33 { 34 private Map _blocks = new HashMap (); 35 36 protected void finishLoad() 37 { 38 _blocks.put(View.TEMPLATE, getComponent("templateBlock")); 39 _blocks.put(View.SPECIFICATION, getComponent("specificationBlock")); 40 _blocks.put(View.ENGINE, getComponent("engineBlock")); 41 _blocks.put(View.PROPERTIES, getComponent("propertiesBlock")); 42 } 43 44 public abstract String getView(); 45 46 public abstract void setView(String value); 47 48 public abstract String getInspectedPageName(); 49 50 public abstract void setInspectedPageName(String value); 51 52 public abstract String getInspectedIdPath(); 53 54 public abstract void setInspectedIdPath(String value); 55 56 62 63 public void selectComponent(String idPath) 64 { 65 setInspectedIdPath(idPath); 66 } 67 68 73 74 public void inspect(String pageName, IRequestCycle cycle) 75 { 76 setInspectedPageName(pageName); 77 selectComponent((String ) null); 78 79 cycle.activate(this); 80 } 81 82 91 92 public void selectComponent(IRequestCycle cycle) 93 { 94 Object [] parameters = cycle.getListenerParameters(); 95 96 String newIdPath; 97 98 100 if (parameters == null || parameters.length == 0) 101 newIdPath = null; 102 else 103 newIdPath = (String ) parameters[0]; 104 105 selectComponent(newIdPath); 106 } 107 108 113 114 public IPage getInspectedPage() 115 { 116 return getRequestCycle().getPage(getInspectedPageName()); 117 } 118 119 124 125 public IComponent getInspectedComponent() 126 { 127 return getInspectedPage().getNestedComponent(getInspectedIdPath()); 128 } 129 130 public String getInspectorTitle() 131 { 132 return "Tapestry Inspector: " + getEngine().getSpecification().getName(); 133 } 134 135 139 140 public Block getBlockForView() 141 { 142 return (Block) _blocks.get(getView()); 143 } 144 } | Popular Tags |