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.search.fields.CmsSearchField;
032import org.opencms.widgets.CmsCheckboxWidget;
033import org.opencms.widgets.CmsDisplayWidget;
034import org.opencms.widgets.CmsInputWidget;
035import org.opencms.widgets.CmsSelectWidget;
036import org.opencms.widgets.CmsSelectWidgetOption;
037import org.opencms.workplace.CmsWidgetDialogParameter;
038
039import java.util.ArrayList;
040import java.util.List;
041
042import javax.servlet.http.HttpServletRequest;
043import javax.servlet.http.HttpServletResponse;
044import javax.servlet.jsp.PageContext;
045
046/**
047 *
048 * Dialog to edit new or existing field in the administration view.<p>
049 *
050 * @since 6.5.5
051 */
052public class CmsEditFieldDialog extends A_CmsFieldDialog {
053
054    /**
055     * Public constructor with JSP action element.<p>
056     *
057     * @param jsp the jsp action element
058     */
059    public CmsEditFieldDialog(CmsJspActionElement jsp) {
060
061        super(jsp);
062    }
063
064    /**
065     * Public constructor with JSP variables.<p>
066     *
067     * @param context the JSP page context
068     * @param req the JSP request
069     * @param res the JSP response
070     */
071    public CmsEditFieldDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
072
073        super(context, req, res);
074    }
075
076    /**
077     * Returns the String value of the indexed value.<p>
078     *
079     * @return String value of the indexed value
080     */
081    public String getIndexed() {
082
083        if ((m_field != null) && (m_field.getIndexed() != null)) {
084            return m_field.getIndexed();
085        }
086        return "";
087    }
088
089    /**
090     * Sets the indexed value of the field.<p>
091     *
092     * @param indexed String value of the indexed value
093     */
094    public void setIndexed(String indexed) {
095
096        m_field.setIndexed(indexed);
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(1024);
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_LABEL_FIELD_BLOCK_SETTINGS_0)));
119            result.append(createWidgetTableStart());
120            result.append(createDialogRowsHtml(0, 6));
121            result.append(createWidgetTableEnd());
122            result.append(dialogBlockEnd());
123        }
124
125        result.append(createWidgetTableEnd());
126        return result.toString();
127    }
128
129    /**
130     * Creates the list of widgets for this dialog.<p>
131     */
132    @Override
133    protected void defineWidgets() {
134
135        super.defineWidgets();
136
137        // set default value if field is new
138        if (m_field.getName() == null) {
139            m_field.setStored(true);
140            m_field.setIndexed(true);
141            m_field.setDisplayed(true);
142        }
143
144        // widgets to display
145        // new indexsource
146        if (m_field.getName() == null) {
147            addWidget(new CmsWidgetDialogParameter(m_field, "name", PAGES[0], new CmsInputWidget()));
148        } else {
149            addWidget(new CmsWidgetDialogParameter(m_field, "name", PAGES[0], new CmsDisplayWidget()));
150        }
151        addWidget(
152            new CmsWidgetDialogParameter(
153                this,
154                "indexed",
155                "true",
156                PAGES[0],
157                new CmsSelectWidget(getTokenizedWidgetConfiguration()),
158                1,
159                1));
160        addWidget(new CmsWidgetDialogParameter(m_field, "stored", "true", PAGES[0], new CmsCheckboxWidget(), 1, 1));
161        addWidget(new CmsWidgetDialogParameter(m_field, "inExcerpt", "", PAGES[0], new CmsCheckboxWidget(), 0, 1));
162        addWidget(
163            new CmsWidgetDialogParameter(
164                m_field,
165                "displayNameForConfiguration",
166                "",
167                PAGES[0],
168                new CmsInputWidget(),
169                0,
170                1));
171        addWidget(new CmsWidgetDialogParameter(m_field, "boostDisplay", "", PAGES[0], new CmsInputWidget(), 0, 1));
172        addWidget(new CmsWidgetDialogParameter(m_field, "defaultValue", "", PAGES[0], new CmsInputWidget(), 0, 1));
173    }
174
175    /**
176     * Returns a list for the indexed select box.<p>
177     *
178     * @return a list for the indexed select box
179     */
180    private List<CmsSelectWidgetOption> getTokenizedWidgetConfiguration() {
181
182        List<CmsSelectWidgetOption> result = new ArrayList<CmsSelectWidgetOption>();
183        result.add(new CmsSelectWidgetOption("true", true));
184        result.add(new CmsSelectWidgetOption("false", false));
185        result.add(new CmsSelectWidgetOption("untokenized", false));
186        return result;
187    }
188}