001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.forms.layout.actions; 020 021import java.io.Serializable; 022 023import javax.faces.application.FacesMessage; 024import javax.faces.context.FacesContext; 025import javax.servlet.http.HttpServletRequest; 026 027import org.nuxeo.ecm.platform.ui.web.rest.FancyNavigationHandler; 028import org.nuxeo.runtime.api.Framework; 029 030/** 031 * Session-scoped Seam component for layout related actions. 032 * 033 * @since 6.0 034 */ 035public class NuxeoLayoutManagerBean implements Serializable { 036 037 private static final long serialVersionUID = 1L; 038 039 public static final String NAME = "nuxeoLayoutManagerBean"; 040 041 protected Boolean devModeSet = null; 042 043 protected static String activatedMessage = "UI Development mode activated: " 044 + "keep the 'shift' key pressed and mouse hover elements in the page."; 045 046 protected static String deactivatedMessage = "UI Development mode deactivated"; 047 048 public boolean isDevModeSet() { 049 if (devModeSet == null) { 050 setDevModeSet(false, Framework.isDevModeSet()); 051 // maybe enable by default when dev mode is set 052 // setDevModeSet(Framework.isDevModeSet()); 053 } 054 return devModeSet.booleanValue(); 055 } 056 057 public void setDevModeSet(boolean activated) { 058 setDevModeSet(activated, true); 059 } 060 061 public void setDevModeSet(boolean activated, boolean addMessage) { 062 devModeSet = Boolean.valueOf(activated); 063 if (addMessage) { 064 FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, activated ? activatedMessage 065 : deactivatedMessage, null); 066 FacesContext faces = FacesContext.getCurrentInstance(); 067 faces.addMessage(null, message); 068 // avoid redirect for message to be displayed 069 HttpServletRequest httpRequest = (HttpServletRequest) faces.getExternalContext().getRequest(); 070 httpRequest.setAttribute(FancyNavigationHandler.DISABLE_REDIRECT_FOR_URL_REWRITE, Boolean.TRUE); 071 } 072 } 073 074}