Search in sources :

Example 36 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class AbstractPaginationLoader method loadDataSourceProvider.

protected void loadDataSourceProvider(Element element) {
    Element loaderProvider = element.element("loaderProvider");
    Element containerProvider = element.element("containerProvider");
    if (loaderProvider != null && containerProvider != null) {
        throw new GuiDevelopmentException("Pagination must have only one provider: 'loaderProvider' or 'containerProvider'", getContext());
    }
    if (loaderProvider != null) {
        loadString(loaderProvider, "loaderId", id -> {
            ScreenData screenData = UiControllerUtils.getScreenData(getComponentContext().getFrame().getFrameOwner());
            DataLoader loader = screenData.getLoader(id);
            if (loader instanceof BaseCollectionLoader) {
                PaginationDataBinder dataSourceProvider = applicationContext.getBean(PaginationLoaderBinder.class, loader);
                resultComponent.setDataBinder(dataSourceProvider);
            } else {
                throw new GuiDevelopmentException(String.format("PaginationDataSourceProvider does not support %s loader type", loader.getClass().getCanonicalName()), getContext());
            }
        });
        if (resultComponent.getDataBinder() == null) {
            throw new GuiDevelopmentException("Specify 'loaderId' attribute of `loaderProvider` element", getContext());
        }
    }
    if (containerProvider != null) {
        loadString(containerProvider, "dataContainer", containerId -> {
            ScreenData screenData = UiControllerUtils.getScreenData(getComponentContext().getFrame().getFrameOwner());
            InstanceContainer container = screenData.getContainer(containerId);
            if (container instanceof CollectionContainer) {
                PaginationDataBinder dataSourceProvider = applicationContext.getBean(PaginationContainerBinder.class, container);
                resultComponent.setDataBinder(dataSourceProvider);
            } else {
                throw new GuiDevelopmentException(String.format("PaginationDataSourceProvider does not support %s container type", container.getClass().getCanonicalName()), getContext());
            }
        });
        if (resultComponent.getDataBinder() == null) {
            throw new GuiDevelopmentException("Specify 'dataContainer' attribute of `containerProvider` element", getContext());
        }
    }
}
Also used : Element(org.dom4j.Element) PaginationDataBinder(io.jmix.ui.component.pagination.data.PaginationDataBinder) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 37 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class AbstractResourceViewLoader method loadUrlResource.

protected void loadUrlResource(ResourceView resultComponent, Element element) {
    Element urlResource = element.element("url");
    if (urlResource == null)
        return;
    String url = urlResource.attributeValue("url");
    if (StringUtils.isEmpty(url)) {
        throw new GuiDevelopmentException("No url provided for the UrlResource", context);
    }
    UrlResource resource = applicationContext.getBean(UrlResource.class);
    try {
        resource.setUrl(new URL(url));
        loadMimeType(resource, urlResource);
        resultComponent.setSource(resource);
    } catch (MalformedURLException e) {
        String msg = String.format("An error occurred while creating UrlResource with the given url: %s", url);
        throw new GuiDevelopmentException(msg, context);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) URL(java.net.URL)

Example 38 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class AbstractResourceViewLoader method loadThemeResource.

protected boolean loadThemeResource(ResourceView resultComponent, Element element) {
    Element themeResource = element.element("theme");
    if (themeResource == null)
        return false;
    String themePath = themeResource.attributeValue("path");
    if (StringUtils.isEmpty(themePath)) {
        throw new GuiDevelopmentException("No path provided for the ThemeResource", context);
    }
    resultComponent.setSource(ThemeResource.class).setPath(themePath);
    return true;
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 39 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class AbstractResourceViewLoader method loadRelativePathResource.

protected boolean loadRelativePathResource(ResourceView resultComponent, Element element) {
    Element relativePath = element.element("relativePath");
    if (relativePath == null)
        return false;
    String path = relativePath.attributeValue("path");
    if (StringUtils.isEmpty(path)) {
        throw new GuiDevelopmentException("No path provided for the RelativePathResource", context);
    }
    RelativePathResource resource = applicationContext.getBean(RelativePathResource.class);
    resource.setPath(path);
    loadMimeType(resource, relativePath);
    resultComponent.setSource(resource);
    return true;
}
Also used : Element(org.dom4j.Element) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException)

Example 40 with GuiDevelopmentException

use of io.jmix.ui.GuiDevelopmentException in project jmix by jmix-framework.

the class AbstractSingleFilterComponentLoader method loadValueComponent.

@SuppressWarnings("unchecked")
protected void loadValueComponent(C resultComponent, Element element) {
    Component valueComponent;
    if (!element.elements().isEmpty()) {
        valueComponent = createValueComponent(element.elements());
    } else {
        valueComponent = generateValueComponent();
    }
    if (!(valueComponent instanceof HasValue)) {
        throw new GuiDevelopmentException("Value component of the PropertyFilter must implement HasValue", getComponentContext().getCurrentFrameId());
    }
    resultComponent.setValueComponent((HasValue) valueComponent);
}
Also used : GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) SingleFilterComponent(io.jmix.ui.component.SingleFilterComponent) Component(io.jmix.ui.component.Component) HasValue(io.jmix.ui.component.HasValue)

Aggregations

GuiDevelopmentException (io.jmix.ui.GuiDevelopmentException)106 Element (org.dom4j.Element)42 FrameOwner (io.jmix.ui.screen.FrameOwner)16 Component (io.jmix.ui.component.Component)13 InstanceContainer (io.jmix.ui.model.InstanceContainer)11 ScreenData (io.jmix.ui.model.ScreenData)11 CollectionContainer (io.jmix.ui.model.CollectionContainer)9 MetaClass (io.jmix.core.metamodel.model.MetaClass)8 Action (io.jmix.ui.action.Action)7 BaseAction (io.jmix.ui.action.BaseAction)6 ParseException (java.text.ParseException)6 Date (java.util.Date)6 Nullable (javax.annotation.Nullable)6 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)5 ComponentLoader (io.jmix.ui.xml.layout.ComponentLoader)5 ArrayList (java.util.ArrayList)5 Datasource (com.haulmont.cuba.gui.data.Datasource)4 Formatter (io.jmix.ui.component.formatter.Formatter)4 JsonParser (com.google.gson.JsonParser)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3