001/* 002 * (C) Copyright 2006-2011 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 */ 018 019package org.nuxeo.ecm.automation.jsf.operations; 020 021import org.apache.commons.logging.Log; 022import org.apache.commons.logging.LogFactory; 023import org.jboss.seam.core.Events; 024import org.nuxeo.ecm.automation.core.Constants; 025import org.nuxeo.ecm.automation.core.annotations.Operation; 026import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 027import org.nuxeo.ecm.automation.core.annotations.Param; 028import org.nuxeo.ecm.automation.core.util.StringList; 029import org.nuxeo.ecm.automation.jsf.OperationHelper; 030import org.nuxeo.ecm.core.api.DocumentModel; 031import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 032import org.nuxeo.ecm.webapp.helpers.EventNames; 033 034/** 035 * Operation that: 036 * <ul> 037 * <li>refreshes the content view cache;</li> 038 * <li>refreshes the navigation context current document cache;</li> 039 * <li>raises standard seam events to trigger refresh of most seam component;</li> 040 * <li>raises additional configurable seam events.</li> 041 * </ul> 042 * 043 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a> 044 */ 045@Operation(id = RefreshUI.ID, category = Constants.CAT_UI, requires = Constants.SEAM_CONTEXT, label = "Refresh", description = "Refresh the UI cache. This is a void operation - the input object is returned back as the oputput", aliases = { "Seam.Refresh" }) 046public class RefreshUI { 047 048 public static final String ID = "WebUI.Refresh"; 049 050 protected static final Log log = LogFactory.getLog(RefreshUI.class); 051 052 /** 053 * Additional list of seam event names to raise 054 * 055 * @since 5.5 056 */ 057 @Param(name = "additional list of seam events to raise", required = false) 058 protected StringList additionalSeamEvents; 059 060 @OperationMethod 061 public void run() { 062 if (OperationHelper.isSeamContextAvailable()) { 063 OperationHelper.getContentViewActions().resetAllContent(); 064 NavigationContext navContext = OperationHelper.getNavigationContext(); 065 navContext.invalidateCurrentDocument(); 066 DocumentModel dm = navContext.getCurrentDocument(); 067 if (dm != null) { 068 Events.instance().raiseEvent(EventNames.DOCUMENT_CHANGED, dm); 069 Events.instance().raiseEvent(EventNames.DOCUMENT_CHILDREN_CHANGED, dm); 070 } 071 if (additionalSeamEvents != null) { 072 for (String event : additionalSeamEvents) { 073 Events.instance().raiseEvent(event); 074 } 075 } 076 } else { 077 log.debug("Skip Seam.Refresh operation since Seam context has not been initialized"); 078 } 079 } 080 081}