001/*
002 * (C) Copyright 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 *     Anahide Tchertchian
018 */
019package org.nuxeo.ecm.webapp.contentbrowser;
020
021import static org.jboss.seam.ScopeType.CONVERSATION;
022
023import java.io.Serializable;
024
025import org.jboss.seam.annotations.In;
026import org.jboss.seam.annotations.Name;
027import org.jboss.seam.annotations.Observer;
028import org.jboss.seam.annotations.Scope;
029import org.nuxeo.ecm.platform.contentview.seam.ContentViewActions;
030import org.nuxeo.ecm.webapp.helpers.EventNames;
031
032/**
033 * Handles observers for refresh and reset of content views.
034 *
035 * @author Anahide Tchertchian
036 * @since 5.4
037 */
038@Name("contentViewObserverActions")
039@Scope(CONVERSATION)
040public class ContentViewObserverActions implements Serializable {
041
042    private static final long serialVersionUID = 1L;
043
044    @In(create = true)
045    protected ContentViewActions contentViewActions;
046
047    /**
048     * Refreshes and resets content views that have declared event {@link EventNames#DOCUMENT_CHANGED} as a
049     * refresh/reset event.
050     */
051    @Observer(value = { EventNames.DOCUMENT_CHANGED })
052    public void onDocumentChanged() {
053        contentViewActions.refreshOnSeamEvent(EventNames.DOCUMENT_CHANGED);
054        contentViewActions.resetPageProviderOnSeamEvent(EventNames.DOCUMENT_CHANGED);
055    }
056
057    /**
058     * Refreshes and resets content views that have declared event {@link EventNames#DOCUMENT_CHILDREN_CHANGED} as a
059     * refresh/reset event.
060     */
061    @Observer(value = { EventNames.DOCUMENT_CHILDREN_CHANGED })
062    public void onDocumentChildrenChanged() {
063        contentViewActions.refreshOnSeamEvent(EventNames.DOCUMENT_CHILDREN_CHANGED);
064        contentViewActions.resetPageProviderOnSeamEvent(EventNames.DOCUMENT_CHILDREN_CHANGED);
065    }
066
067    /**
068     * Refreshes and resets content views that have declared event {@link EventNames#DOCUMENT_PUBLICATION_REJECTED} as a
069     * refresh/reset event.
070     *
071     * @since 5.6
072     */
073    @Observer(value = { EventNames.DOCUMENT_PUBLICATION_REJECTED })
074    public void onDocumentPublicationRejected() {
075        contentViewActions.refreshOnSeamEvent(EventNames.DOCUMENT_PUBLICATION_REJECTED);
076        contentViewActions.resetPageProviderOnSeamEvent(EventNames.DOCUMENT_PUBLICATION_REJECTED);
077    }
078
079    /**
080     * Resets all caches on {@link EventNames#FLUSH_EVENT}, triggered by hot reload when dev mode is set.
081     *
082     * @since 5.6
083     */
084    @Observer(value = { EventNames.FLUSH_EVENT }, create = true)
085    public void onHotReloadFlush() {
086        contentViewActions.resetAll();
087    }
088
089}