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.ui.apps.cacheadmin; 029 030import org.opencms.flex.CmsFlexCache; 031import org.opencms.main.CmsEvent; 032import org.opencms.main.I_CmsEventListener; 033import org.opencms.main.OpenCms; 034import org.opencms.ui.CmsVaadinUtils; 035import org.opencms.ui.FontOpenCms; 036import org.opencms.ui.apps.cacheadmin.CmsFlushCache.I_CloseableDialog; 037import org.opencms.ui.components.CmsBasicDialog; 038 039import java.util.Collections; 040 041import com.vaadin.v7.shared.ui.label.ContentMode; 042import com.vaadin.ui.Button; 043import com.vaadin.ui.Button.ClickEvent; 044import com.vaadin.ui.Button.ClickListener; 045import com.vaadin.v7.ui.Label; 046import com.vaadin.v7.ui.OptionGroup; 047 048/** 049 * Dialog for clean flex cache.<p> 050 */ 051public class CmsFlexCacheCleanDialog extends CmsBasicDialog implements I_CloseableDialog { 052 053 /**vaadin serial id.*/ 054 private static final long serialVersionUID = 142178694100824093L; 055 056 /**Runnable for close action.*/ 057 Runnable m_closeRunnable; 058 059 /**Runnable for ok button.*/ 060 Runnable m_okRunnable; 061 062 /**Vaadin component.*/ 063 private Button m_cancelButton; 064 065 /**Vaadin label for icon.*/ 066 private Label m_icon; 067 068 /**Vaadin component.*/ 069 private OptionGroup m_mode; 070 071 /**Vaadin component.*/ 072 private Button m_okButton; 073 074 /** 075 * Public constructor.<p> 076 * 077 */ 078 public CmsFlexCacheCleanDialog() { 079 080 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 081 082 setDefaultValues(); 083 084 //Set Clicklistener 085 m_cancelButton.addClickListener(new ClickListener() { 086 087 private static final long serialVersionUID = -5769891739879269176L; 088 089 public void buttonClick(ClickEvent event) { 090 091 m_closeRunnable.run(); 092 } 093 }); 094 m_okButton.addClickListener(new ClickListener() { 095 096 private static final long serialVersionUID = 6932464669055039855L; 097 098 public void buttonClick(ClickEvent event) { 099 100 submit(); 101 m_closeRunnable.run(); 102 if (m_okRunnable != null) { 103 m_okRunnable.run(); 104 } 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 * Reads out Checkboxes and chosen mode.<p> 129 */ 130 void submit() { 131 132 int action = -1; 133 134 if (isModeAll()) { 135 action = CmsFlexCache.CLEAR_ONLINE_ALL; 136 } else { 137 action = CmsFlexCache.CLEAR_ONLINE_ENTRIES; 138 } 139 140 OpenCms.fireCmsEvent( 141 new CmsEvent( 142 I_CmsEventListener.EVENT_FLEX_CACHE_CLEAR, 143 Collections.<String, Object> singletonMap(CmsFlexCache.CACHE_ACTION, Integer.valueOf(action)))); 144 } 145 146 /** 147 * Reads out option group for mode.<p> 148 * 149 * @return true if clear all 150 */ 151 private boolean isModeAll() { 152 153 return m_mode.getValue().equals("keysAndVariations"); 154 } 155 156 /** 157 * Set defautl values to vaadin components.<p> 158 */ 159 private void setDefaultValues() { 160 161 //Setup icon 162 m_icon.setContentMode(ContentMode.HTML); 163 m_icon.setValue(FontOpenCms.WARNING.getHtml()); 164 165 //Set Mode option. 166 m_mode.setValue("keysAndVariations"); 167 } 168 169}