Coverage Report - org.apache.tapestry.contrib.inspector.Inspector
 
Classes in this File Line Coverage Branch Coverage Complexity
Inspector
0%
0/23
0%
0/4
1.143
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 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  
 /**
 27  
  *  The Tapestry Inspector page.
 28  
  *
 29  
  *  @author Howard Lewis Ship
 30  
  **/
 31  
 
 32  0
 public abstract class Inspector extends BasePage
 33  
 {
 34  0
     private Map _blocks = new HashMap();
 35  
 
 36  
     protected void finishLoad()
 37  
     {
 38  0
         _blocks.put(View.TEMPLATE, getComponent("templateBlock"));
 39  0
         _blocks.put(View.SPECIFICATION, getComponent("specificationBlock"));
 40  0
         _blocks.put(View.ENGINE, getComponent("engineBlock"));
 41  0
         _blocks.put(View.PROPERTIES, getComponent("propertiesBlock"));
 42  0
     }
 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  
     /** 
 57  
      *  Invoked to change the component being inspected within the current
 58  
      *  page.
 59  
      *
 60  
      *  @since 1.0.6
 61  
      **/
 62  
 
 63  
     public void selectComponent(String idPath)
 64  
     {
 65  0
         setInspectedIdPath(idPath);
 66  0
     }
 67  
 
 68  
     /**
 69  
      *  Method invoked by the {@link InspectorButton} component, 
 70  
      *  to begin inspecting a page.
 71  
      *
 72  
      **/
 73  
 
 74  
     public void inspect(String pageName, IRequestCycle cycle)
 75  
     {
 76  0
         setInspectedPageName(pageName);
 77  0
         selectComponent((String) null);
 78  
 
 79  0
         cycle.activate(this);
 80  0
     }
 81  
 
 82  
     /**
 83  
      *  Listener for the component selection, which allows a particular component.  
 84  
      *  
 85  
      *  <p>The context is a single string,
 86  
      *  the id path of the component to be selected (or null to inspect
 87  
      *  the page itself).  This invokes
 88  
      *  {@link #selectComponent(String)}.
 89  
      *
 90  
      **/
 91  
 
 92  
     public void selectComponent(IRequestCycle cycle)
 93  
     {
 94  0
         Object[] parameters = cycle.getListenerParameters();
 95  
 
 96  
         String newIdPath;
 97  
 
 98  
         // The up button may generate a null context.
 99  
 
 100  0
         if (parameters == null || parameters.length == 0)
 101  0
             newIdPath = null;
 102  
         else
 103  0
             newIdPath = (String) parameters[0];
 104  
 
 105  0
         selectComponent(newIdPath);
 106  0
     }
 107  
 
 108  
     /**
 109  
      *  Returns the {@link IPage} currently inspected by the Inspector, as determined
 110  
      *  from the inspectedPageName property.
 111  
      *
 112  
      **/
 113  
 
 114  
     public IPage getInspectedPage()
 115  
     {
 116  0
         return getRequestCycle().getPage(getInspectedPageName());
 117  
     }
 118  
 
 119  
     /**
 120  
      *  Returns the {@link IComponent} current inspected; this is determined
 121  
      *  from the inspectedPageName and inspectedIdPath properties.
 122  
      *
 123  
      **/
 124  
 
 125  
     public IComponent getInspectedComponent()
 126  
     {
 127  0
         return getInspectedPage().getNestedComponent(getInspectedIdPath());
 128  
     }
 129  
 
 130  
     public String getInspectorTitle()
 131  
     {
 132  0
         return "Tapestry Inspector ";
 133  
     }
 134  
 
 135  
     /**
 136  
      *  Returns the {@link Block} for the currently selected view.
 137  
      *
 138  
      **/
 139  
 
 140  
     public Block getBlockForView()
 141  
     {
 142  0
         return (Block) _blocks.get(getView());
 143  
     }
 144  
 }