001: package ru.emdev.EmForge.web.bean;
002:
003: import java.util.ArrayList;
004: import java.util.Collection;
005:
006: import javax.faces.context.ExternalContext;
007: import javax.faces.context.FacesContext;
008: import javax.servlet.http.HttpServletRequest;
009:
010: import org.springframework.beans.factory.InitializingBean;
011: import org.springframework.web.util.UrlPathHelper;
012:
013: import ru.emdev.EmForge.svn.SvnRepositoryFactory;
014:
015: /**
016: * Class for processing Main Menu
017: */
018: public class MainMenuController implements InitializingBean {
019:
020: /**
021: * @author szakusov
022: */
023: public enum MainMenuItem {
024:
025: WIKI("wiki", "Wiki"), NEWS("news", "News"), PROJECTS(
026: "projects", "Projects"), SOURCES("browser", "Sources"), TASKS(
027: "tasks", "Tasks"), REPORTS("reports", "Reports");
028:
029: private String m_name;
030: private String m_title;
031:
032: /**
033: * @param i_name is the page name
034: * @param i_title is the page title
035: */
036: private MainMenuItem(String i_name, String i_title) {
037:
038: m_name = i_name;
039: m_title = i_title;
040: }
041:
042: /**
043: * @return the page name
044: */
045: public String getName() {
046:
047: return m_name;
048: }
049:
050: /**
051: * @return the page title
052: */
053: public String getTitle() {
054:
055: return m_title;
056: }
057:
058: }
059:
060: private Collection<MenuItemBean> m_menuItems = new ArrayList<MenuItemBean>();
061:
062: private SvnRepositoryFactory m_repositoryFactory;
063:
064: /**
065: * @param i_repositoryFactory
066: */
067: public void setSvnRepositoryFactory(
068: SvnRepositoryFactory i_repositoryFactory) {
069:
070: m_repositoryFactory = i_repositoryFactory;
071: }
072:
073: /**
074: * Initialize Menu Items
075: *
076: * @todo Currently MenuItems is hardcoded, but it should be configurable from Spring Config
077: */
078: public void afterPropertiesSet() throws Exception {
079:
080: m_menuItems.add(new MenuItemBean(MainMenuItem.WIKI));
081: m_menuItems.add(new MenuItemBean(MainMenuItem.NEWS));
082: m_menuItems.add(new MenuItemBean(MainMenuItem.PROJECTS));
083:
084: if (!m_repositoryFactory.isHasRepository()) {
085: m_menuItems.add(new MenuItemBean(MainMenuItem.SOURCES));
086: }
087:
088: m_menuItems.add(new MenuItemBean(MainMenuItem.TASKS));
089: m_menuItems.add(new MenuItemBean(MainMenuItem.REPORTS));
090: }
091:
092: /**
093: * @return
094: */
095: public Collection<MenuItemBean> getMenuItems() {
096:
097: return m_menuItems;
098: }
099:
100: /**
101: * Sets Current Menu Item
102: *
103: * @param i_name - name of selected menu item
104: */
105: public void setSelected(String i_name) {
106:
107: for (MenuItemBean menuItem : m_menuItems) {
108: if (menuItem.getTitle().equals(i_name)) {
109: menuItem.setSelected(true);
110: } else {
111: menuItem.setSelected(false);
112: }
113: }
114: }
115:
116: /**
117: * @return
118: */
119: public String getPathPrefix() {
120:
121: UrlPathHelper urlHelper = new UrlPathHelper();
122: urlHelper.setAlwaysUseFullPath(true);
123:
124: ExternalContext context = FacesContext.getCurrentInstance()
125: .getExternalContext();
126: HttpServletRequest request = (HttpServletRequest) context
127: .getRequest();
128:
129: String urlPath = urlHelper.getLookupPathForRequest(request);
130:
131: return urlPath;
132: }
133: }
|