001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 */ 011 012package org.nuxeo.ecm.automation.jsf.operations; 013 014import org.apache.commons.logging.Log; 015import org.apache.commons.logging.LogFactory; 016import org.jboss.seam.core.Events; 017import org.nuxeo.ecm.automation.core.Constants; 018import org.nuxeo.ecm.automation.core.annotations.Operation; 019import org.nuxeo.ecm.automation.core.annotations.OperationMethod; 020import org.nuxeo.ecm.automation.core.annotations.Param; 021import org.nuxeo.ecm.automation.core.util.StringList; 022import org.nuxeo.ecm.automation.jsf.OperationHelper; 023import org.nuxeo.ecm.core.api.DocumentModel; 024import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 025import org.nuxeo.ecm.webapp.helpers.EventNames; 026 027/** 028 * Operation that: 029 * <ul> 030 * <li>refreshes the content view cache;</li> 031 * <li>refreshes the navigation context current document cache;</li> 032 * <li>raises standard seam events to trigger refresh of most seam component;</li> 033 * <li>raises additional configurable seam events.</li> 034 * </ul> 035 * 036 * @author <a href="mailto:td@nuxeo.com">Thierry Delprat</a> 037 */ 038@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" }) 039public class RefreshUI { 040 041 public static final String ID = "WebUI.Refresh"; 042 043 protected static final Log log = LogFactory.getLog(RefreshUI.class); 044 045 /** 046 * Additional list of seam event names to raise 047 * 048 * @since 5.5 049 */ 050 @Param(name = "additional list of seam events to raise", required = false) 051 protected StringList additionalSeamEvents; 052 053 @OperationMethod 054 public void run() { 055 if (OperationHelper.isSeamContextAvailable()) { 056 OperationHelper.getContentViewActions().resetAllContent(); 057 NavigationContext navContext = OperationHelper.getNavigationContext(); 058 navContext.invalidateCurrentDocument(); 059 DocumentModel dm = navContext.getCurrentDocument(); 060 if (dm != null) { 061 Events.instance().raiseEvent(EventNames.DOCUMENT_CHANGED, dm); 062 Events.instance().raiseEvent(EventNames.DOCUMENT_CHILDREN_CHANGED, dm); 063 } 064 if (additionalSeamEvents != null) { 065 for (String event : additionalSeamEvents) { 066 Events.instance().raiseEvent(event); 067 } 068 } 069 } else { 070 log.debug("Skip Seam.Refresh operation since Seam context has not been initialized"); 071 } 072 } 073 074}