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 fieldconfiguration.<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 CmsDeleteFieldConfigurationDialog extends A_CmsFieldConfigurationDialog {
050
051    /**
052     * Public constructor with JSP action element.<p>
053     *
054     * @param jsp an initialized JSP action element
055     */
056
057    public CmsDeleteFieldConfigurationDialog(CmsJspActionElement jsp) {
058
059        super(jsp);
060
061    }
062
063    /**
064     * Public constructor with JSP variables.<p>
065     *
066     * @param context the JSP page context
067     * @param req the JSP request
068     * @param res the JSP response
069     */
070
071    public CmsDeleteFieldConfigurationDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
072
073        super(context, req, res);
074
075    }
076
077    /**
078     * Commits the edited search index to the search manager.<p>
079     */
080    @Override
081    public void actionCommit() {
082
083        List<Throwable> errors = new ArrayList<Throwable>();
084
085        try {
086
087            m_searchManager.removeSearchFieldConfiguration(m_fieldconfiguration);
088            clearDialogObject();
089            writeConfiguration();
090            // if we go back to /searchindex/singleindex (overview) the deleted searchindex is not
091            // there any more in the CmsSearchManager and CmsOverviewSearchIndex.getUserObject will
092            // find null -> defineWidgets will provide null as bean...
093            setParamCloseLink(CmsToolManager.linkForToolPath(getJsp(), "/searchindex/fieldconfigurations"));
094
095        } catch (Throwable t) {
096            errors.add(t);
097        }
098        // set the list of errors to display when saving failed
099        setCommitErrors(errors);
100    }
101
102    /**
103     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
104     *
105     * This overwrites the method from the super class to create a layout variation for the widgets.<p>
106     *
107     * @param dialog the dialog (page) to get the HTML for
108     * @return the dialog HTML for all defined widgets of the named dialog (page)
109     */
110    @Override
111    protected String createDialogHtml(String dialog) {
112
113        StringBuffer result = new StringBuffer(512);
114
115        result.append(createWidgetTableStart());
116        // show error header once if there were validation errors
117        result.append(createWidgetErrorHeader());
118
119        if (dialog.equals(PAGES[0])) {
120            // create the widgets for the first dialog page
121            result.append(dialogBlockStart(key(Messages.GUI_LIST_FIELDCONFIGURATION_ACTION_DELETE_NAME_0)));
122            result.append(createWidgetTableStart());
123            result.append(key(
124                Messages.GUI_LIST_FIELDCONFIGURATION_ACTION_DELETE_CONF_1,
125                new Object[] {m_fieldconfiguration.getName()}));
126            result.append(createWidgetTableEnd());
127            result.append(dialogBlockEnd());
128        }
129
130        result.append(createWidgetTableEnd());
131
132        // See CmsWidgetDialog.dialogButtonsCustom(): if no widgets are defined that are non-display-only widgets,
133        // no dialog buttons (Ok, Cancel) will be visible....
134        result.append(dialogButtons(new int[] {BUTTON_OK, BUTTON_CANCEL}, new String[2]));
135        return result.toString();
136    }
137}