001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2007
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.war.beans;
034:
035: import com.flexive.faces.FxJsfUtils;
036: import com.flexive.faces.beans.MessageBean;
037:
038: import java.util.ArrayList;
039: import java.util.List;
040:
041: /**
042: * This beans handles the main navigation menu.
043: *
044: * @author Gregor Schober (gregor.schober@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
045: * @version $Rev: 81 $
046: */
047: public class NavigationMenuBean {
048: private static List<Item> items = new ArrayList<Item>(10);
049:
050: static {
051: addItem("Admin.tab.content", "adm/content.jsf",
052: "adm/content/navigation.jsf", "contentNavigation", true);
053: addItem("Admin.tab.structure", "adm/content.jsf",
054: "adm/structure/navigation.jsf", "structureNavigation",
055: true);
056: addItem("Admin.tab.briefcase",
057: "adm/main/briefcase/bcOverview.jsf",
058: "adm/briefcase/navigation.jsf", "briefcaseNavigation",
059: true);
060: addItem("Admin.tab.admin", "adm/main/userGroup/overview.jsf",
061: "adm/main/navigation.jsf", "mainNavigation", false);
062: //addItem("menu4","content4.jsf","content/navigation.jsf","contentNavigation",false);
063: }
064:
065: private int activeIdx = 0;
066:
067: /**
068: * Items that are displayed as navigation.
069: */
070: public static class Item {
071:
072: private int id;
073: private String target;
074: private String display;
075: private String navigation;
076: private String navigationTarget;
077: private boolean renderReloadButton;
078:
079: public Item(int id, String display, String target, String nav,
080: String navigationTarget, boolean renderReloadButton) {
081: this .renderReloadButton = renderReloadButton;
082: this .target = target;
083: this .display = display;
084: this .id = id;
085: this .navigation = nav;
086: this .navigationTarget = navigationTarget;
087: }
088:
089: public boolean getRenderReloadButton() {
090: return renderReloadButton;
091: }
092:
093: public String getNavigationTarget() {
094: return navigationTarget;
095: }
096:
097: public void setNavigationTarget(String navigationTarget) {
098: this .navigationTarget = navigationTarget;
099: }
100:
101: public String getTarget() {
102: return target;
103: }
104:
105: public String getDisplay() {
106: // auto-translate display label for the current user
107: MessageBean messageBean = (MessageBean) FxJsfUtils
108: .getManagedBean("fxMessageBean");
109: return (String) messageBean.get(display);
110: }
111:
112: public int getId() {
113: return id;
114: }
115:
116: public String getNavigation() {
117: return navigation + "?activeIdx=" + id;
118: }
119: }
120:
121: public void setActiveIdx(int idx) {
122: if (idx < 0 || (idx > items.size() - 1)) {
123: idx = 0;
124: }
125: this .activeIdx = idx;
126: }
127:
128: public int getActiveIdx() {
129: return this .activeIdx;
130: }
131:
132: public Item getActiveItem() {
133: return items.get(activeIdx);
134: }
135:
136: private static synchronized void addItem(String display,
137: String target, String nav, String navigationTarget,
138: boolean renderReloadButton) {
139: items.add(new Item(items.size(), display, target, nav,
140: navigationTarget, renderReloadButton));
141: }
142:
143: public List getItems() {
144: return items;
145: }
146:
147: public List getTopItems() {
148: // TODO add caching
149: ArrayList<Item> result = new ArrayList<Item>(activeIdx + 1);
150: for (int i = 0; i < activeIdx; i++) {
151: result.add(items.get(i));
152: }
153: return result;
154: }
155:
156: public List getBottomItems() {
157: // TODO add caching
158: ArrayList<Item> result = new ArrayList<Item>(items.size()
159: - (activeIdx + 1));
160: for (int i = (activeIdx + 1); i < items.size(); i++) {
161: result.add(items.get(i));
162: }
163: return result;
164: }
165:
166: public String gotoMenu(int pos) {
167: setActiveIdx(pos);
168: return "main";
169: }
170:
171: public String toggleMenu() {
172: return items.get(activeIdx).getNavigationTarget();
173: }
174:
175: }
|