KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > workbench > components > Border


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.workbench.components;
16
17 import org.apache.tapestry.BaseComponent;
18 import org.apache.tapestry.IAsset;
19 import org.apache.tapestry.IRequestCycle;
20 import org.apache.tapestry.TapestryUtils;
21 import org.apache.tapestry.annotations.Asset;
22 import org.apache.tapestry.annotations.InjectAsset;
23 import org.apache.tapestry.annotations.InjectState;
24 import org.apache.tapestry.annotations.Message;
25 import org.apache.tapestry.event.PageBeginRenderListener;
26 import org.apache.tapestry.event.PageEvent;
27 import org.apache.tapestry.workbench.Visit;
28
29 /**
30  * Common navigational border for the Workbench tutorial.
31  *
32  * @author Howard Lewis Ship
33  * @since 1.0.7
34  */

35
36 public abstract class Border extends BaseComponent implements PageBeginRenderListener
37 {
38
39     /**
40      * Array of page names, read from the Strings file; this is the same regardless of localization,
41      * so it is static (shared by all).
42      */

43
44     private static String JavaDoc[] _tabOrder;
45
46     @InjectState("visit")
47     public abstract Visit getVisit();
48
49     @Message
50     public abstract String JavaDoc getTabOrder();
51
52     public void pageBeginRender(PageEvent event)
53     {
54         Visit visit = getVisit();
55
56         setActivePageName(visit.getActiveTabName());
57
58         if (_tabOrder == null)
59             _tabOrder = TapestryUtils.split(getTabOrder(), ' ');
60     }
61
62     /**
63      * Returns the logical names of the pages accessible via the navigation bar, in appopriate
64      * order.
65      */

66
67     public String JavaDoc[] getPageTabNames()
68     {
69         return _tabOrder;
70     }
71
72     public abstract void setPageName(String JavaDoc value);
73
74     public abstract String JavaDoc getPageName();
75
76     public abstract void setActivePageName(String JavaDoc activePageName);
77
78     public abstract String JavaDoc getActivePageName();
79
80     public boolean isActivePage()
81     {
82         return getPageName().equals(getActivePageName());
83     }
84
85     public String JavaDoc getPageTitle()
86     {
87         // Need to check for synchronization issues, but I think
88
// ResourceBundle is safe.
89

90         return getMessages().getMessage(getPageName());
91     }
92
93     // Arbitrary mix of @Asset and @InjectAsset just to
94
// test the annotations.
95

96     @Asset("images/tab-active-left.gif")
97     public abstract IAsset getActiveLeft();
98
99     @InjectAsset("inactiveLeft")
100     public abstract IAsset getInactiveLeft();
101
102     @Asset("images/tab-active-mid.gif")
103     public abstract IAsset getActiveMid();
104
105     @InjectAsset("inactiveMid")
106     public abstract IAsset getInactiveMid();
107
108     @Asset("images/tab-active-right.gif")
109     public abstract IAsset getActiveRight();
110
111     @InjectAsset("inactiveRight")
112     public abstract IAsset getInactiveRight();
113
114     public IAsset getLeftTabAsset()
115     {
116         return isActivePage() ? getActiveLeft() : getInactiveLeft();
117     }
118
119     public IAsset getMidTabAsset()
120     {
121         return isActivePage() ? getActiveMid() : getInactiveMid();
122     }
123
124     public IAsset getRightTabAsset()
125     {
126         return isActivePage() ? getActiveRight() : getInactiveRight();
127     }
128
129     public void selectPage(IRequestCycle cycle, String JavaDoc newPageName)
130     {
131         Visit visit = getVisit();
132
133         visit.setActiveTabName(newPageName);
134
135         cycle.activate(newPageName);
136     }
137 }
Popular Tags