001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: https://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.ui.apps.cacheadmin; 029 030import org.opencms.ui.A_CmsUI; 031import org.opencms.ui.CmsVaadinUtils; 032import org.opencms.ui.FontOpenCms; 033import org.opencms.ui.apps.Messages; 034import org.opencms.ui.apps.cacheadmin.CmsFlushCache.I_CloseableDialog; 035import org.opencms.ui.components.CmsBasicDialog; 036import org.opencms.ui.components.CmsDateField; 037import org.opencms.ui.report.CmsReportDialog; 038 039import java.time.Instant; 040import java.util.Calendar; 041 042import com.vaadin.ui.Button; 043import com.vaadin.ui.Button.ClickEvent; 044import com.vaadin.ui.Button.ClickListener; 045import com.vaadin.v7.shared.ui.label.ContentMode; 046import com.vaadin.v7.ui.Label; 047 048/** 049 * Dialog to clean Image Cache.<p> 050 */ 051public class CmsImageCacheCleanDialog extends CmsBasicDialog implements I_CloseableDialog { 052 053 /**vaadin serial id.*/ 054 private static final long serialVersionUID = -6902585433676013120L; 055 056 /**Runnable for close action.*/ 057 Runnable m_closeRunnable; 058 059 /**Runnable for ok action. */ 060 Runnable m_okRunnable; 061 062 /**Vaadin component.*/ 063 private Button m_cancelButton; 064 065 /**Date field.*/ 066 private CmsDateField m_dateField; 067 068 /**Vaadin component.*/ 069 private Label m_icon; 070 071 /**Vaadin component.*/ 072 private Button m_okButton; 073 074 /** 075 * Public constructor.<p> 076 */ 077 public CmsImageCacheCleanDialog() { 078 079 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 080 081 //Setup icon 082 m_icon.setContentMode(ContentMode.HTML); 083 m_icon.setValue(FontOpenCms.WARNING.getHtml()); 084 085 Calendar cal = Calendar.getInstance(); 086 cal.add(Calendar.MINUTE, -30); 087 m_dateField.setDate(cal.getTime()); 088 m_okButton.addClickListener(new ClickListener() { 089 090 private static final long serialVersionUID = 8281661241498918564L; 091 092 public void buttonClick(ClickEvent event) { 093 094 flushCache(); 095 m_closeRunnable.run(); 096 } 097 }); 098 m_cancelButton.addClickListener(new ClickListener() { 099 100 private static final long serialVersionUID = -936541994114016527L; 101 102 public void buttonClick(ClickEvent event) { 103 104 m_closeRunnable.run(); 105 } 106 }); 107 } 108 109 /** 110 * @see org.opencms.ui.apps.cacheadmin.CmsFlushCache.I_CloseableDialog#setCloseRunnable(java.lang.Runnable) 111 */ 112 public void setCloseRunnable(Runnable closeRunnable) { 113 114 m_closeRunnable = closeRunnable; 115 116 } 117 118 /** 119 * @see org.opencms.ui.apps.cacheadmin.CmsFlushCache.I_CloseableDialog#setOkRunnable(java.lang.Runnable) 120 */ 121 public void setOkRunnable(Runnable okRunnable) { 122 123 m_okRunnable = okRunnable; 124 125 } 126 127 /** 128 * Clears the Image Cache according to value of date field.<p> 129 */ 130 void flushCache() { 131 132 Instant cutoff = m_dateField.getDate().toInstant(); 133 CmsImageCacheClearThread thread = new CmsImageCacheClearThread(A_CmsUI.getCmsObject(), cutoff); 134 CmsReportDialog.showReportDialog( 135 CmsVaadinUtils.getMessageText(Messages.GUI_CACHE_IMAGECACHE_CLEAR_REPORT_TITLE_0), 136 thread, 137 m_okRunnable); 138 } 139}