001: package org.contineo.web.navigation;
002:
003: import com.icesoft.faces.component.tree.IceUserObject;
004:
005: import org.contineo.core.security.Menu;
006:
007: import org.contineo.web.StyleBean;
008:
009: import javax.faces.event.ActionEvent;
010:
011: /**
012: * <p>
013: * The PageContentBean class is responsible for holding state information which
014: * will allow a TreeNavigation and NavigationBean display dynamic content.
015: * </p>
016: *
017: * @author Marco Meschieri
018: * @version $Id: PageContentBean.java,v 1.10 2006/09/03 11:40:19 marco Exp $
019: * @since 3.0
020: */
021: public class PageContentBean extends IceUserObject {
022: private Menu menu;
023:
024: // template, default panel to make visible in a panel stack
025: private String contentName = "";
026:
027: // text to be displayed in navigation link
028: private String displayText;
029:
030: // title information to be displayed
031: private String contentTitle;
032: private String template = "";
033: private boolean pageContent = true;
034:
035: // view reference to control the visible content
036: private NavigationBean navigationBean;
037:
038: public PageContentBean(String contentName) {
039: this ();
040: setIcon(StyleBean.getImagePath("spacer.gif"));
041: this .contentName = contentName;
042: }
043:
044: public PageContentBean(String contentName, String template) {
045: this (contentName);
046: this .template = template;
047: }
048:
049: public PageContentBean() {
050: super (null);
051: init();
052: }
053:
054: public PageContentBean(Menu menu) {
055: this ();
056: this .menu = menu;
057: }
058:
059: /**
060: * Initialize internationalization.
061: */
062: private void init() {
063: setBranchContractedIcon(StyleBean.XP_BRANCH_CONTRACTED_ICON);
064: setBranchExpandedIcon(StyleBean.XP_BRANCH_EXPANDED_ICON);
065: setLeafIcon(StyleBean.XP_BRANCH_CONTRACTED_ICON);
066: setExpanded(false);
067: setLeaf(false);
068: setIcon(StyleBean.getImagePath("spacer.gif"));
069: }
070:
071: /**
072: * Gets the navigation callback.
073: *
074: * @return NavigationBean.
075: */
076: public NavigationBean getNavigationSelection() {
077: return navigationBean;
078: }
079:
080: /**
081: * Sets the navigation callback.
082: *
083: * @param navigationBean controls selected panel state.
084: */
085: public void setNavigationSelection(NavigationBean navigationBean) {
086: this .navigationBean = navigationBean;
087: }
088:
089: /**
090: * Gets the template name to display in the showcase.jspx. The template is a
091: * panel in a panel stack which will be made visible.
092: *
093: * @return panel stack template name.
094: */
095: public String getContentName() {
096: return contentName;
097: }
098:
099: /**
100: * Sets the template name to be displayed when selected in tree. Selection
101: * will only occur if pageContent is true.
102: *
103: * @param contentName valid panel name in showcase.jspx
104: */
105: public void setContentName(String templateName) {
106: this .contentName = templateName;
107: }
108:
109: /**
110: * Gets the menu display text. This text will be shown in the navigation
111: * control.
112: *
113: * @return menu display text.
114: */
115: public String getDisplayText() {
116: return displayText;
117: }
118:
119: /**
120: * Sets the text to be displayed in the menu. This text string must match a
121: * resource property in
122: * com.icesoft.icefaces.samples.showcase.resources.messages
123: *
124: * @param displayText menu text to display
125: */
126: public void setDisplayText(String menuDisplayText) {
127: this .displayText = menuDisplayText;
128: setText(getDisplayText());
129: }
130:
131: /**
132: * Get the text to be displayed as the content title. This text string must
133: * match resource property in
134: * com.icesoft.icefaces.samples.showcase.resources.messages
135: *
136: * @return menu content title
137: */
138: public String getContentTitle() {
139: return contentTitle;
140: }
141:
142: /**
143: * Sets the menu content title.
144: *
145: * @param contentTitle menu content title name.
146: */
147: public void setContentTitle(String menuContentTitle) {
148: this .contentTitle = menuContentTitle;
149: }
150:
151: public String getTemplate() {
152: return template;
153: }
154:
155: /**
156: * This is necessary for the Facelets version of component-showcase. Unlike
157: * the JSP version of component-showcase, which uses static includes, the
158: * Facelets version uses dynamic inclusion tied to an EL expression, which
159: * will call getMenuContentInclusionFile().
160: *
161: * @param template The server-side path to the file to be included
162: */
163: public void setTemplate(String menuContentInclusionFile) {
164: this .template = menuContentInclusionFile;
165: }
166:
167: /**
168: * Does the node contain content.
169: *
170: * @return true if the page contains content; otherwise, false.
171: */
172: public boolean isPageContent() {
173: return pageContent;
174: }
175:
176: /**
177: * Sets the page content.
178: *
179: * @param pageContent True if the page contains content; otherwise, false.
180: */
181: public void setPageContent(boolean pageContent) {
182: this .pageContent = pageContent;
183: }
184:
185: public Menu getMenu() {
186: return menu;
187: }
188:
189: public int getMenuId() {
190: if (menu != null) {
191: return menu.getMenuId();
192: } else {
193: return -1;
194: }
195: }
196:
197: public void setMenu(Menu menu) {
198: this .menu = menu;
199: }
200:
201: public String getIcon() {
202: return icon;
203: }
204:
205: public void setIcon(String icon) {
206: this .icon = icon;
207: }
208:
209: /**
210: * Item selection handler
211: */
212: public void onSelect(ActionEvent event) {
213: if (isPageContent()) {
214: if (navigationBean == null) {
215: return;
216: }
217:
218: // only toggle the branch expansion if we have already selected the
219: // node
220: if (navigationBean.getSelectedPanel().equals(this )) {
221: // toggle the branch node expansion
222: setExpanded(!isExpanded());
223: }
224:
225: navigationBean.setSelectedPanel(this );
226: }
227: // Otherwise toggle the node visibility, only changes the state
228: // of the nodes with children.
229: else {
230: setExpanded(!isExpanded());
231: }
232: }
233:
234: @Override
235: public boolean equals(Object obj) {
236: PageContentBean other = (PageContentBean) obj;
237:
238: if ((other != null) && (other.getContentName() != null)
239: && (contentName != null)) {
240: return this .contentName.equals(other.getContentName());
241: } else {
242: return false;
243: }
244: }
245:
246: @Override
247: public String toString() {
248: return displayText;
249: }
250: }
|