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.modules;
029
030import org.opencms.jsp.CmsJspActionElement;
031import org.opencms.util.CmsStringUtil;
032import org.opencms.widgets.CmsCheckboxWidget;
033import org.opencms.widgets.CmsDisplayWidget;
034import org.opencms.widgets.CmsInputWidget;
035import org.opencms.widgets.CmsTextareaWidget;
036import org.opencms.workplace.CmsWidgetDialogParameter;
037
038import javax.servlet.http.HttpServletRequest;
039import javax.servlet.http.HttpServletResponse;
040import javax.servlet.jsp.PageContext;
041
042/**
043 * Edit class to edit an exiting module.<p>
044 *
045 * @since 6.0.0
046 */
047public class CmsModulesEdit extends CmsModulesEditBase {
048
049    /**
050     * Public constructor with JSP action element.<p>
051     *
052     * @param jsp an initialized JSP action element
053     */
054    public CmsModulesEdit(CmsJspActionElement jsp) {
055
056        super(jsp);
057
058    }
059
060    /**
061     * Public constructor with JSP variables.<p>
062     *
063     * @param context the JSP page context
064     * @param req the JSP request
065     * @param res the JSP response
066     */
067    public CmsModulesEdit(PageContext context, HttpServletRequest req, HttpServletResponse res) {
068
069        this(new CmsJspActionElement(context, req, res));
070
071    }
072
073    /**
074     * Creates the dialog HTML for all defined widgets of the named dialog (page).<p>
075     *
076     * @param dialog the dialog (page) to get the HTML for
077     * @return the dialog HTML for all defined widgets of the named dialog (page)
078     */
079    @Override
080    protected String createDialogHtml(String dialog) {
081
082        StringBuffer result = new StringBuffer(1024);
083
084        // create table
085        result.append(createWidgetTableStart());
086
087        // show error header once if there were validation errors
088        result.append(createWidgetErrorHeader());
089
090        if (dialog.equals(PAGES[0])) {
091            result.append(dialogBlockStart(key("label.moduleinformation")));
092            result.append(createWidgetTableStart());
093            result.append(createDialogRowsHtml(0, 7));
094            result.append(createWidgetTableEnd());
095            result.append(dialogBlockEnd());
096            result.append(dialogBlockStart(key("label.modulecreator")));
097            result.append(createWidgetTableStart());
098            result.append(createDialogRowsHtml(8, 9));
099            result.append(createWidgetTableEnd());
100            result.append(dialogBlockEnd());
101            result.append(dialogBlockStart(key("label.moduleexportmode")));
102            result.append(createWidgetTableStart());
103            result.append(createDialogRowsHtml(10, 10));
104            result.append(createWidgetTableEnd());
105            result.append(dialogBlockEnd());
106            if (CmsStringUtil.isEmpty(m_module.getName())) {
107                result.append(dialogBlockStart(key("label.modulefolder")));
108                result.append(createWidgetTableStart());
109                result.append(createDialogRowsHtml(11, 17));
110                result.append(createWidgetTableEnd());
111                result.append(dialogBlockEnd());
112            }
113        }
114
115        // close table
116        result.append(createWidgetTableEnd());
117
118        return result.toString();
119    }
120
121    /**
122     * Creates the list of widgets for this dialog.<p>
123     */
124    @Override
125    protected void defineWidgets() {
126
127        super.defineWidgets();
128        if (CmsStringUtil.isEmpty(m_module.getName())) {
129            addWidget(new CmsWidgetDialogParameter(m_module, "name", PAGES[0], new CmsInputWidget()));
130        } else {
131            addWidget(new CmsWidgetDialogParameter(m_module, "name", PAGES[0], new CmsDisplayWidget()));
132        }
133        addWidget(new CmsWidgetDialogParameter(m_module, "niceName", PAGES[0], new CmsInputWidget()));
134        addWidget(new CmsWidgetDialogParameter(m_module, "description", PAGES[0], new CmsTextareaWidget()));
135        addWidget(new CmsWidgetDialogParameter(m_module, "version.version", PAGES[0], new CmsInputWidget()));
136        addWidget(new CmsWidgetDialogParameter(m_module, "group", PAGES[0], new CmsInputWidget()));
137        addWidget(new CmsWidgetDialogParameter(m_module, "actionClass", PAGES[0], new CmsInputWidget()));
138        addWidget(new CmsWidgetDialogParameter(m_module, "importScript", PAGES[0], new CmsTextareaWidget()));
139        addWidget(new CmsWidgetDialogParameter(m_module, "importSite", PAGES[0], new CmsInputWidget()));
140        addWidget(new CmsWidgetDialogParameter(m_module, "authorName", PAGES[0], new CmsInputWidget()));
141        addWidget(new CmsWidgetDialogParameter(m_module, "authorEmail", PAGES[0], new CmsInputWidget()));
142        addWidget(new CmsWidgetDialogParameter(m_module, "reducedExportMode", PAGES[0], new CmsCheckboxWidget()));
143        // add the second page only when creating a new module
144        if (CmsStringUtil.isEmpty(m_module.getName())) {
145            addWidget(new CmsWidgetDialogParameter(m_module, "createModuleFolder", PAGES[0], new CmsCheckboxWidget()));
146            addWidget(
147                new CmsWidgetDialogParameter(m_module, "createTemplateFolder", PAGES[0], new CmsCheckboxWidget()));
148            addWidget(
149                new CmsWidgetDialogParameter(m_module, "createElementsFolder", PAGES[0], new CmsCheckboxWidget()));
150            addWidget(
151                new CmsWidgetDialogParameter(m_module, "createFormattersFolder", PAGES[0], new CmsCheckboxWidget()));
152            addWidget(
153                new CmsWidgetDialogParameter(m_module, "createResourcesFolder", PAGES[0], new CmsCheckboxWidget()));
154            addWidget(new CmsWidgetDialogParameter(m_module, "createSchemasFolder", PAGES[0], new CmsCheckboxWidget()));
155            addWidget(new CmsWidgetDialogParameter(m_module, "createClassesFolder", PAGES[0], new CmsCheckboxWidget()));
156            addWidget(new CmsWidgetDialogParameter(m_module, "createLibFolder", PAGES[0], new CmsCheckboxWidget()));
157        }
158    }
159
160}