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.containerpage.client.ui; 029 030import org.opencms.ade.containerpage.client.CmsContainerpageController; 031import org.opencms.ade.containerpage.client.CmsContainerpageHandler; 032import org.opencms.ade.containerpage.client.Messages; 033import org.opencms.ade.containerpage.client.ui.css.I_CmsLayoutBundle; 034import org.opencms.ade.containerpage.shared.CmsContainerPageGalleryData; 035import org.opencms.ade.galleries.client.CmsGalleryController; 036import org.opencms.ade.galleries.client.CmsGalleryControllerHandler; 037import org.opencms.ade.galleries.client.I_CmsGalleryHandler; 038import org.opencms.ade.galleries.client.ui.CmsGalleryDialog; 039import org.opencms.ade.galleries.client.ui.CmsResultListItem; 040import org.opencms.ade.galleries.shared.CmsGalleryDataBean; 041import org.opencms.ade.galleries.shared.CmsGallerySearchBean; 042import org.opencms.ade.galleries.shared.CmsResultItemBean; 043import org.opencms.gwt.client.dnd.CmsDNDHandler; 044import org.opencms.gwt.client.ui.A_CmsToolbarMenu; 045import org.opencms.gwt.client.ui.CmsListItemWidget.Background; 046import org.opencms.gwt.client.ui.CmsPopup; 047import org.opencms.gwt.client.ui.CmsToolbarPopup; 048import org.opencms.gwt.client.ui.I_CmsAutoHider; 049import org.opencms.gwt.client.ui.I_CmsButton; 050import org.opencms.gwt.client.ui.input.CmsLabel; 051import org.opencms.gwt.shared.CmsListInfoBean.StateIcon; 052 053import com.google.common.base.Predicate; 054import com.google.common.base.Predicates; 055import com.google.gwt.dom.client.Document; 056import com.google.gwt.dom.client.Style.FontStyle; 057import com.google.gwt.user.client.ui.FlowPanel; 058import com.google.gwt.user.client.ui.SimplePanel; 059import com.google.gwt.user.client.ui.Widget; 060 061/** 062 * The gallery tool-bar menu.<p> 063 * 064 * @since 8.0.0 065 */ 066public class CmsToolbarGalleryMenu extends A_CmsToolbarMenu<CmsContainerpageHandler> { 067 068 /** 069 * The gallery handler for the container page editor.<p> 070 */ 071 class GalleryHandler implements I_CmsGalleryHandler { 072 073 /** The drag and drop filter. */ 074 private Predicate<CmsResultItemBean> m_dndFilter; 075 076 /** 077 * Constructor.<p> 078 * 079 * @param dndFilter the drag and drop filter 080 */ 081 GalleryHandler(Predicate<CmsResultItemBean> dndFilter) { 082 083 m_dndFilter = dndFilter; 084 } 085 086 /** 087 * @see org.opencms.ade.galleries.client.I_CmsGalleryHandler#filterDnd(org.opencms.ade.galleries.shared.CmsResultItemBean) 088 */ 089 public boolean filterDnd(CmsResultItemBean resultBean) { 090 091 if (m_dndFilter != null) { 092 return m_dndFilter.apply(resultBean); 093 } else { 094 return true; 095 } 096 } 097 098 /** 099 * @see org.opencms.ade.galleries.client.I_CmsGalleryHandler#getAdditionalTypeTabControl() 100 */ 101 public Widget getAdditionalTypeTabControl() { 102 103 return CmsContainerpageController.get().getHandler().createViewSelectorForGalleryDialog(); 104 } 105 106 /** 107 * @see org.opencms.ade.galleries.client.I_CmsGalleryHandler#getAutoHideParent() 108 */ 109 public I_CmsAutoHider getAutoHideParent() { 110 111 return getPopup(); 112 } 113 114 /** 115 * @see org.opencms.ade.galleries.client.I_CmsGalleryHandler#getDndHandler() 116 */ 117 public CmsDNDHandler getDndHandler() { 118 119 return getDragHandler(); 120 } 121 122 /** 123 * @see org.opencms.ade.galleries.client.I_CmsGalleryHandler#processResultItem(org.opencms.ade.galleries.client.ui.CmsResultListItem) 124 */ 125 public void processResultItem(CmsResultListItem item) { 126 127 if (item.getResult().isCopyModel()) { 128 item.getListItemWidget().setBackground(Background.YELLOW); 129 CmsLabel titleWidget = item.getListItemWidget().getTitleWidget(); 130 titleWidget.getElement().getStyle().setFontStyle(FontStyle.OBLIQUE); 131 String newText = Messages.get().key(Messages.GUI_COPY_MODEL_TITLE_WRAPPER_1, titleWidget.getText()); 132 titleWidget.setText(newText); 133 item.getListItemWidget().setStateIcon(StateIcon.copy); 134 } 135 } 136 137 } 138 139 /** The gallery dialog instance. */ 140 private CmsGalleryDialog m_dialog; 141 142 /** The drag and drop handler for the gallery menu. */ 143 private CmsDNDHandler m_dragHandler; 144 145 /** The gallery data. */ 146 private CmsGalleryDataBean m_galleryData; 147 148 /** The gallery search bean. */ 149 private CmsGallerySearchBean m_search; 150 151 /** The gallery dialog container. */ 152 private SimplePanel m_tabsContainer; 153 154 /** 155 * Constructor.<p> 156 * 157 * @param handler the container-page handler 158 * @param dragHandler the container-page drag handler 159 */ 160 public CmsToolbarGalleryMenu(CmsContainerpageHandler handler, CmsDNDHandler dragHandler) { 161 162 super(I_CmsButton.ButtonData.WAND_BUTTON, handler); 163 m_dragHandler = dragHandler; 164 FlowPanel contentPanel = new FlowPanel(); 165 m_tabsContainer = new SimplePanel(); 166 m_tabsContainer.addStyleName(I_CmsLayoutBundle.INSTANCE.containerpageCss().menuTabContainer()); 167 contentPanel.add(m_tabsContainer); 168 setMenuWidget(contentPanel); 169 } 170 171 /** 172 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarActivate() 173 */ 174 @SuppressWarnings("unused") 175 public void onToolbarActivate() { 176 177 Document.get().getBody().addClassName(I_CmsButton.ButtonData.WAND_BUTTON.getIconClass()); 178 if (m_dialog == null) { 179 int dialogHeight = CmsToolbarPopup.getAvailableHeight(); 180 int dialogWidth = CmsToolbarPopup.getAvailableWidth(); 181 Predicate<CmsResultItemBean> resultDndFilter = Predicates.alwaysTrue(); 182 if (CmsContainerpageController.get().getData().getTemplateContextInfo().getCurrentContext() != null) { 183 resultDndFilter = new CmsTemplateContextResultDndFilter(); 184 } 185 final Predicate<CmsResultItemBean> finalDndFilter = resultDndFilter; 186 CmsGalleryDialog galleryDialog = new CmsGalleryDialog(new GalleryHandler(finalDndFilter)); 187 CmsGalleryController galleryController = new CmsGalleryController( 188 new CmsGalleryControllerHandler(galleryDialog), 189 m_galleryData, 190 m_search); 191 galleryController.setContainerInfoProvider( 192 () -> CmsContainerpageController.get().getContainerInfoForGalleries()); 193 galleryController.setTemplateContextInfoProvider( 194 () -> CmsContainerpageController.get().getData().getTemplateContextInfo()); 195 m_dialog = galleryDialog; 196 m_dialog.setDialogSize(dialogWidth, dialogHeight); 197 getPopup().setWidth(dialogWidth); 198 m_tabsContainer.add(m_dialog); 199 } else { 200 int dialogWidth = CmsToolbarPopup.getAvailableWidth(); 201 getPopup().setWidth(dialogWidth); 202 m_dialog.truncate("GALLERY_DIALOG_TM", dialogWidth); 203 m_dialog.updateSizes(); 204 } 205 } 206 207 /** 208 * @see org.opencms.gwt.client.ui.I_CmsToolbarButton#onToolbarDeactivate() 209 */ 210 public void onToolbarDeactivate() { 211 212 Document.get().getBody().removeClassName(I_CmsButton.ButtonData.WAND_BUTTON.getIconClass()); 213 } 214 215 /** 216 * Updates the gallery data.<p> 217 * 218 * @param galleryData the gallery data 219 * @param viewChanged <code>true</code> in case the element view changed 220 */ 221 public void updateGalleryData(CmsContainerPageGalleryData galleryData, boolean viewChanged) { 222 223 if (m_dialog != null) { 224 if (viewChanged) { 225 m_dialog.removeFromParent(); 226 m_dialog = null; 227 } else { 228 m_dialog.updateGalleryData(galleryData.getGalleryData()); 229 } 230 } 231 m_galleryData = galleryData.getGalleryData(); 232 m_search = galleryData.getGallerySearch(); 233 } 234 235 /** 236 * Gets the drag handler.<p> 237 * 238 * @return the drag handler 239 */ 240 protected CmsDNDHandler getDragHandler() { 241 242 return m_dragHandler; 243 } 244 245 /** 246 * @see org.opencms.gwt.client.ui.CmsMenuButton#getPopup() 247 */ 248 @Override 249 protected CmsPopup getPopup() { 250 251 return super.getPopup(); 252 } 253 254}