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 GmbH & Co. KG, 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.workplace.tools.searchindex; 029 030import org.opencms.jsp.CmsJspActionElement; 031import org.opencms.workplace.tools.CmsToolManager; 032 033import java.util.ArrayList; 034import java.util.List; 035 036import javax.servlet.http.HttpServletRequest; 037import javax.servlet.http.HttpServletResponse; 038import javax.servlet.jsp.PageContext; 039 040/** 041 * A <code>CmsWidgetDialog</code> that starts a (confirmed) delete dialog for 042 * an field.<p> 043 * 044 * The constraint for allowing deletion of the fieldconfiguration: It must not be referenced by 045 * any searchindex.<p> 046 * 047 * @since 6.5.5 048 */ 049public class CmsDeleteFieldDialog extends A_CmsFieldDialog { 050 051 /** 052 * Public constructor with JSP action element.<p> 053 * 054 * @param jsp an initialized JSP action element 055 */ 056 public CmsDeleteFieldDialog(CmsJspActionElement jsp) { 057 058 super(jsp); 059 } 060 061 /** 062 * Public constructor with JSP variables.<p> 063 * 064 * @param context the JSP page context 065 * @param req the JSP request 066 * @param res the JSP response 067 */ 068 public CmsDeleteFieldDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 069 070 super(context, req, res); 071 } 072 073 /** 074 * Commits the edited search index to the search manager.<p> 075 */ 076 @Override 077 public void actionCommit() { 078 079 List<Throwable> errors = new ArrayList<Throwable>(); 080 081 try { 082 083 m_searchManager.removeSearchFieldConfigurationField(m_fieldconfiguration, m_field); 084 clearDialogObject(); 085 writeConfiguration(); 086 // if we go back to /searchindex/singleindex (overview) the deleted searchindex is not 087 // there any more in the CmsSearchManager and CmsOverviewSearchIndex.getUserObject will 088 // find null -> defineWidgets will provide null as bean... 089 setParamCloseLink( 090 CmsToolManager.linkForToolPath(getJsp(), "/searchindex/fieldconfigurations/fieldconfiguration")); 091 092 } catch (Throwable t) { 093 errors.add(t); 094 } 095 // set the list of errors to display when saving failed 096 setCommitErrors(errors); 097 } 098 099 /** 100 * Creates the dialog HTML for all defined widgets of the named dialog (page).<p> 101 * 102 * This overwrites the method from the super class to create a layout variation for the widgets.<p> 103 * 104 * @param dialog the dialog (page) to get the HTML for 105 * @return the dialog HTML for all defined widgets of the named dialog (page) 106 */ 107 @Override 108 protected String createDialogHtml(String dialog) { 109 110 StringBuffer result = new StringBuffer(512); 111 112 result.append(createWidgetTableStart()); 113 // show error header once if there were validation errors 114 result.append(createWidgetErrorHeader()); 115 116 if (dialog.equals(PAGES[0])) { 117 // create the widgets for the first dialog page 118 result.append(dialogBlockStart(key(Messages.GUI_LIST_FIELD_ACTION_DELETE_NAME_0))); 119 result.append(createWidgetTableStart()); 120 result.append(key(Messages.GUI_LIST_FIELD_ACTION_DELETE_CONF_1, new Object[] {m_field.getName()})); 121 result.append(createWidgetTableEnd()); 122 result.append(dialogBlockEnd()); 123 } 124 125 result.append(createWidgetTableEnd()); 126 127 // See CmsWidgetDialog.dialogButtonsCustom(): if no widgets are defined that are non-display-only widgets, 128 // no dialog buttons (Ok, Cancel) will be visible.... 129 result.append(dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL}, new String[2])); 130 return result.toString(); 131 } 132}