KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
37  * Component that can be placed into application pages that will launch the inspector in a new
38  * window. [ <a HREF="../../../../../../ComponentReference/InspectorButton.html">Component Reference
39  * </a>]
40  * <p>
41  * Because the InspectorButton component is implemented using a
42  * {@link org.apache.tapestry.html.Rollover}, the containing page must use a {@link Body}component
43  * instead of a &lt;body&gt; tag.
44  *
45  * @author Howard Lewis Ship
46  */

47
48 public abstract class InspectorButton extends BaseComponent implements IDirect
49 {
50     private boolean _disabled = false;
51
52     /**
53      * Gets the listener for the link component.
54      *
55      * @since 1.0.5
56      */

57
58     public void trigger(IRequestCycle cycle)
59     {
60         String JavaDoc name = getNamespace().constructQualifiedName("Inspector");
61
62         Inspector inspector = (Inspector) cycle.getPage(name);
63
64         inspector.inspect(getPage().getPageName(), cycle);
65     }
66
67     /**
68      * Renders the script, then invokes the normal implementation.
69      *
70      * @since 1.0.5
71      */

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 JavaDoc symbols = new HashMap JavaDoc();
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         // Now, go render the rest from the template.
98

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     /**
113      * Always returns false.
114      *
115      * @since 2.3
116      */

117
118     public boolean isStateful()
119     {
120         return false;
121     }
122
123 }
Popular Tags