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.preview.ui; 029 030import org.opencms.ade.galleries.client.Messages; 031import org.opencms.ade.galleries.client.preview.CmsBinaryPreviewHandler; 032import org.opencms.ade.galleries.client.ui.CmsResultListItem; 033import org.opencms.ade.galleries.client.ui.CmsResultsTab; 034import org.opencms.ade.galleries.client.ui.CmsResultsTab.DeleteHandler; 035import org.opencms.ade.galleries.shared.CmsResourceInfoBean; 036import org.opencms.gwt.client.dnd.CmsDNDHandler; 037import org.opencms.gwt.client.ui.CmsList; 038import org.opencms.gwt.client.ui.CmsListItem; 039import org.opencms.gwt.client.ui.CmsListItemWidget; 040import org.opencms.gwt.client.ui.CmsPushButton; 041import org.opencms.gwt.client.util.CmsDateTimeUtil; 042import org.opencms.gwt.client.util.CmsDateTimeUtil.Format; 043import org.opencms.gwt.shared.CmsListInfoBean; 044import org.opencms.gwt.shared.property.CmsClientProperty; 045import org.opencms.util.CmsStringUtil; 046import org.opencms.util.CmsUUID; 047 048import com.google.gwt.core.client.GWT; 049import com.google.gwt.dom.client.Style.Unit; 050import com.google.gwt.event.dom.client.ClickEvent; 051import com.google.gwt.event.dom.client.ClickHandler; 052import com.google.gwt.event.logical.shared.CloseEvent; 053import com.google.gwt.event.logical.shared.CloseHandler; 054import com.google.gwt.event.logical.shared.OpenEvent; 055import com.google.gwt.event.logical.shared.OpenHandler; 056import com.google.gwt.uibinder.client.UiBinder; 057import com.google.gwt.uibinder.client.UiField; 058import com.google.gwt.user.client.ui.Composite; 059import com.google.gwt.user.client.ui.HTML; 060import com.google.gwt.user.client.ui.HTMLPanel; 061 062/** 063 * Widget to display resource informations within the resource preview.<p> 064 * 065 * @since 8.0.0 066 */ 067public class CmsBinaryPreviewContent extends Composite { 068 069 /** 070 * The ui-binder interface.<p> 071 */ 072 public interface I_CmsPreviewContentUiBinder extends UiBinder<HTMLPanel, CmsBinaryPreviewContent> { 073 // GWT interface, nothing to do 074 } 075 076 /** The ui binder instance for this widget class. */ 077 private static I_CmsPreviewContentUiBinder uiBinder = GWT.create(I_CmsPreviewContentUiBinder.class); 078 079 /** The preview handler. */ 080 protected CmsBinaryPreviewHandler m_binaryPreviewHandler; 081 082 /** The list which only contains the list item for the previewed resource (required for drag and drop). */ 083 @UiField 084 protected CmsList<CmsListItem> m_list; 085 086 /** The preview content HTML. */ 087 @UiField 088 protected HTML m_previewContent; 089 090 /** 091 * Constructor.<p> 092 * 093 * @param info the resource info to display 094 * @param previewHandler the preview handler 095 */ 096 public CmsBinaryPreviewContent(CmsResourceInfoBean info, CmsBinaryPreviewHandler previewHandler) { 097 098 m_binaryPreviewHandler = previewHandler; 099 CmsListItem listItem = createListItem(info, m_binaryPreviewHandler.getGalleryDialog().getDndHandler()); 100 initWidget(uiBinder.createAndBindUi(this)); 101 CmsUUID structureId = info.getStructureId(); 102 103 if (structureId != null) { 104 listItem.setId(structureId.toString()); 105 } 106 m_list.addItem(listItem); 107 108 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(info.getPreviewContent())) { 109 m_previewContent.setHTML(info.getPreviewContent()); 110 } 111 } 112 113 /** 114 * Creates the list item for the resource information bean.<p> 115 * 116 * @param resourceInfo the resource information bean 117 * @param dndHandler the drag and drop handler 118 * 119 * @return the list item widget 120 */ 121 private CmsListItem createListItem(CmsResourceInfoBean resourceInfo, CmsDNDHandler dndHandler) { 122 123 CmsListInfoBean infoBean = new CmsListInfoBean(); 124 infoBean.setTitle( 125 CmsStringUtil.isNotEmptyOrWhitespaceOnly(resourceInfo.getProperties().get(CmsClientProperty.PROPERTY_TITLE)) 126 ? resourceInfo.getProperties().get(CmsClientProperty.PROPERTY_TITLE) 127 : resourceInfo.getTitle()); 128 infoBean.setSubTitle(resourceInfo.getResourcePath()); 129 infoBean.setResourceType(resourceInfo.getResourceType()); 130 infoBean.setBigIconClasses(resourceInfo.getBigIconClasses()); 131 infoBean.setSmallIconClasses(resourceInfo.getSmallIconClasses()); 132 infoBean.addAdditionalInfo(Messages.get().key(Messages.GUI_PREVIEW_LABEL_SIZE_0), resourceInfo.getSize()); 133 if (resourceInfo.getDescription() != null) { 134 infoBean.addAdditionalInfo( 135 Messages.get().key(Messages.GUI_PREVIEW_LABEL_DESCRIPTION_0), 136 resourceInfo.getDescription()); 137 } 138 if (resourceInfo.getLastModified() != null) { 139 infoBean.addAdditionalInfo( 140 Messages.get().key(Messages.GUI_PREVIEW_LABEL_DATEMODIFIED_0), 141 CmsDateTimeUtil.getDate(resourceInfo.getLastModified(), Format.MEDIUM)); 142 } 143 CmsListItemWidget itemWidget = new CmsListItemWidget(infoBean); 144 itemWidget.addOpenHandler(new OpenHandler<CmsListItemWidget>() { 145 146 public void onOpen(OpenEvent<CmsListItemWidget> event) { 147 148 int widgetHeight = event.getTarget().getOffsetHeight(); 149 m_previewContent.getElement().getStyle().setTop(12 + widgetHeight, Unit.PX); 150 } 151 }); 152 itemWidget.addCloseHandler(new CloseHandler<CmsListItemWidget>() { 153 154 public void onClose(CloseEvent<CmsListItemWidget> event) { 155 156 m_previewContent.getElement().getStyle().clearTop(); 157 } 158 }); 159 CmsListItem result = new CmsListItem(itemWidget); 160 161 CmsPushButton button = CmsResultListItem.createDeleteButton(); 162 if (dndHandler != null) { 163 result.initMoveHandle(dndHandler); 164 } 165 CmsResultsTab resultsTab = m_binaryPreviewHandler.getGalleryDialog().getResultsTab(); 166 final DeleteHandler deleteHandler = resultsTab.makeDeleteHandler(resourceInfo.getResourcePath()); 167 ClickHandler handler = new ClickHandler() { 168 169 public void onClick(ClickEvent event) { 170 171 deleteHandler.onClick(event); 172 m_binaryPreviewHandler.closePreview(); 173 } 174 }; 175 button.addClickHandler(handler); 176 itemWidget.addButton(button); 177 return result; 178 } 179}