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:[email protected]">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 = { 046 "WebUI.Refresh" }) 047public class RefreshUI { 048 049 public static final String ID = "Seam.Refresh"; 050 051 protected static final Log log = LogFactory.getLog(RefreshUI.class); 052 053 /** 054 * Additional list of seam event names to raise 055 * 056 * @since 5.5 057 */ 058 @Param(name = "additional list of seam events to raise", required = false) 059 protected StringList additionalSeamEvents; 060 061 @OperationMethod 062 public void run() { 063 if (OperationHelper.isSeamContextAvailable()) { 064 OperationHelper.getContentViewActions().resetAllContent(); 065 NavigationContext navContext = OperationHelper.getNavigationContext(); 066 navContext.invalidateCurrentDocument(); 067 DocumentModel dm = navContext.getCurrentDocument(); 068 if (dm != null) { 069 Events.instance().raiseEvent(EventNames.DOCUMENT_CHANGED, dm); 070 Events.instance().raiseEvent(EventNames.DOCUMENT_CHILDREN_CHANGED, dm); 071 } 072 if (additionalSeamEvents != null) { 073 for (String event : additionalSeamEvents) { 074 Events.instance().raiseEvent(event); 075 } 076 } 077 } else { 078 log.debug("Skip Seam.Refresh operation since Seam context has not been initialized"); 079 } 080 } 081 082}