⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsprojectsettingsdialog.java

📁 cms是开源的框架
💻 JAVA
字号:
/*
 * File   : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/projects/CmsProjectSettingsDialog.java,v $
 * Date   : $Date: 2006/03/28 12:22:36 $
 * Version: $Revision: 1.13 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.workplace.tools.projects;

import org.opencms.db.CmsProjectResourcesDisplayMode;
import org.opencms.db.CmsUserProjectSettings;
import org.opencms.db.CmsUserSettings;
import org.opencms.i18n.CmsMessages;
import org.opencms.jsp.CmsJspActionElement;
import org.opencms.util.CmsStringUtil;
import org.opencms.widgets.CmsCheckboxWidget;
import org.opencms.widgets.CmsSelectWidget;
import org.opencms.widgets.CmsSelectWidgetOption;
import org.opencms.workplace.CmsDialog;
import org.opencms.workplace.CmsWidgetDialogParameter;
import org.opencms.workplace.CmsWorkplaceSettings;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;

/**
 * Dialog for editing the users project specific settings.<p>
 * 
 * @author Michael Moossen 
 * 
 * @version $Revision: 1.13 $ 
 * 
 * @since 6.0.0 
 */
public class CmsProjectSettingsDialog extends A_CmsProjectDialog {

    /** localized messages Keys prefix. */
    public static final String KEY_PREFIX = "settings";

    /** aux property for mapping the projectFilesMode property of an user project settings object. */
    private String m_mode;

    /** bean for edition of the project settings. */
    private CmsUserProjectSettings m_prjSettings;

    /**
     * Public constructor with JSP action element.<p>
     * 
     * @param jsp an initialized JSP action element
     */
    public CmsProjectSettingsDialog(CmsJspActionElement jsp) {

        super(jsp);
    }

    /**
     * Public constructor with JSP variables.<p>
     * 
     * @param context the JSP page context
     * @param req the JSP request
     * @param res the JSP response
     */
    public CmsProjectSettingsDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {

        this(new CmsJspActionElement(context, req, res));
    }

    /**
     * Commits the edited project to the db.<p>
     */
    public void actionCommit() {

        List errors = new ArrayList();
        try {
            m_prjSettings.setManagerGroup(getCms().readGroup(getManagerGroup()).getId());
            m_prjSettings.setUserGroup(getCms().readGroup(getUserGroup()).getId());
            m_prjSettings.setProjectFilesMode(CmsProjectResourcesDisplayMode.valueOf(getMode()));
            CmsUserSettings settings = new CmsUserSettings(getCms());
            settings.setProjectSettings(m_prjSettings);
            settings.save(getCms());
        } catch (Throwable t) {
            errors.add(t);
        }
        // set the list of errors to display when saving failed
        setCommitErrors(errors);
    }

    /**
     * Returns the project files mode.<p>
     *
     * @return the mode
     */
    public String getMode() {

        return m_mode;
    }

    /**
     * Sets the project files mode.<p>
     *
     * @param mode the mode to set
     */
    public void setMode(String mode) {

        CmsProjectResourcesDisplayMode.valueOf(mode);
        m_mode = mode;
    }

    /**
     * @see org.opencms.workplace.CmsWidgetDialog#createDialogHtml(java.lang.String)
     */
    protected String createDialogHtml(String dialog) {

        StringBuffer result = new StringBuffer(1024);

        result.append(createWidgetTableStart());
        // show error header once if there were validation errors
        result.append(createWidgetErrorHeader());

        if (dialog.equals(PAGES[0])) {
            // create the widgets for the first dialog page
            result.append(dialogBlockStart(key(Messages.GUI_SETTINGS_EDITOR_LABEL_NEWPROJECT_BLOCK_0)));
            result.append(createWidgetTableStart());
            result.append(createDialogRowsHtml(0, 2));
            result.append(createWidgetTableEnd());
            result.append(dialogBlockEnd());
            result.append(dialogBlockStart(key(Messages.GUI_SETTINGS_EDITOR_LABEL_PROJECTFILES_BLOCK_0)));
            result.append(createWidgetTableStart());
            result.append(createDialogRowsHtml(3, 3));
            result.append(createWidgetTableEnd());
            result.append(dialogBlockEnd());
        }

        result.append(createWidgetTableEnd());
        return result.toString();
    }

