<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.gwt.client.property;

import org.opencms.gwt.client.I_DescendantResizeHandler;
import org.opencms.gwt.client.Messages;
import org.opencms.gwt.client.ui.CmsFieldSet;
import org.opencms.gwt.client.ui.CmsListItemWidget;
import org.opencms.gwt.client.ui.CmsScrollPanel;
import org.opencms.gwt.client.ui.CmsTabbedPanel;
import org.opencms.gwt.client.ui.css.I_CmsInputLayoutBundle;
import org.opencms.gwt.client.ui.input.I_CmsFormField;
import org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel;
import org.opencms.gwt.client.ui.input.form.CmsFormDialog;
import org.opencms.gwt.client.ui.input.form.CmsInfoBoxFormFieldPanel;
import org.opencms.gwt.client.util.CmsDomUtil;
import org.opencms.gwt.shared.CmsListInfoBean;
import org.opencms.util.CmsStringUtil;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.BeforeSelectionHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;

/**
 * A tabbed form field container widget.<p>
 * 
 * @since 8.0.0
 */
public class CmsPropertyPanel extends A_CmsFormFieldPanel {

    /** Layout data key. */
    public static final String LD_DISPLAY_VALUE = "displayValue";

    /** Layout data key. */
    public static final String LD_GROUP = "group";

    /** Layout data key. */
    public static final String LD_PROPERTY = "property";

    /** Tab id for the "individual" tab. */
    public static final String TAB_INDIVIDUAL = "individual";

    /** Tab id for the "shared" tab. */
    public static final String TAB_SHARED = "shared";

    /** Tab id for the "simple" tab. */
    public static final String TAB_SIMPLE = "simple";

    /** The tab panel. */
    protected CmsTabbedPanel<CmsScrollPanel> m_tabPanel = new CmsTabbedPanel<CmsScrollPanel>();

    /** Multimap of fields by field group. */
    private Multimap<String, I_CmsFormField> m_fieldsByGroup = ArrayListMultimap.create();

    /** Map from group/tab names to corresponding panels. */
    private Map<String, Panel> m_groups = new LinkedHashMap<String, Panel>();

    /** Set of fields which should be displayed at the top of the "individual" tab. */
    private Set<String> m_individualDisplay = Sets.newHashSet();

    /** The "individual" tab. */
    private FlowPanel m_individualTab = new FlowPanel();

    /** The tab wrapper for the individual tab. */
    private FlowPanel m_individualTabWrapper = new FlowPanel();

    /** Set of fields which should be displayed at the top of the "shared" tab. */
    private Set<String> m_sharedDisplay = Sets.newHashSet();

    /** The "shared" tab. */
    private FlowPanel m_sharedTab = new FlowPanel();

    /** The tab wrapper for the shared tab. */
    private FlowPanel m_sharedTabWrapper = new FlowPanel();

    /** True if the "shared" tab should be shown. */
    private boolean m_showShared;

    /** The "simple" tab. */
    private FlowPanel m_simpleTab = new FlowPanel();

    /** The tab wrapper for the simple tab. */
    private FlowPanel m_simpleTabWrapper = new FlowPanel();

