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.dialogs; 029 030import org.opencms.file.CmsObject; 031import org.opencms.i18n.CmsLocaleManager; 032import org.opencms.main.CmsEvent; 033import org.opencms.main.CmsLog; 034import org.opencms.main.I_CmsEventListener; 035import org.opencms.main.OpenCms; 036import org.opencms.report.CmsLogReport; 037import org.opencms.ui.A_CmsUI; 038import org.opencms.ui.CmsVaadinUtils; 039import org.opencms.ui.I_CmsDialogContext; 040import org.opencms.ui.actions.CmsReindexDialogAction; 041import org.opencms.ui.components.CmsBasicDialog; 042import org.opencms.ui.components.CmsOkCancelActionHandler; 043import org.opencms.util.CmsUUID; 044 045import java.util.ArrayList; 046import java.util.HashMap; 047import java.util.Map; 048 049import org.apache.commons.logging.Log; 050 051import com.vaadin.ui.Button; 052import com.vaadin.ui.Button.ClickEvent; 053import com.vaadin.ui.Button.ClickListener; 054import com.vaadin.v7.ui.CheckBox; 055import com.vaadin.v7.ui.Label; 056 057/** 058 * Dialog used to change resource modification times.<p> 059 */ 060public class CmsReindexDialog extends CmsBasicDialog { 061 062 /** Logger instance for this class. */ 063 private static final Log LOG = CmsLog.getLog(CmsReindexDialog.class); 064 065 /** Serial version id. */ 066 private static final long serialVersionUID = 1L; 067 068 /** The dialog context. */ 069 protected I_CmsDialogContext m_context; 070 071 /** The Cancel button. */ 072 private Button m_cancelButton; 073 074 /** The OK button. */ 075 private Button m_okButton; 076 077 /** Label with info text. */ 078 private Label m_infoText; 079 080 /** The checkbox, telling if related should be reindexed as well. */ 081 private CheckBox m_reindexRelated; 082 083 /** Flag, indicating if we are in the online project. */ 084 private boolean m_isOnline; 085 086 /** 087 * Creates a new instance.<p> 088 * 089 * @param context the dialog context 090 */ 091 public CmsReindexDialog(I_CmsDialogContext context) { 092 093 m_context = context; 094 m_isOnline = context.getCms().getRequestContext().getCurrentProject().isOnlineProject(); 095 CmsVaadinUtils.readAndLocalizeDesign( 096 this, 097 OpenCms.getWorkplaceManager().getMessages(A_CmsUI.get().getLocale()), 098 null); 099 String indexType = CmsVaadinUtils.getMessageText( 100 m_isOnline 101 ? org.opencms.workplace.commons.Messages.GUI_REINDEX_INDEX_TYPE_ONLINE_0 102 : org.opencms.workplace.commons.Messages.GUI_REINDEX_INDEX_TYPE_OFFLINE_0); 103 m_infoText.setValue( 104 CmsVaadinUtils.getMessageText( 105 org.opencms.workplace.commons.Messages.GUI_REINDEX_CONFIRMATION_1, 106 indexType)); 107 m_cancelButton.addClickListener(new ClickListener() { 108 109 private static final long serialVersionUID = 1L; 110 111 public void buttonClick(ClickEvent event) { 112 113 cancel(); 114 } 115 116 }); 117 118 m_okButton.addClickListener(new ClickListener() { 119 120 private static final long serialVersionUID = 1L; 121 122 public void buttonClick(ClickEvent event) { 123 124 reindex(); 125 m_context.finish(new ArrayList<CmsUUID>()); 126 127 } 128 }); 129 displayResourceInfo(m_context.getResources()); 130 131 setActionHandler(new CmsOkCancelActionHandler() { 132 133 private static final long serialVersionUID = 1L; 134 135 @Override 136 protected void cancel() { 137 138 CmsReindexDialog.this.cancel(); 139 } 140 141 @Override 142 protected void ok() { 143 144 reindex(); 145 } 146 }); 147 } 148 149 /** 150 * Triggers reindexing.<p> 151 */ 152 protected void reindex() { 153 154 CmsObject cms = A_CmsUI.getCmsObject(); 155 Map<String, Object> eventData = new HashMap<>(3); 156 if (!m_isOnline) { 157 eventData.put(I_CmsEventListener.KEY_PROJECTID, cms.getRequestContext().getCurrentProject().getId()); 158 } 159 eventData.put(I_CmsEventListener.KEY_RESOURCES, m_context.getResources()); 160 eventData.put( 161 I_CmsEventListener.KEY_REPORT, 162 new CmsLogReport(CmsLocaleManager.getDefaultLocale(), CmsReindexDialogAction.class)); 163 eventData.put(I_CmsEventListener.KEY_USER_ID, cms.getRequestContext().getCurrentUser().getId()); 164 Boolean reindexRelated = m_reindexRelated.getValue(); 165 eventData.put(I_CmsEventListener.KEY_REINDEX_RELATED, reindexRelated); 166 CmsEvent reindexEvent = new CmsEvent( 167 m_isOnline ? I_CmsEventListener.EVENT_REINDEX_ONLINE : I_CmsEventListener.EVENT_REINDEX_OFFLINE, 168 eventData); 169 OpenCms.fireCmsEvent(reindexEvent); 170 171 } 172 173 /** 174 * Cancels the dialog.<p> 175 */ 176 void cancel() { 177 178 m_context.finish(new ArrayList<CmsUUID>()); 179 } 180}