    /**
     * Creates the list of widgets for this dialog.<p>
     */
    protected void defineWidgets() {

        // initialize the project object to use for the dialog
        initSettingsObject();

        setKeyPrefix(KEY_PREFIX);

        // widgets to display
        addWidget(new CmsWidgetDialogParameter(this, "managerGroup", PAGES[0], new CmsSelectWidget(
            getSelectGroups(true))));
        addWidget(new CmsWidgetDialogParameter(this, "userGroup", PAGES[0], new CmsSelectWidget(getSelectGroups(false))));
        addWidget(new CmsWidgetDialogParameter(
            m_prjSettings,
            "deleteAfterPublishing",
            PAGES[0],
            new CmsCheckboxWidget()));
        addWidget(new CmsWidgetDialogParameter(this, "mode", PAGES[0], new CmsSelectWidget(getSelectModes())));
    }

    /**
     * Initializes the project settings object to work with depending on the dialog state and request parameters.<p>
     * 
     * Two initializations of the settings object on first dialog call are possible:
     * <ul>
     * <li>edit existing settings</li>
     * <li>create new settings</li>
     * </ul>
     */
    protected void initSettingsObject() {

        Object o = null;

        try {
            if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) {
                // edit an existing settings, get the setting object from db
                CmsUserSettings settings = new CmsUserSettings(getCms());
                m_prjSettings = settings.getProjectSettings();
            } else {
                // this is not the initial call, get the setting object from session            
                o = getDialogObject();
                m_prjSettings = (CmsUserProjectSettings)o;
            }
            // test
            m_prjSettings.getProjectFilesMode();
        } catch (Exception e) {
            // create a new settings object
            m_prjSettings = new CmsUserProjectSettings();
        }
        try {
            setManagerGroup(getCms().readGroup(m_prjSettings.getManagerGroup()).getName());
        } catch (Exception e) {
            // ignore
        }
        try {
            setUserGroup(getCms().readGroup(m_prjSettings.getUserGroup()).getName());
        } catch (Exception e) {
            // ignore
        }
        try {
            setMode(m_prjSettings.getProjectFilesMode().toString());
        } catch (Exception e) {
            // ignore
        }
    }

    /**
     * Overridden to set a custom online help mapping.<p>
     * 
     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement)
     */
    protected void initWorkplaceMembers(CmsJspActionElement jsp) {

        super.initWorkplaceMembers(jsp);
        setOnlineHelpUriCustom("/projects/project_settings.jsp");
    }

    /**
     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
     */
    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {

        // initialize parameters and dialog actions in super implementation
        super.initWorkplaceRequestValues(settings, request);

        // save the current state of the settings (may be changed because of the widget values)
        setDialogObject(m_prjSettings);
    }

    /**
     * Returns all diferent project file selection modes.<p>
     * 
     * @return a list of modes
     */
    private List getSelectModes() {

        List retVal = new ArrayList();
        CmsMessages messages = Messages.get().getBundle(getLocale());
        retVal.add(new CmsSelectWidgetOption(
            CmsProjectResourcesDisplayMode.ALL_CHANGES.getMode(),
            true,
            messages.key(Messages.GUI_PROJECT_MODE_ALLCHANGES_0)));
        retVal.add(new CmsSelectWidgetOption(
            CmsProjectResourcesDisplayMode.NEW_FILES.getMode(),
            false,
            messages.key(Messages.GUI_PROJECT_MODE_NEWFILES_0)));
        retVal.add(new CmsSelectWidgetOption(
            CmsProjectResourcesDisplayMode.MODIFIED_FILES.getMode(),
            false,
            messages.key(Messages.GUI_PROJECT_MODE_MODFILES_0)));
        retVal.add(new CmsSelectWidgetOption(
            CmsProjectResourcesDisplayMode.DELETED_FILES.getMode(),
            false,
            messages.key(Messages.GUI_PROJECT_MODE_DELFILES_0)));
        return retVal;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -