01: package org.contineo.web.navigation;
02:
03: import java.util.Stack;
04:
05: /**
06: * <p>
07: * The NavigationBean class is responsible for storing the state of the panel
08: * stacks which display dynamic content.
09: * </p>
10: *
11: * @author Marco Meschieri, Alessandro Gasparini
12: * @version $Id: NavigationBean.java,v 1.3 2006/08/29 16:33:46 marco Exp $
13: * @since 3.0
14: */
15: public class NavigationBean {
16: // selected page content bean.
17: private PageContentBean selectedPanel = null;
18:
19: // Maintains the history of accessed pages, useful for back buttons
20: private Stack<PageContentBean> history = new Stack<PageContentBean>();
21:
22: public NavigationBean() {
23: super ();
24: }
25:
26: /**
27: * Gets the currently selected content panel.
28: *
29: * @return currently selected content panel.
30: */
31: public PageContentBean getSelectedPanel() {
32: return selectedPanel;
33: }
34:
35: /**
36: * Sets the selected panel to the specified content.
37: *
38: * @param content a not null page content bean.
39: */
40: public void setSelectedPanel(PageContentBean content) {
41: if ((content != null) && content.isPageContent()
42: && !content.equals(this .selectedPanel)) {
43: if (this .selectedPanel != null) {
44: // Update history
45: history.push(this .selectedPanel);
46:
47: if (history.size() > 10) {
48: history.setSize(10);
49: }
50: }
51:
52: this .selectedPanel = content;
53: }
54: }
55:
56: /**
57: * Handles back button
58: */
59: public String back() {
60: if (!history.isEmpty()) {
61: selectedPanel = history.pop();
62: }
63:
64: return null;
65: }
66:
67: public int getHistorySize() {
68: return history.size();
69: }
70: }
|