<commit_before>/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 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, 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.ade.publish.client;

import org.opencms.ade.publish.client.CmsPublishItemStatus.Signal;
import org.opencms.ade.publish.client.CmsPublishSelectPanel.CheckBoxUpdate;
import org.opencms.ade.publish.shared.CmsPublishGroup;
import org.opencms.ade.publish.shared.CmsPublishResource;
import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.gwt.client.ui.CmsList;
import org.opencms.gwt.client.ui.CmsListItemWidget;
import org.opencms.gwt.client.ui.CmsPreviewDialog;
import org.opencms.gwt.client.ui.CmsPushButton;
import org.opencms.gwt.client.ui.CmsSimpleListItem;
import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
import org.opencms.gwt.client.ui.css.I_CmsImageBundle;
import org.opencms.gwt.client.ui.css.I_CmsInputLayoutBundle;
import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
import org.opencms.gwt.client.ui.input.CmsCheckBox;
import org.opencms.gwt.client.ui.input.CmsTriStateCheckBox;
import org.opencms.gwt.client.ui.input.CmsTriStateCheckBox.State;
import org.opencms.gwt.client.ui.tree.CmsTreeItem;
import org.opencms.gwt.client.util.CmsResourceStateUtil;
import org.opencms.gwt.client.util.CmsStyleVariable;
import org.opencms.gwt.shared.CmsIconUtil;
import org.opencms.gwt.shared.CmsListInfoBean;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;

import java.util.List;
import java.util.Map;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * A panel representing a single publish group.<p>
 * 
 * @since 8.0.0
 */
public class CmsPublishGroupPanel extends Composite {

    /** The CSS bundle used for this widget. */
    protected static final I_CmsPublishCss CSS = I_CmsPublishLayoutBundle.INSTANCE.publishCss();

    /** The number of button slits. */
    private static final int NUM_BUTTON_SLOTS = 3;

    /** The slot for the preview button. */
    private static final int SLOT_PREVIEW = 0;

    /** The slot for the 'remove' checkbox. */
    private static final int SLOT_REMOVE = 1;

    /** The slot for the warning symbol. */
    private static final int SLOT_WARNING = 2;

    /** Text metrics key. */
    private static final String TM_PUBLISH_LIST = "PublishList";

    /** The group index for this panel's corresponding group. */
    protected int m_groupIndex;

    /** The data model for the publish dialog. */
    protected CmsPublishDataModel m_model;

    /** The handler which is called when the publish item selection changes. */
    protected I_CmsPublishSelectionChangeHandler m_selectionChangeHandler;

    /** The global map of selection controllers of *ALL* groups (to which this group's selection controllers are added). */
    private Map<CmsUUID, CmsPublishItemSelectionController> m_controllersById;

    /** The group header (containing the label and add/remove buttons). */
    private CmsSimpleListItem m_header = new CmsSimpleListItem();

    /** The number of loaded publish item widgets for this group (used for scrolling).<p> */
    private int m_itemIndex;

    /** The root panel of this widget. */
    private CmsList<CmsTreeItem> m_panel = new CmsList<CmsTreeItem>();

    /** The publish resources of the current group.<p>*/
    private List<CmsPublishResource> m_publishResources;

    /** Checkbox for selecting/deselecting all group items. */
    private CmsTriStateCheckBox m_selectGroup;

    /** A flag which indicates whether only resources with problems should be shown. */
    private boolean m_showProblemsOnly;

    /**
     * Constructs a new instance.<p>
     * 
     * @param publishGroup the group for which to build the group panel 
     * @param title the title of the group
     * @param groupIndex the index of the group which this panel should render
     * @param selectionChangeHandler the handler for selection changes for publish resources
     * @param model the data model for the publish resources
     * @param controllersById the map of selection controllers to which this panel's selection controllers should be added
     * @param showProblemsOnly if true, sets this panel into "show resources with problems only" mode
     */
    public CmsPublishGroupPanel(
        CmsPublishGroup publishGroup,
        String title,
        int groupIndex,
        I_CmsPublishSelectionChangeHandler selectionChangeHandler,
        CmsPublishDataModel model,
        Map<CmsUUID, CmsPublishItemSelectionController> controllersById,
        boolean showProblemsOnly) {

        initWidget(m_panel);
        m_panel.add(m_header);
        m_model = model;
        m_groupIndex = groupIndex;
        m_publishResources = model.getGroups().get(groupIndex).getResources();
        m_controllersById = controllersById;
        m_panel.truncate(TM_PUBLISH_LIST, CmsPublishDialog.DIALOG_WIDTH);
        initSelectButtons();
        if ((groupIndex == 0) && publishGroup.isAutoSelectable()) {
            m_model.signalGroup(Signal.publish, 0);
        }
        m_showProblemsOnly = showProblemsOnly;
        if (hasNoProblemResources() && showProblemsOnly) {
            this.setVisible(false);
        }

        HTML label = new HTML();
        label.setHTML(title);
        label.addStyleName(CSS.groupHeader());
        m_header.add(label);

        FlowPanel clear = new FlowPanel();
        clear.setStyleName(CSS.clear());
        m_header.add(clear);
        m_selectionChangeHandler = selectionChangeHandler;
    }

