Search in sources :

Example 1 with ContainerTreeItems

use of com.haulmont.cuba.gui.components.data.tree.ContainerTreeItems in project cuba by cuba-platform.

the class TreeLoader method loadTreeChildren.

@SuppressWarnings("unchecked")
protected void loadTreeChildren() {
    Element itemsElem = element.element("treechildren");
    String containerId = element.attributeValue("dataContainer");
    if (containerId != null) {
        FrameOwner frameOwner = getComponentContext().getFrame().getFrameOwner();
        ScreenData screenData = UiControllerUtils.getScreenData(frameOwner);
        InstanceContainer container = screenData.getContainer(containerId);
        CollectionContainer collectionContainer;
        if (container instanceof CollectionContainer) {
            collectionContainer = (CollectionContainer) container;
        } else {
            throw new GuiDevelopmentException("Not a CollectionContainer: " + containerId, context);
        }
        String hierarchyProperty = element.attributeValue("hierarchyProperty");
        if (hierarchyProperty == null && itemsElem != null) {
            // legacy behaviour
            hierarchyProperty = itemsElem.attributeValue("hierarchyProperty");
        }
        if (Strings.isNullOrEmpty(hierarchyProperty)) {
            throw new GuiDevelopmentException("Tree doesn't have 'hierarchyProperty' attribute of the 'treechildren' element", context, "Tree ID", element.attributeValue("id"));
        }
        String showOrphansAttr = element.attributeValue("showOrphans");
        boolean showOrphans = showOrphansAttr == null || Boolean.parseBoolean(showOrphansAttr);
        resultComponent.setItems(new ContainerTreeItems(collectionContainer, hierarchyProperty, showOrphans));
    } else if (itemsElem != null) {
        String datasource = itemsElem.attributeValue("datasource");
        if (!StringUtils.isBlank(datasource)) {
            HierarchicalDatasource ds = (HierarchicalDatasource) getComponentContext().getDsContext().get(datasource);
            resultComponent.setDatasource(ds);
        }
    }
    String captionProperty = element.attributeValue("captionProperty");
    if (captionProperty == null && itemsElem != null) {
        captionProperty = itemsElem.attributeValue("captionProperty");
    }
    if (!StringUtils.isEmpty(captionProperty)) {
        resultComponent.setCaptionProperty(captionProperty);
        resultComponent.setCaptionMode(CaptionMode.PROPERTY);
    }
}
Also used : HierarchicalDatasource(com.haulmont.cuba.gui.data.HierarchicalDatasource) FrameOwner(com.haulmont.cuba.gui.screen.FrameOwner) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) InstanceContainer(com.haulmont.cuba.gui.model.InstanceContainer) CollectionContainer(com.haulmont.cuba.gui.model.CollectionContainer) ScreenData(com.haulmont.cuba.gui.model.ScreenData) ContainerTreeItems(com.haulmont.cuba.gui.components.data.tree.ContainerTreeItems)

Aggregations

GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 ContainerTreeItems (com.haulmont.cuba.gui.components.data.tree.ContainerTreeItems)1 HierarchicalDatasource (com.haulmont.cuba.gui.data.HierarchicalDatasource)1 CollectionContainer (com.haulmont.cuba.gui.model.CollectionContainer)1 InstanceContainer (com.haulmont.cuba.gui.model.InstanceContainer)1 ScreenData (com.haulmont.cuba.gui.model.ScreenData)1 FrameOwner (com.haulmont.cuba.gui.screen.FrameOwner)1 Element (org.dom4j.Element)1