All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opencms.ade.galleries.client.CmsGalleryControllerHandler Maven / Gradle / Ivy

Go to download

OpenCms is an enterprise-ready, easy to use website content management system based on Java and XML technology. Offering a complete set of features, OpenCms helps content managers worldwide to create and maintain beautiful websites fast and efficiently.

There is a newer version: 18.0
Show newest version
/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.ade.galleries.client;

import org.opencms.ade.galleries.client.ui.CmsGalleryDialog;
import org.opencms.ade.galleries.client.ui.CmsSearchTab.ParamType;
import org.opencms.ade.galleries.client.ui.CmsSitemapTab;
import org.opencms.ade.galleries.client.ui.CmsVfsTab;
import org.opencms.ade.galleries.shared.CmsGalleryDataBean;
import org.opencms.ade.galleries.shared.CmsGalleryFolderBean;
import org.opencms.ade.galleries.shared.CmsGallerySearchBean;
import org.opencms.ade.galleries.shared.CmsGalleryTreeEntry;
import org.opencms.ade.galleries.shared.CmsResourceTypeBean;
import org.opencms.ade.galleries.shared.CmsSitemapEntryBean;
import org.opencms.ade.galleries.shared.CmsVfsEntryBean;
import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants;
import org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants.GalleryTabId;
import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.gwt.client.ui.CmsPushButton;
import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
import org.opencms.gwt.shared.CmsCategoryBean;
import org.opencms.gwt.shared.CmsCategoryTreeEntry;
import org.opencms.gwt.shared.sort.CmsComparatorTitle;
import org.opencms.util.CmsStringUtil;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Gallery dialog controller handler.