    /**
     * Creates a new instance.<p>
     * 
     * @param showShared true if the "shared" tab should be shown 
     * @param info the bean to use for displaying the info item
     */
    public CmsPropertyPanel(boolean showShared, CmsListInfoBean info) {

        CmsListItemWidget liWidget = createListItemWidget(info);
        m_simpleTabWrapper.add(liWidget);
        m_simpleTabWrapper.add(m_simpleTab);
        m_simpleTab.addStyleName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll());
        m_simpleTab.addStyleName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.propertiesCss().vfsModeSimplePropertiesBox());

        m_sharedTabWrapper.add(createListItemWidget(info));
        m_sharedTabWrapper.add(m_sharedTab);

        m_individualTabWrapper.add(createListItemWidget(info));
        m_individualTabWrapper.add(m_individualTab);
        m_groups.put(TAB_SIMPLE, m_simpleTab);
        m_groups.put(TAB_SHARED, m_sharedTab);
        m_groups.put(TAB_INDIVIDUAL, m_individualTab);

        m_simpleTabWrapper.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().formGradientBackground());
        m_individualTabWrapper.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().formGradientBackground());
        m_sharedTabWrapper.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().formGradientBackground());

        CmsScrollPanel scrollPanel = GWT.create(CmsScrollPanel.class);
        scrollPanel.setWidget(m_simpleTabWrapper);
        m_tabPanel.add(scrollPanel, Messages.get().key(Messages.GUI_PROPERTY_TAB_SIMPLE_0));
        m_showShared = showShared;
        if (m_showShared) {
            scrollPanel = GWT.create(CmsScrollPanel.class);
            scrollPanel.setWidget(m_individualTabWrapper);
            m_tabPanel.add(scrollPanel, Messages.get().key(Messages.GUI_PROPERTY_TAB_STRUCTURE_0));
            scrollPanel = GWT.create(CmsScrollPanel.class);
            scrollPanel.setWidget(m_sharedTabWrapper);
            m_tabPanel.add(scrollPanel, Messages.get().key(Messages.GUI_PROPERTY_TAB_RESOURCE_0));
        } else {
            scrollPanel = GWT.create(CmsScrollPanel.class);
            scrollPanel.setWidget(m_individualTabWrapper);
            m_tabPanel.add(scrollPanel, Messages.get().key(Messages.GUI_PROPERTY_TAB_COMPLETE_0));
        }
        initWidget(m_tabPanel);
        m_tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {

            public void onSelection(SelectionEvent<Integer> event) {

                Widget selectedTab = m_tabPanel.getWidget(event.getSelectedItem().intValue());
                if (selectedTab instanceof I_DescendantResizeHandler) {
                    ((I_DescendantResizeHandler)selectedTab).onResizeDescendant();
                }
            }
        });
    }

    /**
     * Adds the {@link BeforeSelectionHandler} for the tab panel.<p>
     *  
     * @param handler the pre-selection handler 
     */
    public void addBeforeSelectionHandler(BeforeSelectionHandler<Integer> handler) {

        m_tabPanel.addBeforeSelectionHandler(handler);
    }

    /**
     * Clears the tab with the given id.<p>
     *  
     * @param tabId the id of the tab to clear 
     */
    public void clearTab(String tabId) {

        m_groups.get(tabId).clear();
    }

    /**
     * @see org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel#getDefaultGroup()
     */
    @Override
    public String getDefaultGroup() {

        return TAB_SIMPLE;
    }

    /**
     * Renders a extended tab.<p>
     * 
     * @param fields the fields to add
     * @param tab the tab
     */
    public void renderExtendedTab(Collection<I_CmsFormField> fields, FlowPanel tab) {

        List<CmsFieldSet> result = new ArrayList<CmsFieldSet>();

        tab.clear();

        String used = Messages.get().key(Messages.GUI_PROPERTY_BLOCK_USED_0);
        CmsFieldSet usedFieldSet = new CmsFieldSet();
        usedFieldSet.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().formGradientBackground());
        usedFieldSet.setLegend(used);
        usedFieldSet.setAnimationDuration(50);

        String unused = Messages.get().key(Messages.GUI_PROPERTY_BLOCK_UNUSED_0);
        CmsFieldSet unusedFieldSet = new CmsFieldSet();
        unusedFieldSet.setOpen(false);
        unusedFieldSet.setLegend(unused);
        unusedFieldSet.setAnimationDuration(50);<commit_msg>Fixed background in property 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.gwt.client.property;

