Search in sources :

Example 1 with ListComponent

use of com.haulmont.cuba.gui.components.ListComponent in project cuba by cuba-platform.

the class BulkEditorLoader method loadComponent.

@Override
public void loadComponent() {
    assignXmlDescriptor(resultComponent, element);
    assignFrame(resultComponent);
    loadEnable(resultComponent, element);
    loadVisible(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadCaption(resultComponent, element);
    loadDescription(resultComponent, element);
    loadIcon(resultComponent, element);
    loadWidth(resultComponent, element);
    loadAlign(resultComponent, element);
    loadResponsive(resultComponent, element);
    loadTabIndex(resultComponent, element);
    if (!userSessionSource.getUserSession().isSpecificPermitted(BulkEditor.PERMISSION)) {
        resultComponent.setVisible(false);
    }
    String openType = element.attributeValue("openType");
    if (StringUtils.isNotEmpty(openType)) {
        resultComponent.setOpenType(WindowManager.OpenType.valueOf(openType));
    }
    String exclude = element.attributeValue("exclude");
    String includeProperties = element.attributeValue("includeProperties");
    if (StringUtils.isNotBlank(exclude) && StringUtils.isNotBlank(includeProperties)) {
        throw new GuiDevelopmentException("BulkEditor cannot define simultaneously exclude and includeProperties attributes", getContext().getCurrentFrameId());
    }
    if (StringUtils.isNotBlank(exclude)) {
        resultComponent.setExcludePropertiesRegex(exclude.replace(" ", ""));
    }
    if (StringUtils.isNotBlank(includeProperties)) {
        resultComponent.setIncludeProperties(Splitter.on(',').omitEmptyStrings().trimResults().splitToList(includeProperties));
    }
    String listComponent = element.attributeValue("for");
    if (StringUtils.isEmpty(listComponent)) {
        throw new GuiDevelopmentException("'for' attribute of bulk editor is not specified", context.getFullFrameId(), "componentId", resultComponent.getId());
    }
    String loadDynamicAttributes = element.attributeValue("loadDynamicAttributes");
    if (StringUtils.isNotEmpty(loadDynamicAttributes)) {
        resultComponent.setLoadDynamicAttributes(Boolean.parseBoolean(loadDynamicAttributes));
    }
    context.addPostInitTask((context1, window) -> {
        // todo artamonov here we can use post wrap instead of post init
        if (resultComponent.getListComponent() == null) {
            Component bindComponent = resultComponent.getFrame().getComponent(listComponent);
            if (!(bindComponent instanceof ListComponent)) {
                throw new GuiDevelopmentException("Specify 'for' attribute: id of table or tree", context1.getFullFrameId(), "componentId", resultComponent.getId());
            }
            resultComponent.setListComponent((ListComponent) bindComponent);
        }
    });
    loadValidators(resultComponent, element);
    loadFocusable(resultComponent, element);
}
Also used : GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) ListComponent(com.haulmont.cuba.gui.components.ListComponent) ListComponent(com.haulmont.cuba.gui.components.ListComponent) Component(com.haulmont.cuba.gui.components.Component)

Example 2 with ListComponent

use of com.haulmont.cuba.gui.components.ListComponent in project cuba by cuba-platform.

the class RelatedEntitiesLoader method loadComponent.

@Override
public void loadComponent() {
    assignFrame(resultComponent);
    loadCaption(resultComponent, element);
    loadIcon(resultComponent, element);
    loadWidth(resultComponent, element);
    loadStyleName(resultComponent, element);
    loadEnable(resultComponent, element);
    loadVisible(resultComponent, element);
    loadAlign(resultComponent, element);
    String openType = element.attributeValue("openType");
    if (StringUtils.isNotEmpty(openType)) {
        resultComponent.setOpenType(OpenType.valueOf(openType));
    }
    String exclude = element.attributeValue("exclude");
    if (StringUtils.isNotBlank(exclude)) {
        resultComponent.setExcludePropertiesRegex(exclude);
    }
    for (Object routeObject : element.elements("property")) {
        Element routeElement = (Element) routeObject;
        String property = routeElement.attributeValue("name");
        if (StringUtils.isEmpty(property)) {
            throw new GuiDevelopmentException("Name attribute for related entities property is not specified", context.getFullFrameId(), "componentId", resultComponent.getId());
        }
        String caption = loadResourceString(routeElement.attributeValue("caption"));
        String filterCaption = loadResourceString(routeElement.attributeValue("filterCaption"));
        String screen = routeElement.attributeValue("screen");
        if (StringUtils.isNotEmpty(screen)) {
            WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
            if (windowConfig.findWindowInfo(screen) == null) {
                throw new GuiDevelopmentException("Screen for custom route in related entities not found", context.getFullFrameId(), "componentId", resultComponent.getId());
            }
        }
        resultComponent.addPropertyOption(property, screen, caption, filterCaption);
    }
    String listComponent = element.attributeValue("for");
    if (StringUtils.isEmpty(listComponent)) {
        throw new GuiDevelopmentException("'for' attribute of related entities is not specified", context.getFullFrameId(), "componentId", resultComponent.getId());
    }
    context.addPostInitTask((context1, window) -> {
        if (resultComponent.getListComponent() == null) {
            Component bindComponent = resultComponent.getFrame().getComponent(listComponent);
            if (!(bindComponent instanceof ListComponent)) {
                throw new GuiDevelopmentException("Specify 'for' attribute: id of table or tree", context1.getFullFrameId(), "componentId", resultComponent.getId());
            }
            resultComponent.setListComponent((ListComponent) bindComponent);
        }
    });
    loadFocusable(resultComponent, element);
    loadTabIndex(resultComponent, element);
}
Also used : WindowConfig(com.haulmont.cuba.gui.config.WindowConfig) Element(org.dom4j.Element) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) ListComponent(com.haulmont.cuba.gui.components.ListComponent) ListComponent(com.haulmont.cuba.gui.components.ListComponent) Component(com.haulmont.cuba.gui.components.Component)

Aggregations

GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)2 Component (com.haulmont.cuba.gui.components.Component)2 ListComponent (com.haulmont.cuba.gui.components.ListComponent)2 WindowConfig (com.haulmont.cuba.gui.config.WindowConfig)1 Element (org.dom4j.Element)1