001: /*
002: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
003: * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
004: * Copyright (C) 2007 Mathieu BENOIT <mbenoit@wilos-project.org>
005: *
006: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
007: * General Public License as published by the Free Software Foundation; either version 2 of the License,
008: * or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
011: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License along with this program; if not,
015: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
016: */
017:
018: package wilos.presentation.web.utils;
019:
020: import javax.faces.application.FacesMessage;
021: import javax.faces.context.FacesContext;
022:
023: import wilos.presentation.web.template.MenuBean;
024: import wilos.presentation.web.template.PageContentBean;
025: import wilos.resources.WilosBundle;
026: import wilos.utils.Constantes.State;
027:
028: public class WebCommonService {
029:
030: /* Manage Beans */
031: /**
032: * Gets a bean thanks to its name
033: * @param _beanName the name of the bean
034: * @return the expected bean
035: */
036: public static Object getBean(String _beanName) {
037: return getCurrentFacesContext().getApplication()
038: .getVariableResolver().resolveVariable(
039: getCurrentFacesContext(), _beanName);
040: }
041:
042: /* Manage pages */
043:
044: /**
045: * Changes the content of the page
046: * @param _pageUrl the new url of the new page to display
047: */
048: public static void changeContentPage(String _pageUrl) {
049: getMenuBean().changePage(_pageUrl);
050: }
051:
052: /**
053: * Gets the currently selected panel
054: * @return the selected panel
055: */
056: public static PageContentBean getSelectedPanel() {
057: return getMenuBean().getSelectedPanel();
058: }
059:
060: /* Manage messages */
061:
062: /**
063: * Displays a information message
064: * @param _message the message to display
065: */
066: public static void addInfoMessage(String _message) {
067: FacesMessage message = new FacesMessage();
068: message.setSummary(_message);
069: message.setSeverity(FacesMessage.SEVERITY_INFO);
070: getCurrentFacesContext().addMessage(null, message);
071: }
072:
073: /**
074: * Displays an error message
075: * @param _message the message to display
076: */
077: public static void addErrorMessage(String _message) {
078: FacesMessage message = new FacesMessage();
079: message.setSummary(_message);
080: message.setSeverity(FacesMessage.SEVERITY_ERROR);
081: getCurrentFacesContext().addMessage(null, message);
082: }
083:
084: /* Manage constante translation according the language */
085:
086: /**
087: * Gets the state currently displayed
088: * @param _state the current state
089: * @return the state to display
090: */
091: public static String getDisplayedState(String _state) {
092: String stateInString = "";
093: if (_state.equals(State.CREATED)) {
094: stateInString = WilosBundle
095: .getText("constantes.state.created");
096: } else if (_state.equals(State.READY)) {
097: stateInString = WilosBundle
098: .getText("constantes.state.ready");
099: } else if (_state.equals(State.STARTED)) {
100: stateInString = WilosBundle
101: .getText("constantes.state.started");
102: } else if (_state.equals(State.SUSPENDED)) {
103: stateInString = WilosBundle
104: .getText("constantes.state.suspended");
105: } else if (_state.equals(State.FINISHED)) {
106: stateInString = WilosBundle
107: .getText("constantes.state.finished");
108: }
109: return stateInString;
110: }
111:
112: /**
113: * Gets the state currently displayed fo a milestone
114: * @param _state the current state
115: * @return the state to display
116: */
117: public static String getDisplayedStateForMilestone(String _state) {
118: String stateInString = "";
119: if (_state.equals(State.CREATED)) {
120: stateInString = WilosBundle
121: .getText("constantes.state.created.ms");
122: } else if (_state.equals(State.READY)) {
123: stateInString = WilosBundle
124: .getText("constantes.state.ready.ms");
125: } else if (_state.equals(State.FINISHED)) {
126: stateInString = WilosBundle
127: .getText("constantes.state.finished.ms");
128: }
129: return stateInString;
130: }
131:
132: /**
133: * Gets the state currently displayed for a work product
134: * @param _state the current state
135: * @return the state to display
136: */
137: public static String getDisplayedStateForWorkProduct(String _state) {
138: String stateInString = "";
139: if (_state.equals(State.CREATED)) {
140: stateInString = WilosBundle
141: .getText("constantes.state.created.wp");
142: } else if (_state.equals(State.READY)) {
143: stateInString = WilosBundle
144: .getText("constantes.state.ready.wp");
145: } else {
146: stateInString = _state;
147: }
148: return stateInString;
149: }
150:
151: /* Private methods */
152:
153: /**
154: * Gets the current faces context
155: * @return the faces context
156: */
157: private static FacesContext getCurrentFacesContext() {
158: return FacesContext.getCurrentInstance();
159: }
160:
161: /**
162: * Gets the menu bean
163: * @return the menu bean
164: */
165: private static MenuBean getMenuBean() {
166: MenuBean menuBean = (MenuBean) getCurrentFacesContext()
167: .getApplication().createValueBinding("#{menu}")
168: .getValue(getCurrentFacesContext());
169: return menuBean;
170: }
171: }
|