import org.opencms.gwt.client.I_DescendantResizeHandler;
import org.opencms.gwt.client.Messages;
import org.opencms.gwt.client.ui.CmsFieldSet;
import org.opencms.gwt.client.ui.CmsListItemWidget;
import org.opencms.gwt.client.ui.CmsScrollPanel;
import org.opencms.gwt.client.ui.CmsTabbedPanel;
import org.opencms.gwt.client.ui.css.I_CmsInputLayoutBundle;
import org.opencms.gwt.client.ui.input.I_CmsFormField;
import org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel;
import org.opencms.gwt.client.ui.input.form.CmsFormDialog;
import org.opencms.gwt.client.ui.input.form.CmsInfoBoxFormFieldPanel;
import org.opencms.gwt.client.util.CmsDomUtil;
import org.opencms.gwt.shared.CmsListInfoBean;
import org.opencms.util.CmsStringUtil;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.logical.shared.BeforeSelectionHandler;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;

/**
 * A tabbed form field container widget.<p>
 * 
 * @since 8.0.0
 */
public class CmsPropertyPanel extends A_CmsFormFieldPanel {

    /** Layout data key. */
    public static final String LD_DISPLAY_VALUE = "displayValue";

    /** Layout data key. */
    public static final String LD_GROUP = "group";

    /** Layout data key. */
    public static final String LD_PROPERTY = "property";

    /** Tab id for the "individual" tab. */
    public static final String TAB_INDIVIDUAL = "individual";

    /** Tab id for the "shared" tab. */
    public static final String TAB_SHARED = "shared";

    /** Tab id for the "simple" tab. */
    public static final String TAB_SIMPLE = "simple";

    /** The tab panel. */
    protected CmsTabbedPanel<CmsScrollPanel> m_tabPanel = new CmsTabbedPanel<CmsScrollPanel>();

    /** Multimap of fields by field group. */
    private Multimap<String, I_CmsFormField> m_fieldsByGroup = ArrayListMultimap.create();

    /** Map from group/tab names to corresponding panels. */
    private Map<String, Panel> m_groups = new LinkedHashMap<String, Panel>();

    /** Set of fields which should be displayed at the top of the "individual" tab. */
    private Set<String> m_individualDisplay = Sets.newHashSet();

    /** The "individual" tab. */
    private FlowPanel m_individualTab = new FlowPanel();

    /** The tab wrapper for the individual tab. */
    private FlowPanel m_individualTabWrapper = new FlowPanel();

    /** Set of fields which should be displayed at the top of the "shared" tab. */
    private Set<String> m_sharedDisplay = Sets.newHashSet();

    /** The "shared" tab. */
    private FlowPanel m_sharedTab = new FlowPanel();

    /** The tab wrapper for the shared tab. */
    private FlowPanel m_sharedTabWrapper = new FlowPanel();

    /** True if the "shared" tab should be shown. */
    private boolean m_showShared;

    /** The "simple" tab. */
    private FlowPanel m_simpleTab = new FlowPanel();

    /** The tab wrapper for the simple tab. */
    private FlowPanel m_simpleTabWrapper = new FlowPanel();