* * Delegates the actions of the gallery controller to the gallery dialog. * * @since 8.0.0 */ public class CmsGalleryControllerHandler implements ValueChangeHandler { /** The reference to the gallery dialog. */ protected CmsGalleryDialog m_galleryDialog; /** The gallery mode. */ private I_CmsGalleryProviderConstants.GalleryMode m_mode; /** * Constructor.

* * @param galleryDialog the reference to the gallery dialog */ public CmsGalleryControllerHandler(CmsGalleryDialog galleryDialog) { m_galleryDialog = galleryDialog; } /** * Returns true if a results tab exists.

* * @return true if a results tab exists */ public boolean hasResultsTab() { return m_galleryDialog.getResultsTab() != null; } /** * Hides or shows the show-preview-button.

* * @param hide true to hide the button */ public void hideShowPreviewButton(boolean hide) { // buttons switch (m_mode) { case editor: case widget: m_galleryDialog.hideShowPreviewButton(hide); break; case ade: case view: case adeView: default: break; } } /** * Will be triggered when the categories tab is selected.

*/ public void onCategoriesTabSelection() { if (!m_galleryDialog.getCategoriesTab().isInitOpen()) { m_galleryDialog.getCategoriesTab().onContentChange(); return; } m_galleryDialog.getCategoriesTab().openFirstLevel(); m_galleryDialog.getCategoriesTab().setInitOpen(false); } /** * Deletes the html content of the categories parameter and removes the style.

* * @param categories the categories to remove from selection */ public void onClearCategories(List categories) { if (categories != null) { m_galleryDialog.getCategoriesTab().uncheckCategories(categories); } } /** * The method which is executed when all folders are cleared from the search object.

* * @param folders the folders which have been cleared */ public void onClearFolders(Collection folders) { m_galleryDialog.getVfsTab().uncheckFolders(folders); } /** * clears the search tab input.

*/ public void onClearFullTextSearch() { m_galleryDialog.getSearchTab().clearInput(); } /** * Deletes the html content of the galleries parameter and removes the style.

* * @param galleries the galleries to remove from selection */ public void onClearGalleries(List galleries) { if (galleries != null) { m_galleryDialog.getGalleriesTab().uncheckGalleries(galleries); } } /** * Deletes the html content of the types parameter and removes the style.

* * @param types the types to be removed from selection */ public void onClearTypes(List types) { if (types != null) { m_galleryDialog.getTypesTab().uncheckTypes(types); } } /** * Will be triggered when the galleries tab is selected.

*/ public void onGalleriesTabSelection() { m_galleryDialog.getGalleriesTab().onContentChange(); } /** * Will be triggered when the initial search is performed.

* * @param searchObj the current search object * @param dialogBean the current dialog data bean * @param controller the dialog controller * @param isFirstTime true if this method is called the first time for the gallery dialog instance */ public void onInitialSearch( final CmsGallerySearchBean searchObj, final CmsGalleryDataBean dialogBean, final CmsGalleryController controller, boolean isFirstTime) { m_mode = dialogBean.getMode(); if (isFirstTime) { if (m_mode.equals(I_CmsGalleryProviderConstants.GalleryMode.view)) { RootPanel panel = RootPanel.get(I_CmsGalleryProviderConstants.GALLERY_DIALOG_ID); panel.addStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().popup()); panel.addStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().popupContent()); CmsPushButton closeButton = new CmsPushButton(); closeButton.setButtonStyle(ButtonStyle.TRANSPARENT, null); closeButton.addStyleName(I_CmsLayoutBundle.INSTANCE.dialogCss().closePopup()); closeButton.setImageClass(I_CmsLayoutBundle.INSTANCE.dialogCss().closePopupImage()); closeButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { String closeLink = getCloseLink() + "?resource="; Window.Location.assign(CmsCoreProvider.get().link(closeLink)); } }); panel.add(closeButton); panel.setWidth("660px"); panel.getElement().getStyle().setProperty("margin", "20px auto"); } if ((dialogBean.getSitemapSiteSelectorOptions() == null) || dialogBean.getSitemapSiteSelectorOptions().isEmpty()) { controller.removeTab(GalleryTabId.cms_tab_sitemap); } m_galleryDialog.fillTabs(controller); } if ((m_galleryDialog.getGalleriesTab() != null) && (dialogBean.getGalleries() != null)) { Collections.sort(dialogBean.getGalleries(), new CmsComparatorTitle(true)); setGalleriesTabContent(dialogBean.getGalleries(), searchObj.getGalleries()); } if ((m_galleryDialog.getTypesTab() != null) && (dialogBean.getTypes() != null)) { setTypesTabContent(controller.getSearchTypes(), searchObj.getTypes()); } if ((m_galleryDialog.getCategoriesTab() != null) && (dialogBean.getCategories() != null)) { setCategoriesTabContent(dialogBean.getCategories()); } GalleryTabId startTab = dialogBean.getStartTab(); // start tab from the search bean may override the start tab from the data bean GalleryTabId searchTabId = searchObj.getInitialTabId(); if ((searchTabId != null) && (m_galleryDialog.getTab(searchTabId) != null)) { startTab = searchTabId; } if (startTab == GalleryTabId.cms_tab_results) { if (!searchObj.isEmpty()) { m_galleryDialog.fillResultTab(searchObj); } } CmsSitemapEntryBean sitemapPreloadData = searchObj.getSitemapPreloadData(); if ((sitemapPreloadData != null) && (m_galleryDialog.getSitemapTab() != null)) { onReceiveSitemapPreloadData(sitemapPreloadData); } CmsVfsEntryBean vfsPreloadData = searchObj.getVfsPreloadData(); if (m_galleryDialog.getVfsTab() != null) { if (vfsPreloadData != null) { onReceiveVfsPreloadData(vfsPreloadData); } else if ((dialogBean.getVfsRootFolders() != null)) { m_galleryDialog.getVfsTab().fillInitially(dialogBean.getVfsRootFolders()); } } if (startTab == GalleryTabId.cms_tab_results) { if (searchObj.isEmpty()) { startTab = dialogBean.getTabConfiguration().getDefaultTab(); } } m_galleryDialog.selectTab(startTab, startTab != GalleryTabId.cms_tab_results); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(searchObj.getResourcePath()) && CmsStringUtil.isNotEmptyOrWhitespaceOnly(searchObj.getResourceType()) && !searchObj.isDisablePreview()) { if (m_galleryDialog.isAttached()) { controller.openPreview(searchObj.getResourcePath(), searchObj.getResourceType()); } else { // gallery dialog has to be attached to open the preview m_galleryDialog.setOnAttachCommand(new Command() { /** * @see com.google.gwt.user.client.Command#execute() */ public void execute() { controller.openPreview(searchObj.getResourcePath(), searchObj.getResourceType()); } }); } } Timer timer = new Timer() { @Override public void run() { m_galleryDialog.updateSizes(); } }; timer.schedule(1); } /** * This method is called when preloaded sitemap tree state data is loaded.

