001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017package org.nuxeo.ecm.webapp.contentbrowser;
018
019import static org.jboss.seam.ScopeType.CONVERSATION;
020
021import java.io.Serializable;
022
023import org.jboss.seam.annotations.In;
024import org.jboss.seam.annotations.Name;
025import org.jboss.seam.annotations.Observer;
026import org.jboss.seam.annotations.Scope;
027import org.nuxeo.ecm.platform.contentview.seam.ContentViewActions;
028import org.nuxeo.ecm.webapp.helpers.EventNames;
029
030/**
031 * Handles observers for refresh and reset of content views.
032 *
033 * @author Anahide Tchertchian
034 * @since 5.4
035 */
036@Name("contentViewObserverActions")
037@Scope(CONVERSATION)
038public class ContentViewObserverActions implements Serializable {
039
040    private static final long serialVersionUID = 1L;
041
042    @In(create = true)
043    protected ContentViewActions contentViewActions;
044
045    /**
046     * Refreshes and resets content views that have declared event {@link EventNames#DOCUMENT_CHANGED} as a
047     * refresh/reset event.
048     */
049    @Observer(value = { EventNames.DOCUMENT_CHANGED })
050    public void onDocumentChanged() {
051        contentViewActions.refreshOnSeamEvent(EventNames.DOCUMENT_CHANGED);
052        contentViewActions.resetPageProviderOnSeamEvent(EventNames.DOCUMENT_CHANGED);
053    }
054
055    /**
056     * Refreshes and resets content views that have declared event {@link EventNames#DOCUMENT_CHILDREN_CHANGED} as a
057     * refresh/reset event.
058     */
059    @Observer(value = { EventNames.DOCUMENT_CHILDREN_CHANGED })
060    public void onDocumentChildrenChanged() {
061        contentViewActions.refreshOnSeamEvent(EventNames.DOCUMENT_CHILDREN_CHANGED);
062        contentViewActions.resetPageProviderOnSeamEvent(EventNames.DOCUMENT_CHILDREN_CHANGED);
063    }
064
065    /**
066     * Refreshes and resets content views that have declared event {@link EventNames#DOCUMENT_PUBLICATION_REJECTED} as a
067     * refresh/reset event.
068     *
069     * @since 5.6
070     */
071    @Observer(value = { EventNames.DOCUMENT_PUBLICATION_REJECTED })
072    public void onDocumentPublicationRejected() {
073        contentViewActions.refreshOnSeamEvent(EventNames.DOCUMENT_PUBLICATION_REJECTED);
074        contentViewActions.resetPageProviderOnSeamEvent(EventNames.DOCUMENT_PUBLICATION_REJECTED);
075    }
076
077    /**
078     * Resets all caches on {@link EventNames#FLUSH_EVENT}, triggered by hot reload when dev mode is set.
079     *
080     * @since 5.6
081     */
082    @Observer(value = { EventNames.FLUSH_EVENT }, create = true)
083    public void onHotReloadFlush() {
084        contentViewActions.resetAll();
085    }
086
087}