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; 029 030import org.opencms.ade.galleries.client.preview.ui.CmsBinaryPreviewDialog; 031import org.opencms.ade.galleries.client.ui.CmsGalleryDialog; 032import org.opencms.ade.galleries.shared.CmsResourceInfoBean; 033import org.opencms.ade.galleries.shared.I_CmsBinaryPreviewProvider; 034import org.opencms.gwt.client.rpc.CmsRpcAction; 035 036import java.util.Map; 037 038import com.google.gwt.user.client.Command; 039import com.google.gwt.user.client.ui.FlowPanel; 040 041/** 042 * The binary resource preview.<p> 043 * 044 * @since 8.0.0 045 */ 046public final class CmsBinaryResourcePreview extends A_CmsResourcePreview<CmsResourceInfoBean> { 047 048 /** The preview handler. */ 049 private CmsBinaryPreviewHandler m_handler; 050 051 /** The preview dialog widget. */ 052 private CmsBinaryPreviewDialog m_previewDialog; 053 054 /** 055 * Constructor.<p> 056 * 057 * @param galleryDialog the gallery dialog instance 058 */ 059 public CmsBinaryResourcePreview(CmsGalleryDialog galleryDialog) { 060 061 super(galleryDialog); 062 } 063 064 /** 065 * @see org.opencms.ade.galleries.client.preview.A_CmsResourcePreview#getHandler() 066 */ 067 @Override 068 public CmsBinaryPreviewHandler getHandler() { 069 070 return m_handler; 071 } 072 073 /** 074 * @see org.opencms.ade.galleries.client.preview.I_CmsResourcePreview#getPreviewDialog() 075 */ 076 public CmsBinaryPreviewDialog getPreviewDialog() { 077 078 return m_previewDialog; 079 } 080 081 /** 082 * @see org.opencms.ade.galleries.client.preview.I_CmsResourcePreview#getPreviewName() 083 */ 084 public String getPreviewName() { 085 086 return I_CmsBinaryPreviewProvider.PREVIEW_NAME; 087 } 088 089 /** 090 * Loads the resource info and displays the retrieved data.<p> 091 * 092 * @param resourcePath the resource path 093 */ 094 public void loadResourceInfo(final String resourcePath) { 095 096 CmsRpcAction<CmsResourceInfoBean> action = new CmsRpcAction<CmsResourceInfoBean>() { 097 098 /** 099 * @see org.opencms.gwt.client.rpc.CmsRpcAction#execute() 100 */ 101 @Override 102 public void execute() { 103 104 getService().getResourceInfo(resourcePath, getLocale(), this); 105 } 106 107 /** 108 * @see org.opencms.gwt.client.rpc.CmsRpcAction#onResponse(java.lang.Object) 109 */ 110 @Override 111 protected void onResponse(CmsResourceInfoBean result) { 112 113 showData(result); 114 } 115 }; 116 action.execute(); 117 } 118 119 /** 120 * @see org.opencms.ade.galleries.client.preview.I_CmsResourcePreview#openPreview(java.lang.String, boolean) 121 */ 122 public void openPreview(String resourcePath, boolean disableSelection) { 123 124 if (m_previewDialog != null) { 125 m_previewDialog.removeFromParent(); 126 } 127 FlowPanel parentPanel = getGalleryDialog().getParentPanel(); 128 m_previewDialog = new CmsBinaryPreviewDialog( 129 getGalleryDialog().getController().getDialogMode(), 130 parentPanel.getOffsetHeight(), 131 parentPanel.getOffsetWidth(), 132 disableSelection); 133 134 m_handler = new CmsBinaryPreviewHandler(this); 135 m_previewDialog.init(m_handler); 136 CmsPreviewUtil.exportFunctions(getPreviewName(), this); 137 parentPanel.add(m_previewDialog); 138 m_handler.getGalleryDialog().setPreviewVisible(true); 139 //load preview data 140 loadResourceInfo(resourcePath); 141 } 142 143 /** 144 * @see org.opencms.ade.galleries.client.preview.A_CmsResourcePreview#removePreview() 145 */ 146 @Override 147 public void removePreview() { 148 149 super.removePreview(); 150 m_handler = null; 151 } 152 153 /** 154 * @see org.opencms.ade.galleries.client.preview.I_CmsResourcePreview#saveProperties(java.util.Map, com.google.gwt.user.client.Command) 155 */ 156 public void saveProperties(final Map<String, String> properties, final Command afterSaveCallback) { 157 158 CmsRpcAction<CmsResourceInfoBean> action = new CmsRpcAction<CmsResourceInfoBean>() { 159 160 /** 161 * @see org.opencms.gwt.client.rpc.CmsRpcAction#execute() 162 */ 163 @Override 164 public void execute() { 165 166 getService().updateResourceProperties(getResourcePath(), getLocale(), properties, this); 167 } 168 169 /** 170 * @see org.opencms.gwt.client.rpc.CmsRpcAction#onResponse(java.lang.Object) 171 */ 172 @Override 173 protected void onResponse(CmsResourceInfoBean result) { 174 175 showData(result); 176 if (afterSaveCallback != null) { 177 afterSaveCallback.execute(); 178 } 179 180 } 181 }; 182 action.execute(); 183 184 } 185}