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.widgets.CmsDisplayWidget;
032import org.opencms.widgets.CmsVfsFileWidget;
033import org.opencms.workplace.CmsWidgetDialogParameter;
034
035import javax.servlet.http.HttpServletRequest;
036import javax.servlet.http.HttpServletResponse;
037import javax.servlet.jsp.PageContext;
038
039/**
040 *
041 * Widget dialog to add or remove resources (folders) to / from the request parameter
042 * given <code>{@link org.opencms.search.CmsSearchIndexSource}</code> ("indexsource").<p>
043 *
044 * @since 6.0.0
045 */
046public class CmsSearchIndexSourceAssignResourcesWidget extends A_CmsEditIndexSourceDialog {
047
048    /**
049     * Public constructor with JSP action element.<p>
050     *
051     * @param jsp an initialized JSP action element
052     */
053    public CmsSearchIndexSourceAssignResourcesWidget(CmsJspActionElement jsp) {
054
055        super(jsp);
056    }
057
058    /**
059     * Public constructor with JSP variables.<p>
060     *
061     * @param context the JSP page context
062     * @param req the JSP request
063     * @param res the JSP response
064     */
065    public CmsSearchIndexSourceAssignResourcesWidget(
066        PageContext context,
067        HttpServletRequest req,
068        HttpServletResponse res) {
069
070        this(new CmsJspActionElement(context, req, res));
071    }
072
073    /**
074     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
075     *
076     * This overwrites the method from the super class to create a layout variation for the widgets.<p>
077     *
078     * @param dialog the dialog (page) to get the HTML for
079     * @return the dialog HTML for all defined widgets of the named dialog (page)
080     */
081    @Override
082    protected String createDialogHtml(String dialog) {
083
084        StringBuffer result = new StringBuffer(1024);
085
086        result.append(createWidgetTableStart());
087        // show error header once if there were validation errors
088        result.append(createWidgetErrorHeader());
089
090        if (dialog.equals(PAGES[0])) {
091            // 1st block: indexsource information
092            result.append(dialogBlockStart(key(Messages.GUI_LABEL_INDEXSOURCE_BLOCK_SETTINGS_0)));
093            result.append(createWidgetTableStart());
094            result.append(createDialogRowsHtml(0, 1));
095            result.append(createWidgetTableEnd());
096            result.append(dialogBlockEnd());
097
098            // 2nd block: configureable resources for indexsource
099            result.append(dialogBlockStart(key(Messages.GUI_LIST_SEARCHRESOURCES_NAME_0)));
100            result.append(createWidgetTableStart());
101            result.append(createDialogRowsHtml(2, 2));
102            result.append(createWidgetTableEnd());
103            result.append(dialogBlockEnd());
104        }
105
106        result.append(createWidgetTableEnd());
107        return result.toString();
108    }
109
110    /**
111     * Creates the list of widgets for this dialog.<p>
112     */
113    @Override
114    protected void defineWidgets() {
115
116        super.defineWidgets();
117
118        // widgets to display
119        // indexsource data (first block)
120        addWidget(new CmsWidgetDialogParameter(m_indexsource, "name", PAGES[0], new CmsDisplayWidget()));
121        addWidget(new CmsWidgetDialogParameter(m_indexsource, "indexerClassName", PAGES[0], new CmsDisplayWidget()));
122
123        // resources block
124        addWidget(
125            new CmsWidgetDialogParameter(
126                m_indexsource.getResourcesNames(),
127                "resourcesNames",
128                "/",
129                PAGES[0],
130                new CmsVfsFileWidget(false, ""),
131                1,
132                10));
133    }
134}