    /**
     * Creates a new instance.<p>
     * 
     * @param showShared true if the "shared" tab should be shown 
     * @param info the bean to use for displaying the info item
     */
    public CmsPropertyPanel(boolean showShared, CmsListInfoBean info) {

        CmsListItemWidget liWidget = createListItemWidget(info);
        m_simpleTabWrapper.add(liWidget);
        m_simpleTabWrapper.add(m_simpleTab);
        m_simpleTab.addStyleName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll());
        m_simpleTab.addStyleName(org.opencms.gwt.client.ui.css.I_CmsLayoutBundle.INSTANCE.propertiesCss().vfsModeSimplePropertiesBox());
        m_simpleTab.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().formGradientBackground());
        m_sharedTabWrapper.add(createListItemWidget(info));
        m_sharedTabWrapper.add(m_sharedTab);

        m_individualTabWrapper.add(createListItemWidget(info));
        m_individualTabWrapper.add(m_individualTab);
        m_groups.put(TAB_SIMPLE, m_simpleTab);
        m_groups.put(TAB_SHARED, m_sharedTab);
        m_groups.put(TAB_INDIVIDUAL, m_individualTab);
        CmsScrollPanel scrollPanel = GWT.create(CmsScrollPanel.class);
        scrollPanel.setWidget(m_simpleTabWrapper);
        m_tabPanel.add(scrollPanel, Messages.get().key(Messages.GUI_PROPERTY_TAB_SIMPLE_0));
        m_showShared = showShared;
        if (m_showShared) {
            scrollPanel = GWT.create(CmsScrollPanel.class);
            scrollPanel.setWidget(m_individualTabWrapper);
            m_tabPanel.add(scrollPanel, Messages.get().key(Messages.GUI_PROPERTY_TAB_STRUCTURE_0));
            scrollPanel = GWT.create(CmsScrollPanel.class);
            scrollPanel.setWidget(m_sharedTabWrapper);
            m_tabPanel.add(scrollPanel, Messages.get().key(Messages.GUI_PROPERTY_TAB_RESOURCE_0));
        } else {
            scrollPanel = GWT.create(CmsScrollPanel.class);
            scrollPanel.setWidget(m_individualTabWrapper);
            m_tabPanel.add(scrollPanel, Messages.get().key(Messages.GUI_PROPERTY_TAB_COMPLETE_0));
        }
        initWidget(m_tabPanel);
        m_tabPanel.addSelectionHandler(new SelectionHandler<Integer>() {

            public void onSelection(SelectionEvent<Integer> event) {

                Widget selectedTab = m_tabPanel.getWidget(event.getSelectedItem().intValue());
                if (selectedTab instanceof I_DescendantResizeHandler) {
                    ((I_DescendantResizeHandler)selectedTab).onResizeDescendant();
                }
            }
        });
    }

    /**
     * Adds the {@link BeforeSelectionHandler} for the tab panel.<p>
     *  
     * @param handler the pre-selection handler 
     */
    public void addBeforeSelectionHandler(BeforeSelectionHandler<Integer> handler) {

        m_tabPanel.addBeforeSelectionHandler(handler);
    }

    /**
     * Clears the tab with the given id.<p>
     *  
     * @param tabId the id of the tab to clear 
     */
    public void clearTab(String tabId) {

        m_groups.get(tabId).clear();
    }

    /**
     * @see org.opencms.gwt.client.ui.input.form.A_CmsFormFieldPanel#getDefaultGroup()
     */
    @Override
    public String getDefaultGroup() {

        return TAB_SIMPLE;
    }

    /**
     * Renders a extended tab.<p>
     * 
     * @param fields the fields to add
     * @param tab the tab
     */
    public void renderExtendedTab(Collection<I_CmsFormField> fields, FlowPanel tab) {

        List<CmsFieldSet> result = new ArrayList<CmsFieldSet>();

        tab.clear();

        String used = Messages.get().key(Messages.GUI_PROPERTY_BLOCK_USED_0);
        CmsFieldSet usedFieldSet = new CmsFieldSet();
        usedFieldSet.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().formGradientBackground());
        usedFieldSet.setLegend(used);
        usedFieldSet.setAnimationDuration(50);

        String unused = Messages.get().key(Messages.GUI_PROPERTY_BLOCK_UNUSED_0);
        CmsFieldSet unusedFieldSet = new CmsFieldSet();
        unusedFieldSet.addStyleName(I_CmsInputLayoutBundle.INSTANCE.inputCss().formGradientBackground());
        unusedFieldSet.setOpen(false);
        unusedFieldSet.setLegend(unused);
        unusedFieldSet.setAnimationDuration(50);
{'fraction_non_alphanumeric': 0.10166491509486145, 'fraction_numerical': 0.003208142043254605, 'mean_word_length': 3.484126984126984, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, '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': '6719042', 'n_tokens_mistral': 5548, 'n_tokens_neox': 5373, 'n_words': 1248}