<commit_before>/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */
package com.haulmont.cuba.gui.xml.layout.loaders;

import com.haulmont.cuba.gui.components.BoxLayout;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.SplitPanel;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;

import java.util.Collection;

/**
 * @author abramov
 * @version $Id$
 */
public class SplitPanelLoader extends ContainerLoader{

    public SplitPanelLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
        super(context, config, factory);
    }

    @Override
    public Component loadComponent(ComponentsFactory factory, Element element, Component parent) {
        final SplitPanel component = factory.createComponent(SplitPanel.NAME);

        assignXmlDescriptor(component, element);
        loadId(component, element);

        final String orientation = element.attributeValue("orientation");
        if (StringUtils.isEmpty(orientation)) {
            component.setOrientation(SplitPanel.ORIENTATION_VERTICAL);
        } else if ("vertical".equalsIgnoreCase(orientation)) {
            component.setOrientation(SplitPanel.ORIENTATION_VERTICAL);
        } else if ("horizontal".equalsIgnoreCase(orientation)) {
            component.setOrientation(SplitPanel.ORIENTATION_HORIZONTAL);
        }

        loadVisible(component, element);
        loadStyleName(component, element);

        final Collection<Component> components = loadSubComponents(component, element, "visible");
        if (components.size() == 1) {
            component.add(factory.createComponent(BoxLayout.VBOX));
        }

        final String pos = element.attributeValue("pos");
        if (!StringUtils.isEmpty(pos)) {
            component.setSplitPosition(Integer.valueOf(pos));
        }
<commit_msg>Show more useful error message when we try to open screen which has empty splitPanel #PL-2764<commit_after>/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */
package com.haulmont.cuba.gui.xml.layout.loaders;

import com.haulmont.cuba.gui.GuiDevelopmentException;
import com.haulmont.cuba.gui.components.BoxLayout;
import com.haulmont.cuba.gui.components.Component;
import com.haulmont.cuba.gui.components.SplitPanel;
import com.haulmont.cuba.gui.xml.layout.ComponentsFactory;
import com.haulmont.cuba.gui.xml.layout.LayoutLoaderConfig;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;

import java.util.Collection;

/**
 * @author abramov
 * @version $Id$
 */
public class SplitPanelLoader extends ContainerLoader{

    public SplitPanelLoader(Context context, LayoutLoaderConfig config, ComponentsFactory factory) {
        super(context, config, factory);
    }

    @Override
    public Component loadComponent(ComponentsFactory factory, Element element, Component parent) {
        final SplitPanel component = factory.createComponent(SplitPanel.NAME);

        assignXmlDescriptor(component, element);
        loadId(component, element);

        final String orientation = element.attributeValue("orientation");
        if (StringUtils.isEmpty(orientation)) {
            component.setOrientation(SplitPanel.ORIENTATION_VERTICAL);
        } else if ("vertical".equalsIgnoreCase(orientation)) {
            component.setOrientation(SplitPanel.ORIENTATION_VERTICAL);
        } else if ("horizontal".equalsIgnoreCase(orientation)) {
            component.setOrientation(SplitPanel.ORIENTATION_HORIZONTAL);
        }

        loadVisible(component, element);
        loadStyleName(component, element);

        final Collection<Component> components = loadSubComponents(component, element, "visible");
        if (components.size() == 0) {
            throw new GuiDevelopmentException("Split panel must contain at least one child component",
                    context.getFullFrameId());
        } else if (components.size() == 1) {
            component.add(factory.createComponent(BoxLayout.VBOX));
        }

        final String pos = element.attributeValue("pos");
        if (!StringUtils.isEmpty(pos)) {
            component.setSplitPosition(Integer.valueOf(pos));
        }

{'fraction_non_alphanumeric': 0.10344827586206896, 'fraction_numerical': 0.0055617352614015575, 'mean_word_length': 3.702928870292887, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3753868', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1160, 'n_words': 249}