* * @param sitemapPreloadData the sitemap preload data */ public void onReceiveSitemapPreloadData(CmsSitemapEntryBean sitemapPreloadData) { CmsSitemapTab sitemapTab = m_galleryDialog.getSitemapTab(); if (sitemapTab != null) { sitemapTab.onReceiveSitemapPreloadData(sitemapPreloadData); } } /** * This method is called when preloaded VFS tree state data is loaded.

* * @param vfsPreloadData the preload data */ public void onReceiveVfsPreloadData(CmsVfsEntryBean vfsPreloadData) { CmsVfsTab vfsTab = m_galleryDialog.getVfsTab(); if (vfsTab != null) { vfsTab.onReceiveVfsPreloadData(vfsPreloadData); } } /** * Removes a parameter from the search tab.

* * @param type the parameter type */ public void onRemoveSearchParam(ParamType type) { m_galleryDialog.getSearchTab().removeParameter(type); } /** * Will be triggered when the results tab is selected.

* * @param searchObj the current search object */ public void onResultTabSelection(CmsGallerySearchBean searchObj) { m_galleryDialog.fillResultTab(searchObj); } /** * Will be triggered when the types tab is selected.

*/ public void onTypesTabSelection() { m_galleryDialog.getTypesTab().onContentChange(); } /** * Will be triggered when categories list is sorted.

* * @param categoriesList the updated categories list * @param selectedCategories the selected categories */ public void onUpdateCategoriesList(List categoriesList, List selectedCategories) { m_galleryDialog.getCategoriesTab().updateContentList(categoriesList, selectedCategories); } /** * Will be triggered when the tree is selected.

* * @param categoryTreeEntry the category root entry * @param selectedCategories the selected categories */ public void onUpdateCategoriesTree(List categoryTreeEntry, List selectedCategories) { m_galleryDialog.getCategoriesTab().updateContentTree(categoryTreeEntry, selectedCategories); } /** * Will be triggered when the sort parameters of the galleries list are changed.

* * @param galleries the updated galleries list * @param selectedGalleries the list of galleries to select */ public void onUpdateGalleries(List galleries, List selectedGalleries) { m_galleryDialog.getGalleriesTab().updateListContent(galleries, selectedGalleries); } /** * Updates the gallery tree.

* * @param galleryTreeEntries the gallery tree entries * @param selectedGalleries the selected galleries */ public void onUpdateGalleryTree(List galleryTreeEntries, List selectedGalleries) { m_galleryDialog.getGalleriesTab().updateTreeContent(galleryTreeEntries, selectedGalleries); } /** * Will be triggered when the sort parameters of the types list are changed.

* * @param types the updated types list * @param selectedTypes the list of types to select */ public void onUpdateTypes(List types, List selectedTypes) { m_galleryDialog.getTypesTab().updateContent(types, selectedTypes); } /** * @see com.google.gwt.event.logical.shared.ValueChangeHandler#onValueChange(com.google.gwt.event.logical.shared.ValueChangeEvent) */ public void onValueChange(ValueChangeEvent event) { if (!m_galleryDialog.getController().isSearchObjectEmpty()) { m_galleryDialog.enableSearchTab(); } else { m_galleryDialog.disableSearchTab(); } } /** * Selects the result tab.

*/ public void selectResultTab() { m_galleryDialog.selectTab(GalleryTabId.cms_tab_results, true); } /** * Sets the list content of the category tab.

* * @param categoryRoot the root category tree entry */ public void setCategoriesTabContent(List categoryRoot) { m_galleryDialog.getCategoriesTab().fillContent(categoryRoot); } /** * Sets the list content of the galleries tab.

* * @param galleryInfos the gallery info beans * @param selectedGalleries the selected galleries */ public void setGalleriesTabContent(List galleryInfos, List selectedGalleries) { m_galleryDialog.getGalleriesTab().fillContent(galleryInfos, selectedGalleries); } /** * Sets the list content of the types tab.

* * @param typeInfos the type info beans * @param selectedTypes the selected types */ public void setTypesTabContent(List typeInfos, List selectedTypes) { m_galleryDialog.getTypesTab().fillContent(typeInfos, selectedTypes); } /** * Shows the message if no search params were selected.

*/ public void showNoParamsMessage() { m_galleryDialog.getResultsTab().showNoParamsMessage(); } /** * Retrieves the close link global variable as a string.

* * @return the close link */ protected native String getCloseLink() /*-{ return $wnd[@org.opencms.ade.galleries.shared.I_CmsGalleryProviderConstants::ATTR_CLOSE_LINK]; }-*/; /** * Causes the preloaded tree states to be displayed in the tree tabs.

* * @param result the gallery search bean from which to take the preload data */ protected void showPreloadDataInTabs(CmsGallerySearchBean result) { CmsSitemapEntryBean sitemapPreloadData = result.getSitemapPreloadData(); if (sitemapPreloadData != null) { onReceiveSitemapPreloadData(sitemapPreloadData); } CmsVfsEntryBean vfsPreloadData = result.getVfsPreloadData(); if (vfsPreloadData != null) { onReceiveVfsPreloadData(vfsPreloadData); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy