KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > icefaces > samples > showcase > navigation > PageContentBean


1 /*
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * "The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
11  * License for the specific language governing rights and limitations under
12  * the License.
13  *
14  * The Original Code is ICEfaces 1.5 open source software code, released
15  * November 5, 2006. The Initial Developer of the Original Code is ICEsoft
16  * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C)
17  * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved.
18  *
19  * Contributor(s): _____________________.
20  *
21  * Alternatively, the contents of this file may be used under the terms of
22  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"
23  * License), in which case the provisions of the LGPL License are
24  * applicable instead of those above. If you wish to allow use of your
25  * version of this file only under the terms of the LGPL License and not to
26  * allow others to use your version of this file under the MPL, indicate
27  * your decision by deleting the provisions above and replace them with
28  * the notice and other provisions required by the LGPL License. If you do
29  * not delete the provisions above, a recipient may use your version of
30  * this file under either the MPL or the LGPL License."
31  *
32  */

33
34 package com.icesoft.icefaces.samples.showcase.navigation;
35
36 import com.icesoft.faces.component.tree.IceUserObject;
37 import com.icesoft.icefaces.samples.showcase.util.StyleBean;
38
39 import javax.faces.context.FacesContext;
40 import javax.faces.event.ActionEvent;
41 import java.util.Locale JavaDoc;
42 import java.util.ResourceBundle JavaDoc;
43
44 /**
45  * <p>The PageContentBean class is responsible for holding state information
46  * which will allow a TreeNavigation and NavigationBean display dynamic content.
47  * </p>
48  *
49  * @since 0.3.0
50  */

51 public class PageContentBean extends IceUserObject {
52
53     // template, default panel to make visible in a panel stack
54
private String JavaDoc templateName = "";
55
56     // text to be displayed in navigation link
57
private String JavaDoc menuDisplayText;
58     // title information to be displayed
59
private String JavaDoc menuContentTitle;
60     private String JavaDoc menuContentInclusionFile;
61
62     // True indicates that there is content associated with link and as a
63
// result templateName and contentPanelName can be used. Otherwise we
64
// just toggle the branch visibility.
65
private boolean pageContent = true;
66
67     // Each component example needs extra information to be displayed. These
68
// variables store that information
69

70     // message bundle for component.
71
private static ResourceBundle JavaDoc messages = null;
72
73     // view reference to control the visible content
74
private NavigationBean navigationBean;
75
76     /**
77      * Build a default node for the tree. We also change the default icon and
78      * always expand branches.
79      */

80     public PageContentBean() {
81         super(null);
82         init();
83     }
84
85     /**
86      * Initialize internationalization.
87      */

88     private void init() {
89
90         setBranchContractedIcon(StyleBean.XP_BRANCH_CONTRACTED_ICON);
91         setBranchExpandedIcon(StyleBean.XP_BRANCH_EXPANDED_ICON);
92         setLeafIcon("./images/gear.gif");
93         setExpanded(true);
94
95         Locale JavaDoc locale =
96                 FacesContext.getCurrentInstance().getViewRoot().getLocale();
97         // assign a default locale if the faces context has none, shouldn't happen
98
if (locale == null) {
99             locale = Locale.ENGLISH;
100         }
101         messages = ResourceBundle.getBundle(
102                 "com.icesoft.icefaces.samples.showcase.resources.messages",
103                 locale);
104     }
105
106     /**
107      * Gets the navigation callback.
108      *
109      * @return NavigationBean.
110      */

111     public NavigationBean getNavigationSelection() {
112         return navigationBean;
113     }
114
115     /**
116      * Sets the navigation callback.
117      *
118      * @param navigationBean controls selected panel state.
119      */

120     public void setNavigationSelection(NavigationBean navigationBean) {
121         this.navigationBean = navigationBean;
122     }
123
124     /**
125      * Gets the template name to display in the showcase.jspx. The template is
126      * a panel in a panel stack which will be made visible.
127      *
128      * @return panel stack template name.
129      */

130     public String JavaDoc getTemplateName() {
131         return templateName;
132     }
133
134     /**
135      * Sets the template name to be displayed when selected in tree. Selection
136      * will only occur if pageContent is true.
137      *
138      * @param templateName valid panel name in showcase.jspx
139      */

140     public void setTemplateName(String JavaDoc templateName) {
141         this.templateName = templateName;
142     }
143
144     /**
145      * Gets the menu display text. This text will be shown in the navigation
146      * tree.
147      *
148      * @return menu display text.
149      */

150     public String JavaDoc getMenuDisplayText() {
151         // get localized string value
152
return messages.getString(menuDisplayText);
153     }
154
155     /**
156      * Sets the text to be displayed in the menu. This text string must match a
157      * resource property in com.icesoft.icefaces.samples.showcase.resources.messages
158      *
159      * @param menuDisplayText menu text to display
160      */

161     public void setMenuDisplayText(String JavaDoc menuDisplayText) {
162         if (menuDisplayText != null) {
163             this.menuDisplayText = menuDisplayText;
164             // set tree node text value
165
setText(getMenuDisplayText());
166         } else {
167             this.menuDisplayText = "";
168         }
169     }
170
171     /**
172      * Get the text to be displayed as the content title. This text string must
173      * match resource property in com.icesoft.icefaces.samples.showcase.resources.messages
174      *
175      * @return menu content title
176      */

177     public String JavaDoc getMenuContentTitle() {
178         if (menuContentTitle != null && !menuContentTitle.equals("")) {
179             return messages.getString(menuContentTitle);
180         } else {
181             return "";
182         }
183     }
184
185     /**
186      * Sets the menu content title.
187      *
188      * @param menuContentTitle menu content title name.
189      */

190     public void setMenuContentTitle(String JavaDoc menuContentTitle) {
191         if (menuContentTitle != null) {
192             this.menuContentTitle = menuContentTitle;
193         } else {
194             this.menuContentTitle = "";
195         }
196     }
197     
198     public String JavaDoc getMenuContentInclusionFile() {
199         return menuContentInclusionFile;
200     }
201
202     /**
203      * This is necessary for the Facelets version of component-showcase.
204      * Unlike the JSP version of component-showcase, which uses static includes,
205      * the Facelets version uses dynamic inclusion tied to an EL expression,
206      * which will call getMenuContentInclusionFile().
207      *
208      * @param menuContentInclusionFile The server-side path to the file to be included
209      */

210     public void setMenuContentInclusionFile(String JavaDoc menuContentInclusionFile) {
211         this.menuContentInclusionFile = menuContentInclusionFile;
212     }
213
214     /**
215      * Does the node contain content.
216      *
217      * @return true if the page contains content; otherwise, false.
218      */

219     public boolean isPageContent() {
220         return pageContent;
221     }
222
223     /**
224      * Sets the page content.
225      *
226      * @param pageContent True if the page contains content; otherwise, false.
227      */

228     public void setPageContent(boolean pageContent) {
229         this.pageContent = pageContent;
230     }
231
232     /**
233      * Sets the navigationSelectionBeans selected state
234      */

235     public void contentVisibleAction(ActionEvent event) {
236         if (isPageContent()) {
237             // only toggle the branch expansion if we have already selected the node
238
if (navigationBean.getSelectedPanel().equals(this)) {
239                 // toggle the branch node expansion
240
setExpanded(!isExpanded());
241             }
242             navigationBean.setSelectedPanel(this);
243         }
244         // Otherwise toggle the node visibility, only changes the state
245
// of the nodes with children.
246
else {
247             setExpanded(!isExpanded());
248         }
249     }
250 }
Popular Tags