001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.ade.galleries.client;
029
030import org.opencms.ade.galleries.client.ui.CmsResultsTab.ParamType;
031import org.opencms.ade.galleries.shared.CmsGallerySearchScope;
032
033import com.google.gwt.event.logical.shared.CloseEvent;
034import com.google.gwt.user.client.ui.PopupPanel;
035
036/**
037 * The results tab handler.<p>
038 *
039 * This class receives event information from the results tab and
040 * delegates it to the gallery controller.
041 *
042 * @since 8.0.0
043 */
044public class CmsResultsTabHandler extends A_CmsTabHandler {
045
046    /**
047     * Constructor.<p>
048     *
049     * @param controller the gallery controller
050     */
051    public CmsResultsTabHandler(CmsGalleryController controller) {
052
053        super(controller);
054    }
055
056    /**
057     * @see org.opencms.ade.galleries.client.A_CmsTabHandler#clearParams()
058     */
059    @Override
060    public void clearParams() {
061
062        // nothing to do here
063    }
064
065    /**
066     * Deletes the given resource.<p>
067     *
068     * @param resourcePath the resource path of the resource to delete
069     */
070    public void deleteResource(String resourcePath) {
071
072        m_controller.deleteResource(resourcePath);
073    }
074
075    /**
076     * Returns the result view type.<p>
077     *
078     * @return the result view type
079     */
080    public String getResultViewType() {
081
082        return m_controller.getResultViewType();
083    }
084
085    /**
086     * Returns if a preview is available for the given resource type.<p>
087     *
088     * @param resourceType the requested resource type
089     *
090     * @return <code>true</code> if a preview is available for the given resource type
091     */
092    public boolean hasPreview(String resourceType) {
093
094        return m_controller.hasPreview(resourceType);
095    }
096
097    /**
098     * Returns if resource entries in the search result are selectable.<p>
099     *
100     * @return if resource entries in the search result are selectable
101     */
102    public boolean hasSelectResource() {
103
104        return m_controller.hasSelectResource() && m_controller.hasResultsSelectable();
105    }
106
107    /**
108     * Returns if a load results request is currently running.<p>
109     *
110     * @return <code>true</code> if a load results request is currently running
111     */
112    public boolean isLoading() {
113
114        return m_controller.isLoading();
115    }
116
117    /**
118     * @see org.opencms.ade.galleries.client.A_CmsTabHandler#onClose(com.google.gwt.event.logical.shared.CloseEvent)
119     */
120    @Override
121    public void onClose(CloseEvent<PopupPanel> event) {
122
123        m_controller.updateResultsTab(false);
124    }
125
126    /**
127     * Will be triggered when the bottom of the result list is reached by scrolling.<p>
128     */
129    public void onScrollToBottom() {
130
131        m_controller.updateResultsTab(true);
132
133    }
134
135    /**
136     * @see org.opencms.ade.galleries.client.A_CmsTabHandler#onSelection()
137     */
138    @Override
139    public void onSelection() {
140
141        if (m_controller.isSearchObjectChanged()) {
142            m_controller.updateResultsTab(false);
143        }
144    }
145
146    /**
147     * @see org.opencms.ade.galleries.client.A_CmsTabHandler#onSort(java.lang.String,java.lang.String)
148     */
149    @Override
150    public void onSort(String sortParams, String filter) {
151
152        // ignore filter, not available for this tab
153        m_controller.sortResults(sortParams);
154    }
155
156    /**
157     * Will be triggered when the result item is clicked.<p>
158     *
159     * @param resourcePath the resource path of the result
160     * @param resourceType the resource type
161     */
162    public void openPreview(String resourcePath, String resourceType) {
163
164        m_controller.openPreview(resourcePath, resourceType);
165
166    }
167
168    /**
169     * @see org.opencms.ade.galleries.client.A_CmsTabHandler#removeParam(java.lang.String)
170     */
171    @Override
172    public void removeParam(String paramKey) {
173
174        if (ParamType.scope.name().equals(paramKey)) {
175            m_controller.removeScope();
176
177        } else if (ParamType.text.name().equals(paramKey)) {
178            m_controller.removeQuery();
179
180        }
181    }
182
183    /**
184     * Stores the result view type.<p>
185     *
186     * @param resultViewType the result view type
187     */
188    public void setResultViewType(String resultViewType) {
189
190        m_controller.setResultViewType(resultViewType);
191    }
192
193    /**
194     * Sets the search scope.<p>
195     *
196     * @param scope the search scope
197     */
198    public void setScope(CmsGallerySearchScope scope) {
199
200        m_controller.addScope(scope);
201        m_controller.updateResultsTab(false);
202    }
203
204    /**
205     * Updates the result tab.<p>
206     */
207    public void updateResult() {
208
209        m_controller.updateResultsTab(false);
210    }
211}