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.searchindex; 029 030import org.opencms.ui.CmsVaadinUtils; 031import org.opencms.ui.apps.Messages; 032 033import java.util.ArrayList; 034import java.util.Iterator; 035import java.util.List; 036import java.util.Set; 037 038import com.vaadin.ui.Button; 039import com.vaadin.ui.Button.ClickEvent; 040import com.vaadin.ui.Button.ClickListener; 041import com.vaadin.ui.Component; 042import com.vaadin.ui.FormLayout; 043import com.vaadin.ui.Panel; 044import com.vaadin.v7.ui.Label; 045import com.vaadin.v7.ui.VerticalLayout; 046 047/** 048 * Class for the GUI to rebuild indexes.<p> 049 */ 050public class CmsSearchindexRebuild extends VerticalLayout { 051 052 /**vaadin serial id.*/ 053 private static final long serialVersionUID = -3306537840428458751L; 054 055 /**vaadin component.*/ 056 private Label m_confirm; 057 058 /**List of indexes to rebuild.*/ 059 private List<String> m_indexList; 060 061 /**vaadin component.*/ 062 private FormLayout m_layout; 063 064 /**Instance of calling app.*/ 065 private CmsSearchindexApp m_manager; 066 067 /**vaadin component.*/ 068 private Button m_ok; 069 070 /**vaadin component.*/ 071 private Panel m_reportPanel; 072 073 /**vaadin component.*/ 074 private Panel m_startPanel; 075 076 /** 077 * public constructor.<p> 078 * @param app instance 079 * @param data indexes to be updated 080 */ 081 public CmsSearchindexRebuild(CmsSearchindexApp app, Set<String> data) { 082 083 CmsVaadinUtils.readAndLocalizeDesign(this, CmsVaadinUtils.getWpMessagesForCurrentLocale(), null); 084 setHeight("570px"); 085 m_manager = app; 086 m_reportPanel.setVisible(false); 087 m_confirm.setValue( 088 CmsVaadinUtils.getMessageText(Messages.GUI_SEARCHINDEX_REBUILD_CONFIRM_1, getCommaSeperatedIndexes(data))); 089 090 m_indexList = new ArrayList<String>(data); 091 092 m_ok.addClickListener(new ClickListener() { 093 094 /**vaadin serial id.*/ 095 private static final long serialVersionUID = 7361499756763447027L; 096 097 public void buttonClick(ClickEvent event) { 098 099 startThread(); 100 101 } 102 }); 103 } 104 105 /** 106 * Starts the rebuild thread.<p> 107 */ 108 protected void startThread() { 109 110 m_reportPanel.setVisible(true); 111 m_startPanel.setVisible(false); 112 Component report = m_manager.getUpdateThreadComponent(m_indexList); 113 report.setHeight("500px"); 114 report.setWidth("100%"); 115 m_layout.removeAllComponents(); 116 m_layout.addComponent(report); 117 } 118 119 /** 120 * Creates a comma seperated string with all indexes represented by a string using the CmsSearchindexApp.SEPERATOR_INDEXNAMES.<p> 121 * 122 * @param data list of indexes seperated by CmsSearchindexApp.SEPERATOR_INDEXNAMES 123 * @return string representation of indexes 124 */ 125 private String getCommaSeperatedIndexes(Set<String> data) { 126 127 Iterator<String> it = data.iterator(); 128 String res = it.next(); 129 if (data.size() == 1) { 130 return res; 131 } 132 res += ", "; 133 while (it.hasNext()) { 134 res += it.next() + ", "; 135 } 136 res = res.substring(0, res.length() - 2); 137 return res; 138 } 139}