001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (https://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: https://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: https://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.CmsCheckboxWidget;
032import org.opencms.widgets.CmsDisplayWidget;
033import org.opencms.widgets.CmsInputWidget;
034import org.opencms.widgets.CmsSelectWidget;
035import org.opencms.widgets.CmsSelectWidgetOption;
036import org.opencms.workplace.CmsWidgetDialogParameter;
037
038import java.util.ArrayList;
039import java.util.List;
040
041import jakarta.servlet.http.HttpServletRequest;
042import jakarta.servlet.http.HttpServletResponse;
043import jakarta.servlet.jsp.PageContext;
044
045/**
046 *
047 * Dialog to edit new or existing field in the administration view.<p>
048 *
049 * @since 6.5.5
050 */
051public class CmsEditFieldDialog extends A_CmsFieldDialog {
052
053    /**
054     * Public constructor with JSP action element.<p>
055     *
056     * @param jsp the jsp action element
057     */
058    public CmsEditFieldDialog(CmsJspActionElement jsp) {
059
060        super(jsp);
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    public CmsEditFieldDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
071
072        super(context, req, res);
073    }
074
075    /**
076     * Returns the String value of the indexed value.<p>
077     *
078     * @return String value of the indexed value
079     */
080    public String getIndexed() {
081
082        if ((m_field != null) && (m_field.getIndexed() != null)) {
083            return m_field.getIndexed();
084        }
085        return "";
086    }
087
088    /**
089     * Sets the indexed value of the field.<p>
090     *
091     * @param indexed String value of the indexed value
092     */
093    public void setIndexed(String indexed) {
094
095        m_field.setIndexed(indexed);
096    }
097
098    /**
099     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
100     *
101     * This overwrites the method from the super class to create a layout variation for the widgets.<p>
102     *
103     * @param dialog the dialog (page) to get the HTML for
104     * @return the dialog HTML for all defined widgets of the named dialog (page)
105     */
106    @Override
107    protected String createDialogHtml(String dialog) {
108
109        StringBuffer result = new StringBuffer(1024);
110
111        result.append(createWidgetTableStart());
112        // show error header once if there were validation errors
113        result.append(createWidgetErrorHeader());
114
115        if (dialog.equals(PAGES[0])) {
116            // create the widgets for the first dialog page
117            result.append(dialogBlockStart(key(Messages.GUI_LABEL_FIELD_BLOCK_SETTINGS_0)));
118            result.append(createWidgetTableStart());
119            result.append(createDialogRowsHtml(0, 6));
120            result.append(createWidgetTableEnd());
121            result.append(dialogBlockEnd());
122        }
123
124        result.append(createWidgetTableEnd());
125        return result.toString();
126    }
127
128    /**
129     * Creates the list of widgets for this dialog.<p>
130     */
131    @Override
132    protected void defineWidgets() {
133
134        super.defineWidgets();
135
136        // set default value if field is new
137        if (m_field.getName() == null) {
138            m_field.setStored(true);
139            m_field.setIndexed(true);
140            m_field.setDisplayed(true);
141        }
142
143        // widgets to display
144        // new indexsource
145        if (m_field.getName() == null) {
146            addWidget(new CmsWidgetDialogParameter(m_field, "name", PAGES[0], new CmsInputWidget()));
147        } else {
148            addWidget(new CmsWidgetDialogParameter(m_field, "name", PAGES[0], new CmsDisplayWidget()));
149        }
150        addWidget(
151            new CmsWidgetDialogParameter(
152                this,
153                "indexed",
154                "true",
155                PAGES[0],
156                new CmsSelectWidget(getTokenizedWidgetConfiguration()),
157                1,
158                1));
159        addWidget(new CmsWidgetDialogParameter(m_field, "stored", "true", PAGES[0], new CmsCheckboxWidget(), 1, 1));
160        addWidget(new CmsWidgetDialogParameter(m_field, "inExcerpt", "", PAGES[0], new CmsCheckboxWidget(), 0, 1));
161        addWidget(
162            new CmsWidgetDialogParameter(
163                m_field,
164                "displayNameForConfiguration",
165                "",
166                PAGES[0],
167                new CmsInputWidget(),
168                0,
169                1));
170        addWidget(new CmsWidgetDialogParameter(m_field, "boostDisplay", "", PAGES[0], new CmsInputWidget(), 0, 1));
171        addWidget(new CmsWidgetDialogParameter(m_field, "defaultValue", "", PAGES[0], new CmsInputWidget(), 0, 1));
172    }
173
174    /**
175     * Returns a list for the indexed select box.<p>
176     *
177     * @return a list for the indexed select box
178     */
179    private List<CmsSelectWidgetOption> getTokenizedWidgetConfiguration() {
180
181        List<CmsSelectWidgetOption> result = new ArrayList<CmsSelectWidgetOption>();
182        result.add(new CmsSelectWidgetOption("true", true));
183        result.add(new CmsSelectWidgetOption("false", false));
184        result.add(new CmsSelectWidgetOption("untokenized", false));
185        return result;
186    }
187}