KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > inspector > Inspector


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 JavaDoc;
18 import java.util.Map JavaDoc;
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 public abstract class Inspector extends BasePage
33 {
34     private Map JavaDoc _blocks = new HashMap JavaDoc();
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 JavaDoc getView();
45
46     public abstract void setView(String JavaDoc value);
47
48     public abstract String JavaDoc getInspectedPageName();
49     
50     public abstract void setInspectedPageName(String JavaDoc value);
51
52     public abstract String JavaDoc getInspectedIdPath();
53
54     public abstract void setInspectedIdPath(String JavaDoc 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 JavaDoc idPath)
64     {
65         setInspectedIdPath(idPath);
66     }
67
68     /**
69      * Method invoked by the {@link InspectorButton} component,
70      * to begin inspecting a page.
71      *
72      **/

73
74     public void inspect(String JavaDoc pageName, IRequestCycle cycle)
75     {
76         setInspectedPageName(pageName);
77         selectComponent((String JavaDoc) null);
78
79         cycle.activate(this);
80     }
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         Object JavaDoc[] parameters = cycle.getListenerParameters();
95
96         String JavaDoc newIdPath;
97
98         // The up button may generate a null context.
99

100         if (parameters == null || parameters.length == 0)
101             newIdPath = null;
102         else
103             newIdPath = (String JavaDoc) parameters[0];
104
105         selectComponent(newIdPath);
106     }
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         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         return getInspectedPage().getNestedComponent(getInspectedIdPath());
128     }
129
130     public String JavaDoc getInspectorTitle()
131     {
132         return "Tapestry Inspector: " + getEngine().getSpecification().getName();
133     }
134
135     /**
136      * Returns the {@link Block} for the currently selected view.
137      *
138      **/

139
140     public Block getBlockForView()
141     {
142         return (Block) _blocks.get(getView());
143     }
144 }
Popular Tags