    /**
     * Creates a basic list item widget for a given publish resource bean.<p>
     * 
     * @param resourceBean the publish resource bean
     * 
     * @return the list item widget representing the publish resource bean 
     */
    public static CmsListItemWidget createListItemWidget(final CmsPublishResource resourceBean) {

        CmsListInfoBean info = new CmsListInfoBean();
        info.setTitle(getTitle(resourceBean));
        info.setSubTitle(resourceBean.getName());
        String stateLabel = org.opencms.gwt.client.Messages.get().key(
            org.opencms.gwt.client.Messages.GUI_RESOURCE_STATE_0);
        info.setResourceState(resourceBean.getState());
        String stateName = CmsResourceStateUtil.getStateName(resourceBean.getState());
        // this can be null for the source resources of broken relations in the 'broken links' 
        // panel since these resources don't have to be new or deleted or changed
        if (stateName != null) {
            info.addAdditionalInfo(stateLabel, stateName, CmsResourceStateUtil.getStateStyle(resourceBean.getState()));
        }
        if (resourceBean.getUserLastModified() != null) {
            String userLabel = org.opencms.ade.publish.client.Messages.get().key(
                org.opencms.ade.publish.client.Messages.GUI_LABEL_USER_LAST_MODIFIED_0);<commit_msg>Fixed problem with duplicate additional info items for resource states in the publish dialog.<commit_after>/*
 * This library is part of OpenCms -
 * the Open Source Content Management System
 *
 * Copyright (c) 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, 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.ade.publish.client;

import org.opencms.ade.publish.client.CmsPublishItemStatus.Signal;
import org.opencms.ade.publish.client.CmsPublishSelectPanel.CheckBoxUpdate;
import org.opencms.ade.publish.shared.CmsPublishGroup;
import org.opencms.ade.publish.shared.CmsPublishResource;
import org.opencms.gwt.client.CmsCoreProvider;
import org.opencms.gwt.client.ui.CmsList;
import org.opencms.gwt.client.ui.CmsListItemWidget;
import org.opencms.gwt.client.ui.CmsPreviewDialog;
import org.opencms.gwt.client.ui.CmsPushButton;
import org.opencms.gwt.client.ui.CmsSimpleListItem;
import org.opencms.gwt.client.ui.I_CmsButton.ButtonStyle;
import org.opencms.gwt.client.ui.css.I_CmsImageBundle;
import org.opencms.gwt.client.ui.css.I_CmsInputLayoutBundle;
import org.opencms.gwt.client.ui.css.I_CmsLayoutBundle;
import org.opencms.gwt.client.ui.input.CmsCheckBox;
import org.opencms.gwt.client.ui.input.CmsTriStateCheckBox;
import org.opencms.gwt.client.ui.input.CmsTriStateCheckBox.State;
import org.opencms.gwt.client.ui.tree.CmsTreeItem;
import org.opencms.gwt.client.util.CmsStyleVariable;
import org.opencms.gwt.shared.CmsIconUtil;
import org.opencms.gwt.shared.CmsListInfoBean;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;

import java.util.List;
import java.util.Map;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.dom.client.Style.Visibility;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * A panel representing a single publish group.<p>
 * 
 * @since 8.0.0
 */
public class CmsPublishGroupPanel extends Composite {

    /** The CSS bundle used for this widget. */
    protected static final I_CmsPublishCss CSS = I_CmsPublishLayoutBundle.INSTANCE.publishCss();

    /** The number of button slits. */
    private static final int NUM_BUTTON_SLOTS = 3;

    /** The slot for the preview button. */
    private static final int SLOT_PREVIEW = 0;

    /** The slot for the 'remove' checkbox. */
    private static final int SLOT_REMOVE = 1;

    /** The slot for the warning symbol. */
    private static final int SLOT_WARNING = 2;

    /** Text metrics key. */
    private static final String TM_PUBLISH_LIST = "PublishList";

    /** The group index for this panel's corresponding group. */
    protected int m_groupIndex;

    /** The data model for the publish dialog. */
    protected CmsPublishDataModel m_model;

    /** The handler which is called when the publish item selection changes. */
    protected I_CmsPublishSelectionChangeHandler m_selectionChangeHandler;

    /** The global map of selection controllers of *ALL* groups (to which this group's selection controllers are added). */
    private Map<CmsUUID, CmsPublishItemSelectionController> m_controllersById;

    /** The group header (containing the label and add/remove buttons). */
    private CmsSimpleListItem m_header = new CmsSimpleListItem();

    /** The number of loaded publish item widgets for this group (used for scrolling).<p> */
    private int m_itemIndex;

    /** The root panel of this widget. */
    private CmsList<CmsTreeItem> m_panel = new CmsList<CmsTreeItem>();

    /** The publish resources of the current group.<p>*/
    private List<CmsPublishResource> m_publishResources;

    /** Checkbox for selecting/deselecting all group items. */
    private CmsTriStateCheckBox m_selectGroup;

    /** A flag which indicates whether only resources with problems should be shown. */
    private boolean m_showProblemsOnly;

    /**
     * Constructs a new instance.<p>
     * 
     * @param publishGroup the group for which to build the group panel 
     * @param title the title of the group
     * @param groupIndex the index of the group which this panel should render
     * @param selectionChangeHandler the handler for selection changes for publish resources
     * @param model the data model for the publish resources
     * @param controllersById the map of selection controllers to which this panel's selection controllers should be added
     * @param showProblemsOnly if true, sets this panel into "show resources with problems only" mode
     */
    public CmsPublishGroupPanel(
        CmsPublishGroup publishGroup,
        String title,
        int groupIndex,
        I_CmsPublishSelectionChangeHandler selectionChangeHandler,
        CmsPublishDataModel model,
        Map<CmsUUID, CmsPublishItemSelectionController> controllersById,
        boolean showProblemsOnly) {

        initWidget(m_panel);
        m_panel.add(m_header);
        m_model = model;
        m_groupIndex = groupIndex;
        m_publishResources = model.getGroups().get(groupIndex).getResources();
        m_controllersById = controllersById;
        m_panel.truncate(TM_PUBLISH_LIST, CmsPublishDialog.DIALOG_WIDTH);
        initSelectButtons();
        if ((groupIndex == 0) && publishGroup.isAutoSelectable()) {
            m_model.signalGroup(Signal.publish, 0);
        }
        m_showProblemsOnly = showProblemsOnly;
        if (hasNoProblemResources() && showProblemsOnly) {
            this.setVisible(false);
        }

        HTML label = new HTML();
        label.setHTML(title);
        label.addStyleName(CSS.groupHeader());
        m_header.add(label);

        FlowPanel clear = new FlowPanel();
        clear.setStyleName(CSS.clear());
        m_header.add(clear);
        m_selectionChangeHandler = selectionChangeHandler;
    }

    /**
     * Creates a basic list item widget for a given publish resource bean.<p>
     * 
     * @param resourceBean the publish resource bean
     * 
     * @return the list item widget representing the publish resource bean 
     */
    public static CmsListItemWidget createListItemWidget(final CmsPublishResource resourceBean) {

        CmsListInfoBean info = new CmsListInfoBean();
        info.setTitle(getTitle(resourceBean));
        info.setSubTitle(resourceBean.getName());
        info.setResourceState(resourceBean.getState());
        if (resourceBean.getUserLastModified() != null) {
            String userLabel = org.opencms.ade.publish.client.Messages.get().key(
                org.opencms.ade.publish.client.Messages.GUI_LABEL_USER_LAST_MODIFIED_0);
{'fraction_non_alphanumeric': 0.08936379873129273, 'fraction_numerical': 0.0032641497813635525, 'mean_word_length': 3.6222601764873326, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7150266', 'n_tokens_mistral': 4840, 'n_tokens_neox': 4695, 'n_words': 1327}